Home > Back-end >  Spring security integrated cas, set the home page and login/cas allow anonymous filtering through th
Spring security integrated cas, set the home page and login/cas allow anonymous filtering through th

Time:10-12

Spring security integrated cas, set the home page and login/cas allow anonymous filtering through the chain, can into the home page, login/cas at 401 error
security configuration below
HTTP
//for/request/only the authorize, other according to the default configuration/login configuration,
RequestMatchers ()
//this way, if the configuration is automatically authorized to jump to the login page
. AntMatchers ("/* * ")
And ()
AuthorizeRequests ()
//antMatchers ("/user/* * ")
//hasRole (" user ")
//. AntMatchers ("/login/cas)
AntMatchers ("/* ", "login/cas", "/document/* *", "/category/* *")
PermitAll ()
AnyRequest (). Authenticated ()
And ()
ExceptionHandling ()
. AuthenticationEntryPoint (authenticationEntryPoint)
And ()
. AddFilter (casAuthenticationFilter)
AddFilterBefore (singleSignOutFilter, CasAuthenticationFilter. Class)
AddFilterBefore (logoutFilter, logoutFilter. Class);

cas configuration below

@ Configuration
Public class CasSecurityConfig {
The @autowired
CASClientProperties CASClientProperties;
The @autowired
CASServerProperties CASServerProperties;
The @autowired
UserDetailsService userDetailService;

@ Bean
ServiceProperties ServiceProperties () {
ServiceProperties ServiceProperties=new ServiceProperties ();
ServiceProperties. SetService (casClientProperties getLogin ());
Return serviceProperties;
}

@ Bean
@ Primary
AuthenticationEntryPoint AuthenticationEntryPoint () {
CasAuthenticationEntryPoint entryPoint=new CasAuthenticationEntryPoint ();
EntryPoint. SetLoginUrl (casServerProperties getLogin ());
EntryPoint. SetServiceProperties (serviceProperties ());
Return the entryPoint;
}

@ Bean
TicketValidator TicketValidator () {
Return new Cas20ProxyTicketValidator (casServerProperties getPrefix ());
}

@ Bean
@ Primary
CasAuthenticationProvider CasAuthenticationProvider () {
CasAuthenticationProvider provider=new CasAuthenticationProvider ();
The provider. SetServiceProperties (serviceProperties ());
The provider. SetTicketValidator (ticketValidator ());
The provider. SetUserDetailsService (userDetailService);
The provider. The setKey (" DDDD ");
Return the provider;
}
@ Bean
CasAuthenticationFilter CasAuthenticationFilter (AuthenticationProvider AuthenticationProvider) {
CasAuthenticationFilter filter=new CasAuthenticationFilter ();
Filter. SetServiceProperties (serviceProperties ());
List Dd=Arrays. AsList (authenticationProvider);
Filter. SetAuthenticationManager (new ProviderManager (dd));
Return the filter;
}


@ Bean
SingleSignOutFilter SingleSignOutFilter () {
SingleSignOutFilter sign=new SingleSignOutFilter ();
Sign. SetIgnoreInitConfiguration (true);
Return the sign;
}
@ Bean
LogoutFilter LogoutFilter () {
LogoutFilter filter=new LogoutFilter (casServerProperties getLogout (), new SecurityContextLogoutHandler ());
Filter. SetFilterProcessesUrl (casClientProperties getLogoutRelative ());
Return the filter;
}

}
  • Related