使用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 ...
随机推荐
- Linux系统中调用短信猫发送短信(笔记)
1, 拷贝底层串口依赖的librxtxSerial.so到JDK安装路径cp librxtxSerial.so /usr/java/{0}/jre/lib/{1} # {0}: JDK的基础目录,例如 ...
- 【转】对GAMIT/GLOBK的基本认识
1.1 GAMIT/GLOBK软件可从网络上申请下载.该软件功能强大,用途广泛,一般包括精确定位,大气层可降水汽估计和空间电离层变化分析等.后两种用途只需要用到GAMIT模块,精确定位则还需要GL ...
- ASP.NET Core Web API下事件驱动型架构的实现(三):基于RabbitMQ的事件总线
在上文中,我们讨论了事件处理器中对象生命周期的问题,在进入新的讨论之前,首先让我们总结一下,我们已经实现了哪些内容.下面的类图描述了我们已经实现的组件及其之间的关系,貌似系统已经变得越来越复杂了. 其 ...
- MongoDB 基本操作学习笔记
// 查看所有数据库 show dbs // amdin 0.000GB // local 0.000GB // 使用数据库 use admin // switched to db admin // ...
- ATS 分级缓存
理解缓存分级cache hierarchies 缓存分级是由彼此能够相互通信的各级缓存组成的,ATS支持几种类型的缓存分级.所有的缓存分级都有父子缓存概念. 父缓存位于缓存分级的较高级别,ATS能将请 ...
- java根据模板导出pdf
在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支持模板,有的只是随便把数据放里面生成文件,完全不考虑数据怎样放置的以及以后的维护性,想想还是自己总结一个完全版的导出 ...
- spring之p命名空间注入
<bean id="personId" class="com.itheima.f_xml.c_p.Person" p:pname="禹太璞&qu ...
- 浅谈大型web系统架构(一)
目录 Web前端系统 负载均衡系统 数据库集群系统 缓存系统 分布式存储系统 分布式服务器管理系统 代码发布系统 动态应用,是相对于网站静态内容而言,是指以c/c++.php.Java.perl. ...
- PHP可以通过类名调用非静态方法
今日有兄弟遇上一个问题,就是可以通过class名称直接调用该类中的函数,我测试了一下,确实可以,概念中是只有静态方法才可以这样调用的,现在 被刷新了,于是我在方法中加入一行$this相关的操作,再运行 ...
- ABP官方文档翻译 2.3 缓存
缓存 介绍 ICacheManager 警告:GetCache方法 ICache ITypedCache 配置 实体缓存 实体缓存如何工作 Redis缓存集成 介绍 ABP为缓存提供了一个抽象接口,它 ...