赞
踩
客户端配置
- spring:
- boot:
- admin:
- client:
- url: http://localhost:7000
- username: admin
- password: admin
- instance:
- name: admin-client
- prefer-ip: true
- application:
- name: admin-client
-
- management:
- endpoint:
- health:
- show-details: always
- endpoints:
- enabled-by-default: true
- web:
- base-path: /actuator
- exposure:
- include: '*'
-
- server:
- port: 7001
服务端配置文件
- server:
- port: 7000
-
- spring:
- application:
- name: admin-server
- security:
- user:
- name: admin
- password: admin
- management:
- endpoint:
- health:
- show-details: always
- package com.base.admin.server.config;
-
- import de.codecentric.boot.admin.server.config.AdminServerProperties;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.security.config.annotation.web.builders.HttpSecurity;
- import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
- import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
-
- @Configuration
- public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
-
- private final String adminContextPath;
-
- public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
- this.adminContextPath = adminServerProperties.getContextPath();
- }
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
- successHandler.setTargetUrlParameter("redirectTo");
- successHandler.setDefaultTargetUrl(adminContextPath + "/");
-
- http.authorizeRequests()
- //授予对所有静态资产和登录页面的公共访问权限
- .antMatchers(adminContextPath + "/assets/**").permitAll()
- .antMatchers(adminContextPath + "/login").permitAll()
- .antMatchers("/actuator/**").permitAll()
- //必须对每个其他请求进行身份验证
- .anyRequest().authenticated()
- .and()
- //配置登录和注销
- .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
- .logout().logoutUrl(adminContextPath + "/logout").and()
- //启用HTTP-Basic支持。这是Spring Boot Admin Client注册所必需的
- .httpBasic().and();
- }
- }
问题出现在权限控制这里,废话:
- package com.base.admin.server.config;
-
- import de.codecentric.boot.admin.server.config.AdminServerProperties;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.security.config.annotation.web.builders.HttpSecurity;
- import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
- import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
- import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
-
- @Configuration
- public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
-
- private final String adminContextPath;
-
- public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
- this.adminContextPath = adminServerProperties.getContextPath();
- }
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
- successHandler.setTargetUrlParameter("redirectTo");
- successHandler.setDefaultTargetUrl(adminContextPath + "/");
-
- http.authorizeRequests()
- .antMatchers("/assets/**").permitAll()
- .antMatchers("/login").permitAll()
- .anyRequest().authenticated().and()
- .formLogin().loginPage("/login")
- .successHandler(successHandler).and()
- .logout().logoutUrl("/logout").and()
- .httpBasic()
- .and()
- .csrf()
- .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
- //解决 401 问题
- .ignoringAntMatchers(
- "/instances",
- "/actuator/**"
- );
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。