update dependencies, javadoc, formatting
This commit is contained in:
@@ -9,7 +9,6 @@ import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
|
||||
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
|
||||
|
||||
|
||||
/**
|
||||
* The Class LocalRememberMeServices.
|
||||
*/
|
||||
@@ -18,18 +17,19 @@ public class LocalRememberMeServices extends PersistentTokenBasedRememberMeServi
|
||||
/**
|
||||
* Instantiates a new local remember me services.
|
||||
*
|
||||
* @param key the key
|
||||
* @param key the key
|
||||
* @param userDetailsService the user details service
|
||||
* @param tokenRepository the token repository
|
||||
* @param tokenRepository the token repository
|
||||
*/
|
||||
public LocalRememberMeServices(String key, UserDetailsService userDetailsService,
|
||||
PersistentTokenRepository tokenRepository) {
|
||||
super(key, userDetailsService, tokenRepository);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices#rememberMeRequested(javax.servlet.http.HttpServletRequest, java.lang.String)
|
||||
* @see org.springframework.security.web.authentication.rememberme.
|
||||
* AbstractRememberMeServices#rememberMeRequested(javax.servlet.http.
|
||||
* HttpServletRequest, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected boolean rememberMeRequested(HttpServletRequest request, String parameter) {
|
||||
|
||||
@@ -21,12 +21,11 @@ public class LocalUserDetails extends User {
|
||||
/**
|
||||
* Instantiates a new local user details.
|
||||
*
|
||||
* @param username the username
|
||||
* @param password the password
|
||||
* @param username the username
|
||||
* @param password the password
|
||||
* @param authorities the authorities
|
||||
*/
|
||||
public LocalUserDetails(String username, String password,
|
||||
Collection<? extends GrantedAuthority> authorities) {
|
||||
public LocalUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities) {
|
||||
super(username, password, authorities);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,17 +29,18 @@ import de.bstly.board.model.LocalUser;
|
||||
* The Class OAuth2AuthenticationSuccessHandler.
|
||||
*/
|
||||
@Component
|
||||
public class OAuth2AuthenticationSuccessHandler
|
||||
extends SavedRequestAwareAuthenticationSuccessHandler {
|
||||
public class OAuth2AuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
|
||||
|
||||
@Autowired
|
||||
private UserManager localUserManager;
|
||||
|
||||
private RememberMeServices rememberMeServices;
|
||||
|
||||
|
||||
/*
|
||||
* @see org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler#onAuthenticationSuccess(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.springframework.security.core.Authentication)
|
||||
* @see org.springframework.security.web.authentication.
|
||||
* SavedRequestAwareAuthenticationSuccessHandler#onAuthenticationSuccess(javax.
|
||||
* servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
|
||||
* org.springframework.security.core.Authentication)
|
||||
*/
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
|
||||
@@ -52,8 +53,8 @@ public class OAuth2AuthenticationSuccessHandler
|
||||
authorities.addAll(authentication.getAuthorities());
|
||||
authorities.addAll(userDetails.getAuthorities());
|
||||
|
||||
UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken(
|
||||
userDetails, null, authorities);
|
||||
UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken(userDetails,
|
||||
null, authorities);
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(newAuthentication);
|
||||
|
||||
|
||||
@@ -51,7 +51,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
private String loginTargetUrl;
|
||||
|
||||
/*
|
||||
* @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity)
|
||||
* @see org.springframework.security.config.annotation.web.configuration.
|
||||
* WebSecurityConfigurerAdapter#configure(org.springframework.security.config.
|
||||
* annotation.web.builders.HttpSecurity)
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.security.config.annotation.web.configuration.
|
||||
@@ -73,25 +75,20 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.anonymous().disable()
|
||||
// login
|
||||
.formLogin().loginPage("/login").defaultSuccessUrl(loginTargetUrl)
|
||||
.failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl
|
||||
+ "?error"))
|
||||
.and()
|
||||
.failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?error")).and()
|
||||
// remember me
|
||||
.rememberMe().rememberMeServices(rememberMeServices()).and()
|
||||
// logout
|
||||
.logout().logoutUrl("/logout")
|
||||
.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK))
|
||||
.and()
|
||||
.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)).and()
|
||||
// exception
|
||||
.exceptionHandling()
|
||||
.defaultAuthenticationEntryPointFor(
|
||||
new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED),
|
||||
.defaultAuthenticationEntryPointFor(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED),
|
||||
new AntPathRequestMatcher("/api/**"))
|
||||
.and()
|
||||
// oidc
|
||||
.oauth2Login().successHandler(oAuth2AuthenticationSuccessHandler)
|
||||
.failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl
|
||||
+ "?externalError"))
|
||||
.failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?externalError"))
|
||||
.loginPage("/login");
|
||||
}
|
||||
|
||||
@@ -124,8 +121,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
*/
|
||||
@Bean
|
||||
public RememberMeServices rememberMeServices() {
|
||||
PersistentTokenBasedRememberMeServices rememberMeServices = new LocalRememberMeServices(
|
||||
"remember-me", localUserManager, persistentTokenRepository());
|
||||
PersistentTokenBasedRememberMeServices rememberMeServices = new LocalRememberMeServices("remember-me",
|
||||
localUserManager, persistentTokenRepository());
|
||||
return rememberMeServices;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user