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

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. Apache Shiro java安全框架

    什么是Apache Shiro? Apache Shiro(发音为“shee-roh”,日语“堡垒(Castle)”的意思)是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理功能,可为 ...

  2. JavaScript 函数创建思想

    //定义一个函数的步骤//1.开辟一个新的空间地址//2.把函数体里面的代码当做字符串存储到空间里面(一个函数如果只定义了,没有执行的话,这个函数没有任何意义)//3.在把我们的地址给我们的函数名fu ...

  3. ecplise最有用的8个快捷键

    1. ctrl+shift+r 打开资源 这组快捷键可以让你打开你工作区中的任何一个文件.而你只需要按下键盘的文件名或前几个字母 美中不足的是这组快捷键并非在所有视图下都能用. 2.ctrl+o:快速 ...

  4. 验证码 jsp

    验证码的jsp实现 <%@ page contentType="image/jpeg" import="java.awt.*, java.awt.image.*,j ...

  5. IO (二)

    1 字符流的缓冲区 缓冲区的出现提高了对数据的读写效率. 对应的类: BufferedWriter BufferedReader 缓冲区要结合流才能使用. 在流的基础上对流的功能进行了增强. 2 Bu ...

  6. Cacti在selinux开启的情况下使用

    # chcon -R -t httpd_sys_content_t /var/www/html/cacti

  7. 以C语言为例的程序性能优化 --《深入理解计算机系统》第五章读书笔记

    其实大多数的编译器本身就能提供一些简单的优化,比如gcc就能通过使用 -O2 或者 -O3 的选项来优化程序.但编译器的优化始终也是有限,因为它必须小心翼翼保证优化过程不对程序的功能有改动.故而程序员 ...

  8. Django中不返回QuerySets的API -- Django从入门到精通系列教程

    该系列教程系个人原创,并完整发布在个人官网刘江的博客和教程 所有转载本文者,需在顶部显著位置注明原作者及www.liujiangblog.com官网地址. Python及Django学习QQ群:453 ...

  9. [TFRecord格式数据]利用TFRecords存储与读取带标签的图片

    利用TFRecords存储与读取带标签的图片 原创文章,转载请注明出处~ 觉得有用的话,欢迎一起讨论相互学习~Follow Me TFRecords其实是一种二进制文件,虽然它不如其他格式好理解,但是 ...

  10. 从iconfont下载项目所需的图标资源

    前端开发中,经常会用到各种各样的图标(icon).这些icon,如果每个都要自己去做,那真的是耗时又耗力.但是,有了阿里巴巴矢量图标库这样的平台后,一切都变得简单了起来. 本文以此平台为例,演示如何搜 ...