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

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. Linux make nginx 的时候报错

    报错如下: `conf/koi-win' and `/usr/local/nginx/conf/koi-win' are the same file   原因: 可能在编译 nginx 的时候步骤不对 ...

  2. java面向对象基础(四):抽象类和接口

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  3. MySQL刷新事务日志级别设置

    标签(linux): mysql 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 # if set to 1 , InnoDB will flush (fsync ...

  4. 【转】matlab针对不同格式文件的读写

    本技术支持指南主要处理:ASCII, binary, and MAT files.要得到MATLAB中可用来读写各种文件格式的完全函数列表,可以键入以下命令: help iofun MATLAB中有两 ...

  5. lodash源码分析之baseFindIndex中的运算符优先级

    我悟出权力本来就是不讲理的--蟑螂就是海米:也悟出要造反,内心必须强大到足以承受任何后果才行. --北岛<城门开> 本文为读 lodash 源码的第十篇,后续文章会更新到这个仓库中,欢迎 ...

  6. word文字覆盖问题

    我们在编写word文档时,偶尔会遇到这个问题: 在一个段落中的某个位置修改文字时,直接就把后面的字体给覆盖了,导致后面的句子也不完整了. 解决经过: 之前遇到这种情况,非常恼火,直接新建一个word文 ...

  7. Centos更改镜像源

    阿里云Linux安装镜像源: 1.备份原镜像文件以便于恢复. [root@localhost ~]#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repo ...

  8. VS下WPF自定义控件的基本步骤和基本代码实现

    一.自定义控件的基本步骤: (本示例项目名称为:W:添加的自定义控件名称为) 1.  在"解决方案资源管理器"窗口的项目名上: 右击à添加à新建项(Ctrl+Shift+A) 2. ...

  9. C++——函数的调用

    调用前先声明函数: >>若函数定义在调用点之前,则无需另外声明 >>若函数定义在调用点之后,则需要在调用函数前按如下形式声明函数原型(原型声明) 类型标识符   被调用函数名( ...

  10. node-glob的*匹配

    目录结构 src/js/libs/app.js src/js/index.js 测试脚本 var glob = require('glob') glob('', {}, function (err, ...