mirror of
https://github.com/fabioformosa/quartz-manager.git
synced 2025-12-30 22:23:15 +09:00
#6 wrapped httpsecurity
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package it.fabioformosa.quartzmanager.configuration;
|
||||
|
||||
import it.fabioformosa.quartzmanager.configuration.helpers.impl.QuartzManagerHttpSecurity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -42,7 +43,7 @@ public class WebSecurityConfigJWT extends WebSecurityConfigurerAdapter {
|
||||
|
||||
private static final String[] PATTERNS_SWAGGER_UI = {"/swagger-ui.html", "/v2/api-docs", "/swagger-resources/**", "/webjars/**"};
|
||||
|
||||
@Value("${quartz-manager.security.jwt.cookie}")
|
||||
@Value("${quartz-manager.security.jwt.cookie-strategy.cookie}")
|
||||
private String TOKEN_COOKIE;
|
||||
|
||||
// @Autowired
|
||||
@@ -81,9 +82,8 @@ public class WebSecurityConfigJWT extends WebSecurityConfigurerAdapter {
|
||||
.addFilterBefore(jwtAuthenticationTokenFilter(), BasicAuthenticationFilter.class) //
|
||||
.authorizeRequests().anyRequest().authenticated();
|
||||
|
||||
loginConfig.login(http, authenticationManager()).logout().logoutRequestMatcher(new AntPathRequestMatcher("/api/logout"))
|
||||
.logoutSuccessHandler(logoutSuccess).deleteCookies(TOKEN_COOKIE);
|
||||
|
||||
QuartzManagerHttpSecurity.from(http).login(authenticationManager()).logout().logoutRequestMatcher(new AntPathRequestMatcher("/api/logout"))
|
||||
.logoutSuccessHandler(logoutSuccess).deleteCookies(TOKEN_COOKIE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,24 +1,39 @@
|
||||
package it.fabioformosa.quartzmanager.configuration.helpers.impl;
|
||||
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
|
||||
public class QuartzManagerHttpSecurity {
|
||||
|
||||
static QuartzManagerHttpSecurity from(HttpSecurity httpSecurity) {
|
||||
QuartzManagerHttpSecurity newInstance = new QuartzManagerHttpSecurity();
|
||||
newInstance.httpSecurity = httpSecurity;
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
private HttpSecurity httpSecurity;
|
||||
|
||||
QuartzManagerHttpSecurity login(AuthenticationManager authenticationManager){
|
||||
return this;
|
||||
}
|
||||
|
||||
QuartzManagerHttpSecurity logout(){
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
package it.fabioformosa.quartzmanager.configuration.helpers.impl;
|
||||
|
||||
import it.fabioformosa.quartzmanager.configuration.helpers.LoginConfig;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
|
||||
import org.springframework.security.web.DefaultSecurityFilterChain;
|
||||
|
||||
public class QuartzManagerHttpSecurity extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
private HttpSecurity httpSecurity;
|
||||
|
||||
private final LoginConfig loginConfig;
|
||||
|
||||
public static QuartzManagerHttpSecurity from(HttpSecurity httpSecurity){
|
||||
QuartzManagerHttpSecurity newInstance = new QuartzManagerHttpSecurity(httpSecurity);
|
||||
newInstance.setBuilder(httpSecurity);
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
public QuartzManagerHttpSecurity(HttpSecurity httpSecurity) {
|
||||
this.httpSecurity = httpSecurity;
|
||||
this.applicationContext = httpSecurity.getSharedObject(ApplicationContext.class);
|
||||
this.loginConfig = this.applicationContext.getBean(LoginConfig.class);
|
||||
}
|
||||
|
||||
public QuartzManagerHttpSecurity login(AuthenticationManager authenticationManager) throws Exception {
|
||||
httpSecurity = loginConfig.login(httpSecurity, authenticationManager);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public LogoutConfigurer<HttpSecurity> logout() throws Exception {
|
||||
return httpSecurity.logout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class AuthenticationController {
|
||||
@Value("${quartz-manager.security.jwt.expiration-in-sec}")
|
||||
private int EXPIRES_IN_SEC;
|
||||
|
||||
@Value("${quartz-manager.security.jwt.cookie}")
|
||||
@Value("${quartz-manager.security.jwt.cookie-strategy-cookie}")
|
||||
private String TOKEN_COOKIE;
|
||||
|
||||
@RequestMapping(value = "/changePassword", method = RequestMethod.POST)
|
||||
|
||||
Reference in New Issue
Block a user