效果展示

BootMonitor1.png

BootMonitor3.png

BootMonitor4.png
客户端
maven引用
org.springframework.boot spring-boot-starter-parent2.0.0.RELEASE org.springframework.boot spring-boot-starter-actuatorde.codecentric spring-boot-admin-starter-client2.0.0
配置文件
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
安全保护
public class ActuatorAuthFilter implements Filter, Ordered {
private AuthService authService = SpringBootBeanUtil.getBean(AuthService.class);
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
boolean authPass = false;
HttpServletRequest req = (HttpServletRequest) request;
String system = req.getHeader("system");
String token = req.getHeader("token");
if ( !StringUtil.isEmpty(system) && !StringUtil.isEmpty(token)) {
if(system.equals("haopanwatch") && token.equals("7e447e5d38d323b847edf2b4895eb242")){
authPass = true;
}
}
if (authPass) {
chain.doFilter(request, response);
} else {
Result result = Result.errorResult().setMsg("NoAuthAccess").setCode(SystemErrorCodeEnum.ErrorCode.TokenAuthError.get_value());
response.getWriter().println(JSON.toJSON(result));
}
}
@Override
public void destroy() {
}
@Override
public int getOrder() {
return 11;
}
}
管理端
maven引用
org.springframework.boot spring-boot-starter-parent2.2.0.RELEASE org.springframework.boot spring-boot-starterorg.springframework.boot spring-boot-starter-webde.codecentric spring-boot-admin-starter-server2.2.0 org.springframework.boot spring-boot-starter-securityorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-tomcatorg.springframework.boot spring-boot-starter-jetty
配置文件
server.port=9550
spring.application.name=springboot-admin-server
#配置一个账号和密码
spring.security.user.name=admin
spring.security.user.password=abcd@1234
启动注解
@SpringBootApplication
@EnableAdminServer
public class HaopanWatchApplication {
public static void main(String[] args) {
SpringApplication.run(HaopanWatchApplication.class, args);
}
@Bean
public ApplicationRunner applicationRunner() {
return applicationArguments -> {
System.out.println("haopanwatch启动成功!");
};
}
}
安全保护
@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()
.anyRequest().authenticated()
.and()
//登录和登出路径
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
.logout().logoutUrl(adminContextPath + "/logout").and()
//开启http basic支持,admin-client注册时需要使用
.httpBasic().and()
.csrf()
//开启基于cookie的csrf保护
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
//忽略这些路径的csrf保护以便admin-client注册
.ignoringAntMatchers(
adminContextPath + "/instances",
adminContextPath + "/actuator/**"
);
}
}
客户端认证
@Component
public class HttpHeadersProviderConfig implements HttpHeadersProvider {
@Override
public HttpHeaders getHeaders(Instance instance) {
HttpHeaders httpHeaders = new HttpHeaders();
//设置约定好的请求头参数
httpHeaders.add("token", "7e447e5d38d323b847edf2b4895eb242");
httpHeaders.add("system", "haopanwatch");
return httpHeaders;
}
}
【信息由网络或者个人提供,如有涉及版权请联系COOY资源网邮箱处理】
© 版权声明
本平台(www.cooy.cn)的一切软件、教程及内容信息仅限用于学习和研究,付费仅为收集整理归类费用;
不得将上述内容用于商业或者非法用途,否则一切后果用户自行承担负责。本平台资源、内容、信息均来自来自用户上传,版权争议及其他问题与本平台无关。
您必须在下载后的24个小时之内从您的电脑或手机中彻底删除上述下载内容,如果您喜欢该程序或内容,请支持正版以获取更好的服务。我们非常重视版权问题,如有侵权请发送邮件至下方邮件(655465@qq.com),敬请谅解!
如发现违法违规内容,请联系下方邮箱举报,我们收到后将会第一时间处理。
THE END
暂无评论内容