-
-
Save rsvalerio/ae9a6f7acb250c79cbdd 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
@Configuration | |
@EnableWebMvcSecurity | |
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | |
@Bean | |
public ServiceProperties serviceProperties() { | |
ServiceProperties serviceProperties = new ServiceProperties(); | |
serviceProperties.setService("https://localhost:8443/cas-sample/j_spring_cas_security_check"); | |
serviceProperties.setSendRenew(false); | |
return serviceProperties; | |
} | |
@Bean | |
public CasAuthenticationProvider casAuthenticationProvider() { | |
CasAuthenticationProvider casAuthenticationProvider = new CasAuthenticationProvider(); | |
casAuthenticationProvider.setAuthenticationUserDetailsService(authenticationUserDetailsService()); | |
casAuthenticationProvider.setServiceProperties(serviceProperties()); | |
casAuthenticationProvider.setTicketValidator(cas20ServiceTicketValidator()); | |
casAuthenticationProvider.setKey("an_id_for_this_auth_provider_only"); | |
return casAuthenticationProvider; | |
} | |
@Bean | |
public AuthenticationUserDetailsService authenticationUserDetailsService() { | |
return new TestCasAuthenticationUserDetailsService(); | |
} | |
@Bean | |
public Cas20ServiceTicketValidator cas20ServiceTicketValidator() { | |
return new Cas20ServiceTicketValidator("https://localhost:9443/cas)"; | |
} | |
@Bean | |
public CasAuthenticationFilter casAuthenticationFilter() throws Exception { | |
CasAuthenticationFilter casAuthenticationFilter = new CasAuthenticationFilter(); | |
casAuthenticationFilter.setAuthenticationManager(authenticationManager()); | |
return casAuthenticationFilter; | |
} | |
@Bean | |
public CasAuthenticationEntryPoint casAuthenticationEntryPoint() { | |
CasAuthenticationEntryPoint casAuthenticationEntryPoint = new CasAuthenticationEntryPoint(); | |
casAuthenticationEntryPoint.setLoginUrl("https://localhost:9443/cas/login"); | |
casAuthenticationEntryPoint.setServiceProperties(serviceProperties()); | |
return casAuthenticationEntryPoint; | |
} | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http | |
.addFilter(casAuthenticationFilter()); | |
http | |
.exceptionHandling() | |
.authenticationEntryPoint(casAuthenticationEntryPoint()); | |
} | |
@Override | |
protected void configure(AuthenticationManagerBuilder auth) throws Exception { | |
auth | |
.authenticationProvider(casAuthenticationProvider()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment