使用SpringSecurity保护你的Eureka.
因为注册中心基本上都是自己的应用在使用,应用不是特别多,可以写死,如果应用很多,那么就写入数据库把
pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
WebSecurityConfigurerAdapter ,注意为了可以使用 http://pc:123456@localhost:8000/eureka/ 这种方式登录,所以必须是httpBasic,如果是form方式,不能使用url格式登录
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Value("${users.admin.name}")
private String admin_name;
@Value("${users.admin.password}")
private String admin_password;
@Value("${users.admin.roles}")
private String [] admin_roles; @Value("${users.pc.name}")
private String pc_name;
@Value("${users.pc.password}")
private String pc_password;
@Value("${users.pc.roles}")
private String [] pc_roles; @Value("${users.app.name}")
private String app_name;
@Value("${users.app.password}")
private String app_password;
@Value("${users.app.roles}")
private String [] app_roles; @Value("${users.apiuser.name}")
private String apiuser_name;
@Value("${users.apiuser.password}")
private String apiuser_password;
@Value("${users.apiuser.roles}")
private String [] apiuser_roles; @Value("${users.zuul.name}")
private String zuul_name;
@Value("${users.zuul.password}")
private String zuul_password;
@Value("${users.zuul-router.roles}")
private String [] zuul_roles; @Override
public void configure(WebSecurity web) throws Exception {
//这里忽略app调用的接口服务,让接口服务的Oauth去验证
web.ignoring().antMatchers("/app-server/api/**");
} @Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
http.authorizeRequests().anyRequest().fullyAuthenticated().antMatchers("/app-server/pc/**").hasRole("PCSERVER");
// .antMatchers("/app-server/api/**").hasRole("APIUSER");
http.csrf().disable();
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
} @Override
protected void configure(AuthenticationManagerBuilder auth)throws Exception{
auth.inMemoryAuthentication().withUser(admin_name).password(admin_password).roles(admin_roles)
.and().withUser(pc_name).password(pc_password).roles(pc_roles)//PC 服务
.and().withUser(app_name).password(app_password).roles(app_roles)//APP 服务
.and().withUser(zuul_name).password(zuul_password).roles(zuul_roles) //路由
.and().withUser(apiuser_name).password(apiuser_password).roles(apiuser_roles);//接口调用者
} }
application.yml
server:
port: 8000
max-threads: 2000
max-connections: 2000 eureka:
instance:
hostname: localhost
appname: eureka
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ users:
admin:
name: admin
password: admin
roles: ADMIN,PC,APIUSER
pc:
name: pc
password: 123456
roles: PCSERVER
app:
name: app
password: 123456
roles: app
apiuser:
name: apiuser
password: 123456
roles: APIUSER
zuul:
name: zuul
password: 123456
roles: ZUUL
其他服务连接eureka
http://pc:123456@localhost:8000/eureka/
使用SpringSecurity保护你的Eureka.的更多相关文章
- 使用SpringSecurity保护程序安全
首先,引入依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...
- 使用SpringSecurity保护方法应用
(1)pom添加依赖 <dependency> <groupId>org.springframework.security</groupId> <artifa ...
- 笔记:Spring Cloud Eureka 常用配置及说明
配置参数 默认值 说明 服务注册中心配置 Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean ...
- Eureka服务配置与进阶
1. Eureka服务配置与进阶 1.1. 主要配置 1.1.1. 服务端(eureka.server.*) enableSelfPreservation默认true,启用注册中心的自保护机制,Eur ...
- Spring Cloud Eureka基本概述
记一次Eureka的进一步学习. 一.Eureka简介 百科描述:Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡 ...
- Spring Cloud Eureka 常用配置及说明
配置参数 默认值 说明 服务注册中心配置 Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean eu ...
- spring cloud Eureka常见问题总结
Spring Cloud中,Eureka常见问题总结. 指定Eureka的Environment 1 eureka.environment: 指定环境 参考文档:https://github.com/ ...
- Spring Cloud Eureka 属性作用
配置参数 默认值 说明 服务注册中心配置 Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean eu ...
- Spring Cloud(Dalston.SR5)--Eureka 常用配置
配置参数 默认值 说明 服务注册中心配置 Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean eu ...
随机推荐
- elasticsearch的集中常见操作
1.引入dependency <dependency> <groupId>org.springframework.data</groupId> <artifa ...
- 国内不谈java
今天晚上在整理电脑,不知道怎么回事,电脑里面放着一篇文章.打开一看写的挺好的,现在就贴出来,望共勉. 国内不谈java--会有千万人跳出来和你争嘴的.越是如此,我越是不忍心不说出来,越是不不忍心看 ...
- android onSaveInstanceState应用实例
//activity销毁之前调用,把状态值存储上 @Override protected void onSaveInstanceState(Bundle outState) { outState.pu ...
- 通俗易懂的分析如何用Python实现一只小爬虫,爬取拉勾网的职位信息
源代码:https://github.com/nnngu/LagouSpider 效果预览 思路 1.首先我们打开拉勾网,并搜索"java",显示出来的职位信息就是我们的目标. 2 ...
- zabbix-proxy搭建
环境: 因为公司需要监控远程客户机,但server端无法主动连接agent端,客户端可以连接公司ip 公司有固定ip,可以开放某个端口给zabbixserver,客户机agent端可以主动通过外网连接 ...
- Web安全之CSP
内容安全策略(Content-Security-Policy,简称CSP) 概念: 内容安全策略(CSP)是一种web应用技术用于帮助缓解大部分类型的内容注入攻击,包括XSS攻击和数据注入等,这些攻击 ...
- 在IAR下移植CC2650 contiki工程
与Instant Contiki相比,在Windows的IAR下开发可以在线仿真,下载也更方便,因此我想把BLEach的工程移植到IAR下.弄了好几天总算编译并且下载成功了,参考了[这篇TI的wiki ...
- wpf图片浏览器,实现缩放平移操作图片切换等功能
wpf经常要用到控件来查看图片,尤其是高清图片,于是做了一个例子: 1.定义图片的队列,用list来存. private readonly List<string> files; 2.切换 ...
- 解决AspNet Zero Core 5.0.1无法运行的问题
最近在研究AspNet Zero Core 5.0.1时发现VS点击调试后就自动退出了,从ABP QQ群里得知作者加入了licensecode校验.经过一个周左右断断续续的折腾,算是破解了吧.原本想把 ...
- ABP官方文档翻译 10.1 ABP Nuget包
ABP Nuget包 Packages Abp Abp.AspNetCore Abp.Web.Common Abp.Web Abp.Web.Mvc Abp.Web.Api Abp.Web.Api.OD ...