Advertisement
rodrigosan88

Untitled

Nov 21st, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         SpringApplication.run(SpringBootAdminApplication.class, args);
  3.     }
  4.  
  5.     @Profile("insecure")
  6.     @Configuration
  7.     public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
  8.         private final String adminContextPath;
  9.  
  10.         public SecurityPermitAllConfig(AdminServerProperties adminServerProperties) {
  11.             this.adminContextPath = adminServerProperties.getContextPath();
  12.         }
  13.  
  14.         @Override
  15.         protected void configure(HttpSecurity http) throws Exception {
  16.             http.authorizeRequests()
  17.                 .anyRequest()
  18.                 .permitAll()
  19.                 .and()
  20.                 .csrf()
  21.                 .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
  22.                 .ignoringAntMatchers(adminContextPath + "/instances", adminContextPath + "/actuator/**");
  23.         }
  24.     }
  25.  
  26.     @Profile("secure")
  27.     @Configuration
  28.     public static class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
  29.         private final String adminContextPath;
  30.  
  31.         public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
  32.             this.adminContextPath = adminServerProperties.getContextPath();
  33.         }
  34.  
  35.         @Override
  36.         protected void configure(HttpSecurity http) throws Exception {
  37.             // @formatter:off
  38.             SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
  39.             successHandler.setTargetUrlParameter("redirectTo");
  40.             successHandler.setDefaultTargetUrl(adminContextPath + "/");
  41.  
  42.             http.authorizeRequests()
  43.                 .antMatchers(adminContextPath + "/assets/**").permitAll()
  44.                 .antMatchers(adminContextPath + "/login").permitAll()
  45.                 .anyRequest().authenticated()
  46.                 .and()
  47.             .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
  48.             .logout().logoutUrl(adminContextPath + "/logout").and()
  49.             .httpBasic().and()
  50.             .csrf()
  51.                 .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
  52.                 .ignoringAntMatchers(adminContextPath + "/instances", adminContextPath + "/actuator/**");
  53.             // @formatter:on
  54.         }
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement