使用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 ...
随机推荐
- git 安装使用
系统ubuntu14.04 1.安装:sudo apt-get install git 2.设置name and Email: git config --global user.name " ...
- VisionPro笔记(1):动态创建控件
VisionPro学习笔记(1):动态创建控件 有的时候可能需要在程序中动态创建控件,VisionPro实例中提供了一例动态创建Blob控件的方法.当然,动态创建过多的控件会极大的消耗系统的资源,建 ...
- Ipython的安装/ipython notebook的简单使用
安装了pyhton的windows版的shell好久了,今天才听说Ipython这个东西,确实在windows下的python shell很难用,一旦输入错误就要重新来过 了解了下ipython,然后 ...
- 【转】centos安装vim7.4
centos安装vim7.4 系统版本centos6.4; root权限 su - root 卸载 $ rpm -qa | grep vim $ yum remove vim vim-en ...
- [UWP]新控件ColorPicker
1. 前言 Fall Creators Update中提供了一个新得ColorPicker控件,解决了以前选择颜色只能用Combo Box的窘境. 2. 一个简单的例子 <ColorPicker ...
- js实现键盘按键检测
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...
- appium问题整理
在刚进入appium的世界时,遇到无数的坑,趟过无数的浑水,现在整理一些常用的报错讯息,供大家参考 1.org.openqa.selenium.remote.UnreachableBrowserExc ...
- 不干胶打印机 www.bgjdyj.com
不干胶打印机如何保养 不干胶打印机专卖网根据多年的维修经验总结了以下几种保养不干胶打印机的方法: 1.不干胶打印机打印机标签纸不能搁置太长时间,第一容易起静电.第二容易起灰尘2.不干胶打印机的打印头最 ...
- Spring源码情操陶冶-自定义节点的解析
本文承接前文Spring源码情操陶冶-DefaultBeanDefinitionDocumentReader#parseBeanDefinitions,特开辟出一块新地来啃啃这块有意思的骨头 自定义节 ...
- 关于WebAPI
1. 现在越来越多的企业以及网站 以及互联网使用WebApi .那么WebApi 和 普通的WebServices 和WCF 最大的区别是什么了.那就是Web API很多人都会想到Web服务,但是 ...