因为注册中心基本上都是自己的应用在使用,应用不是特别多,可以写死,如果应用很多,那么就写入数据库把

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.的更多相关文章

  1. 使用SpringSecurity保护程序安全

    首先,引入依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...

  2. 使用SpringSecurity保护方法应用

    (1)pom添加依赖 <dependency> <groupId>org.springframework.security</groupId> <artifa ...

  3. 笔记:Spring Cloud Eureka 常用配置及说明

    配置参数 默认值 说明 服务注册中心配置    Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean ...

  4. Eureka服务配置与进阶

    1. Eureka服务配置与进阶 1.1. 主要配置 1.1.1. 服务端(eureka.server.*) enableSelfPreservation默认true,启用注册中心的自保护机制,Eur ...

  5. Spring Cloud Eureka基本概述

    记一次Eureka的进一步学习. 一.Eureka简介 百科描述:Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡 ...

  6. Spring Cloud Eureka 常用配置及说明

    配置参数 默认值 说明 服务注册中心配置 Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean eu ...

  7. spring cloud Eureka常见问题总结

    Spring Cloud中,Eureka常见问题总结. 指定Eureka的Environment 1 eureka.environment: 指定环境 参考文档:https://github.com/ ...

  8. Spring Cloud Eureka 属性作用

    配置参数 默认值 说明 服务注册中心配置 Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean eu ...

  9. Spring Cloud(Dalston.SR5)--Eureka 常用配置

    配置参数 默认值 说明 服务注册中心配置 Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean eu ...

随机推荐

  1. java1.8--1.8入门介绍

    在我之前的工作中,一直使用的是java6.所以即使现在java已经到了1.8,对于1.7增加的新特性我也基本没使用的.在整理一系列1.8的新特性的过程中,我也会添加上1.7增加的特性. 下面的整理可能 ...

  2. Tomcat常用操作

    Tomcat简介 TOMCAT是APACHE JAKARTA软件组织的一个子项目,TOMCAT是一个JSP/SERVLET容器,它是在SUN公司的JSWDK(JAVA SERVER WEB DEVEL ...

  3. gd库的安装

    gd库简介 主要用途编辑 在网站上GD库通常用来生成缩略图,或者用来对图片加水印,或者用来生成汉字验证码,或者对网站数据生成报表等.在PHP处理图像,可使用GD库,而GD库开始时是支持GIF的,但由于 ...

  4. jenkins插件安装与升级[三]

    标签(linux): jenkins 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 默认的插件 Folders Plugin OWASP Markup Form ...

  5. javacript 组合使用构造函数模式和原型模式

    构造函数模式创建对象 基本方法 function Person(name,age){ this.name=name; this.age=age; this.sayName=function(){ al ...

  6. use zlib lib to compress or decompress file

    If you want to compress or decompress file when writing C++ code,you can choose zlib library,that's ...

  7. 关于css选择器的一些细节

    1.如何区分一个html标签的不同样式 使用标签名.类名的方式解决 如果希望特别强调其中的某一个或几个元素,处理的方案有三个: 1.id选择器 2.class选择器 3.层级选择器 看下面的代码: & ...

  8. Python之Suds库调用WCF时复杂参数序列化

    今天主要做自动化测技术支持工作,最近一直在做接口自动化这块,前些天在研究将web页面模拟http进行接口自动化,这周杭州那边想测试WCF服务,所以这两天一直在探索.遇到的第一个问题就是服务参数传参序列 ...

  9. SpringMVC源码情操陶冶-AbstractHandlerMapping

    分析下springmvc的HandlerMapping映射的抽象类 初始化操作 通过initApplicationContext()方法进行初始化,其一般是由父类执行ApplicationContex ...

  10. #1280 : Rikka with Sequence II [meet int the middle]

    tle弃疗了 等着回学校找个标程拍一下吧 #include <iostream> #include <cstdio> #include <cstring> #inc ...