Last active
October 15, 2019 13:21
-
-
Save SteelAlex/ac129a8099c9518e50f6815b3c2bfe1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Slf4j | |
@Configuration | |
@EnableWebSecurity | |
@EnableJdbcHttpSession | |
@EnableGlobalMethodSecurity(prePostEnabled = true) | |
class SecurityConfig extends WebSecurityConfigurerAdapter { | |
private static final String SESSION_STORAGE_NAME = "X-COMPANY-NAME-TOKEN"; | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http | |
.authorizeRequests() | |
.antMatchers("/").permitAll() | |
.and() | |
.sessionManagement() | |
.maximumSessions(1) | |
.maxSessionsPreventsLogin(false).and() | |
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) | |
.and() | |
.formLogin() | |
.loginPage("/") | |
.loginProcessingUrl("/auth") | |
.usernameParameter("login") | |
.passwordParameter("password") | |
.successHandler((request, response, authentication) -> { | |
//for MSIE 8 support | |
if (authentication.isAuthenticated()) { | |
log.info("Successful authentication"); | |
response.setStatus(200); | |
} else { | |
response.setStatus(401); | |
} | |
}) | |
.failureHandler((request, response, authentication) -> { | |
log.info("Failed authentication"); | |
response.setStatus(401); | |
}) | |
.and() | |
.logout() | |
.logoutUrl("/logout") | |
.logoutSuccessUrl("/index.html") | |
.invalidateHttpSession(true) | |
.clearAuthentication(true) | |
.and() | |
.httpBasic() | |
.and() | |
.csrf().disable() | |
.headers() | |
.contentTypeOptions().disable() | |
.xssProtection().disable() | |
.cacheControl() | |
.and().frameOptions().disable() | |
.and() | |
.cors() | |
.configurationSource(corsConfigurationSource()) | |
.and() | |
.requestCache() | |
; | |
} | |
@Bean | |
public HttpSessionIdResolver httpSessionIdResolver() { | |
return new HeaderHttpSessionIdResolver(SESSION_STORAGE_NAME); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fragment of build.gradle