mirror of
https://github.com/fabioformosa/quartz-manager.git
synced 2025-12-27 20:53:17 +09:00
#32 clean up
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
<groupId>it.fabioformosa.quartz-manager</groupId>
|
||||
<artifactId>quartz-manager-parent</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -27,17 +27,17 @@
|
||||
<dependency>
|
||||
<groupId>it.fabioformosa.quartz-manager</groupId>
|
||||
<artifactId>quartz-manager-api</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>it.fabioformosa.quartz-manager</groupId>
|
||||
<artifactId>quartz-manager-security</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>it.fabioformosa.quartz-manager</groupId>
|
||||
<artifactId>quartz-manager-ui-webjar</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>it.fabioformosa.quartz-manager</groupId>
|
||||
<artifactId>quartz-manager-parent</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>quartz-manager-api</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>it.fabioformosa.quartz-manager</groupId>
|
||||
<artifactId>quartz-manager-parent</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>quartz-manager-security</artifactId>
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.controllers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import it.fabioformosa.quartzmanager.security.helpers.impl.JwtTokenHelper;
|
||||
import it.fabioformosa.quartzmanager.security.models.UserTokenState;
|
||||
import it.fabioformosa.quartzmanager.security.services.impl.CustomUserDetailsService;
|
||||
|
||||
/**
|
||||
* JWT Temporary disabled
|
||||
*
|
||||
* @author Fabio.Formosa
|
||||
*
|
||||
*/
|
||||
|
||||
//@RestController
|
||||
//@RequestMapping( value = "/api", produces = MediaType.APPLICATION_JSON_VALUE )
|
||||
public class AuthenticationController {
|
||||
|
||||
static class PasswordChanger {
|
||||
public String oldPassword;
|
||||
public String newPassword;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private CustomUserDetailsService userDetailsService;
|
||||
|
||||
@Autowired
|
||||
JwtTokenHelper tokenHelper;
|
||||
|
||||
@Value("${quartz-manager.security.jwt.expiration-in-sec}")
|
||||
private int EXPIRES_IN_SEC;
|
||||
|
||||
@Value("${quartz-manager.security.jwt.cookie-strategy-cookie}")
|
||||
private String TOKEN_COOKIE;
|
||||
|
||||
@RequestMapping(value = "/changePassword", method = RequestMethod.POST)
|
||||
@PreAuthorize("hasRole('USER')")
|
||||
public ResponseEntity<?> changePassword(@RequestBody PasswordChanger passwordChanger) {
|
||||
userDetailsService.changePassword(passwordChanger.oldPassword, passwordChanger.newPassword);
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put( "result", "success" );
|
||||
return ResponseEntity.accepted().body(result);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/refresh", method = RequestMethod.GET)
|
||||
public ResponseEntity<?> refreshAuthenticationToken(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
String authToken = tokenHelper.retrieveToken( request );
|
||||
if (authToken != null && tokenHelper.canTokenBeRefreshed(authToken)) {
|
||||
// TODO check user password last update
|
||||
String refreshedToken = tokenHelper.refreshToken(authToken);
|
||||
|
||||
Cookie authCookie = new Cookie( TOKEN_COOKIE, refreshedToken );
|
||||
authCookie.setPath( "/quartz-manager" );
|
||||
authCookie.setHttpOnly( true );
|
||||
authCookie.setMaxAge( EXPIRES_IN_SEC );
|
||||
// Add cookie to response
|
||||
response.addCookie( authCookie );
|
||||
|
||||
UserTokenState userTokenState = new UserTokenState(refreshedToken, EXPIRES_IN_SEC);
|
||||
return ResponseEntity.ok(userTokenState);
|
||||
} else {
|
||||
UserTokenState userTokenState = new UserTokenState();
|
||||
return ResponseEntity.accepted().body(userTokenState);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,24 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
|
||||
|
||||
//@Component
|
||||
//@ConditionalOnProperty(prefix = "quartz-manager.security.login-model", name = "form-login-enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class AuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
|
||||
|
||||
private final JwtAuthenticationSuccessHandler jwtAuthenticationSuccessHandler;
|
||||
private final JwtAuthenticationSuccessHandler jwtAuthenticationSuccessHandler;
|
||||
|
||||
// @Autowired
|
||||
public AuthenticationSuccessHandler(JwtAuthenticationSuccessHandler jwtAuthenticationSuccessHandler) {
|
||||
super();
|
||||
this.jwtAuthenticationSuccessHandler = jwtAuthenticationSuccessHandler;
|
||||
}
|
||||
public AuthenticationSuccessHandler(JwtAuthenticationSuccessHandler jwtAuthenticationSuccessHandler) {
|
||||
super();
|
||||
this.jwtAuthenticationSuccessHandler = jwtAuthenticationSuccessHandler;
|
||||
}
|
||||
|
||||
public String cookieMustBeDeletedAtLogout() {
|
||||
return jwtAuthenticationSuccessHandler.cookieMustBeDeletedAtLogout();
|
||||
}
|
||||
public String cookieMustBeDeletedAtLogout() {
|
||||
return jwtAuthenticationSuccessHandler.cookieMustBeDeletedAtLogout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
|
||||
Authentication authentication ) throws IOException, ServletException {
|
||||
clearAuthenticationAttributes(request);
|
||||
jwtAuthenticationSuccessHandler.onLoginSuccess(authentication, response);
|
||||
}
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
|
||||
Authentication authentication ) throws IOException, ServletException {
|
||||
clearAuthenticationAttributes(request);
|
||||
jwtAuthenticationSuccessHandler.onLoginSuccess(authentication, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.helpers.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ComboEntryPoint extends LoginUrlAuthenticationEntryPoint {
|
||||
|
||||
private static final String LOGIN_FORM_URL = "/login";
|
||||
|
||||
public ComboEntryPoint() {
|
||||
super(LOGIN_FORM_URL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response,
|
||||
AuthenticationException authException) throws IOException, ServletException {
|
||||
|
||||
if (RESTRequestMatcher.isRestRequest(request)
|
||||
|| WebsocketRequestMatcher.isWebsocketConnectionRequest(request))
|
||||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
|
||||
else
|
||||
super.commence(request, response, authException);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,15 +33,12 @@ public class JwtTokenHelper {
|
||||
return Base64.getEncoder().encodeToString(secretKey.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
// @Value("${app.name}")
|
||||
private final String appName;
|
||||
|
||||
// @Autowired
|
||||
private final JwtSecurityProperties jwtSecurityProps;
|
||||
|
||||
private SignatureAlgorithm SIGNATURE_ALGORITHM = SignatureAlgorithm.HS512;
|
||||
|
||||
// @Autowired
|
||||
public JwtTokenHelper(String appName, JwtSecurityProperties jwtSecurityProps) {
|
||||
super();
|
||||
this.appName = appName;
|
||||
|
||||
@@ -15,43 +15,42 @@ import it.fabioformosa.quartzmanager.security.helpers.LoginConfigurer;
|
||||
*/
|
||||
public class QuartzManagerHttpSecurity extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
||||
|
||||
public static QuartzManagerHttpSecurity from(HttpSecurity httpSecurity){
|
||||
QuartzManagerHttpSecurity newInstance = new QuartzManagerHttpSecurity(httpSecurity);
|
||||
newInstance.setBuilder(httpSecurity);
|
||||
return newInstance;
|
||||
}
|
||||
public static QuartzManagerHttpSecurity from(HttpSecurity httpSecurity){
|
||||
QuartzManagerHttpSecurity newInstance = new QuartzManagerHttpSecurity(httpSecurity);
|
||||
newInstance.setBuilder(httpSecurity);
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
private HttpSecurity httpSecurity;
|
||||
private HttpSecurity httpSecurity;
|
||||
|
||||
private LoginConfigurer loginConfigurer;
|
||||
private LoginConfigurer loginConfigurer;
|
||||
|
||||
private LogoutSuccess logoutSuccess;
|
||||
private LogoutSuccess logoutSuccess;
|
||||
|
||||
public QuartzManagerHttpSecurity(HttpSecurity httpSecurity) {
|
||||
this.httpSecurity = httpSecurity;
|
||||
// applicationContext = httpSecurity.getSharedObject(ApplicationContext.class);
|
||||
}
|
||||
public QuartzManagerHttpSecurity(HttpSecurity httpSecurity) {
|
||||
this.httpSecurity = httpSecurity;
|
||||
}
|
||||
|
||||
public QuartzManagerHttpSecurity login(String loginPath, AuthenticationManager authenticationManager) throws Exception {
|
||||
if(loginConfigurer == null || logoutSuccess == null)
|
||||
throw new IllegalStateException("QuartzManagerHttpSecurity requires to be set loginConfigurer and logoutSuccess!");
|
||||
httpSecurity = loginConfigurer.login(loginPath, httpSecurity, authenticationManager);
|
||||
return this;
|
||||
}
|
||||
public QuartzManagerHttpSecurity login(String loginPath, AuthenticationManager authenticationManager) throws Exception {
|
||||
if(loginConfigurer == null || logoutSuccess == null)
|
||||
throw new IllegalStateException("QuartzManagerHttpSecurity requires to be set loginConfigurer and logoutSuccess!");
|
||||
httpSecurity = loginConfigurer.login(loginPath, httpSecurity, authenticationManager);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public LogoutConfigurer<HttpSecurity> logout(String logoutPath) throws Exception {
|
||||
LogoutConfigurer<HttpSecurity> logoutConfigurer = httpSecurity.logout().logoutRequestMatcher(new AntPathRequestMatcher(logoutPath))
|
||||
.logoutSuccessHandler(logoutSuccess);
|
||||
String cookie = loginConfigurer.cookieMustBeDeletedAtLogout();
|
||||
if(cookie != null)
|
||||
logoutConfigurer.deleteCookies(cookie);
|
||||
return logoutConfigurer;
|
||||
}
|
||||
public LogoutConfigurer<HttpSecurity> logout(String logoutPath) throws Exception {
|
||||
LogoutConfigurer<HttpSecurity> logoutConfigurer = httpSecurity.logout().logoutRequestMatcher(new AntPathRequestMatcher(logoutPath))
|
||||
.logoutSuccessHandler(logoutSuccess);
|
||||
String cookie = loginConfigurer.cookieMustBeDeletedAtLogout();
|
||||
if(cookie != null)
|
||||
logoutConfigurer.deleteCookies(cookie);
|
||||
return logoutConfigurer;
|
||||
}
|
||||
|
||||
public QuartzManagerHttpSecurity withLoginConfigurer(LoginConfigurer loginConfigurer, LogoutSuccess logoutSuccess) {
|
||||
this.loginConfigurer = loginConfigurer;
|
||||
this.logoutSuccess = logoutSuccess;
|
||||
return this;
|
||||
}
|
||||
public QuartzManagerHttpSecurity withLoginConfigurer(LoginConfigurer loginConfigurer, LogoutSuccess logoutSuccess) {
|
||||
this.loginConfigurer = loginConfigurer;
|
||||
this.logoutSuccess = logoutSuccess;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.helpers.impl;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.web.util.matcher.ELRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
|
||||
public class RESTRequestMatcher {
|
||||
|
||||
static private final Logger log = LoggerFactory.getLogger(RESTRequestMatcher.class);
|
||||
|
||||
static public RequestMatcher matcherRequestedWith = new ELRequestMatcher(
|
||||
"hasHeader('X-Requested-With','XMLHttpRequest')");
|
||||
static public RequestMatcher matcherAccept = new ELRequestMatcher(
|
||||
"hasHeader('accept','application/json, text/plain, */*')");
|
||||
|
||||
static public boolean isRestRequest(HttpServletRequest request) {
|
||||
log.trace("Detecting if it's an AJAX Request: " + request.getRequestURL() + " accept: "
|
||||
+ request.getHeader("accept") + " " + " X-Requested-With: "
|
||||
+ request.getHeader("X-Requested-With"));
|
||||
return matcherRequestedWith.matches(request) || matcherAccept.matches(request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.helpers.impl;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class WebsocketRequestMatcher {
|
||||
|
||||
static private final Logger log = LoggerFactory.getLogger(WebsocketRequestMatcher.class);
|
||||
|
||||
static public boolean isWebsocketConnectionRequest(HttpServletRequest request) {
|
||||
log.trace("Detecting if it's a Websocket Connection Request: " + request.getRequestURL());
|
||||
return request.getServletPath().equals("/progress/info")
|
||||
|| request.getServletPath().equals("/logs/info");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,35 +19,37 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
//@Table(name="Authority")
|
||||
public class Authority implements GrantedAuthority {
|
||||
|
||||
@Id
|
||||
@Column(name="id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Long id;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name="name")
|
||||
String name;
|
||||
@Id
|
||||
@Column(name="id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Long id;
|
||||
|
||||
@Override
|
||||
public String getAuthority() {
|
||||
return name;
|
||||
}
|
||||
@Column(name="name")
|
||||
String name;
|
||||
|
||||
@JsonIgnore
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@Override
|
||||
public String getAuthority() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@JsonIgnore
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
@JsonIgnore
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,106 +28,105 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
//@Entity
|
||||
//@Table(name = "USER")
|
||||
public class User implements UserDetails, Serializable {
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "username")
|
||||
private String username;
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@JsonIgnore
|
||||
@Column(name = "password")
|
||||
private String password;
|
||||
@Column(name = "username")
|
||||
private String username;
|
||||
|
||||
@Column(name = "firstname")
|
||||
private String firstname;
|
||||
@JsonIgnore
|
||||
@Column(name = "password")
|
||||
private String password;
|
||||
|
||||
@Column(name = "lastname")
|
||||
private String lastname;
|
||||
@Column(name = "firstname")
|
||||
private String firstname;
|
||||
|
||||
@Column(name = "lastname")
|
||||
private String lastname;
|
||||
|
||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "user_authority",
|
||||
joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "authority_id", referencedColumnName = "id"))
|
||||
private List<Authority> authorities;
|
||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "user_authority", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "authority_id", referencedColumnName = "id"))
|
||||
private List<Authority> authorities;
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
// We can add the below fields in the users table.
|
||||
// For now, they are hardcoded.
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
// We can add the below fields in the users table.
|
||||
// For now, they are hardcoded.
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setAuthorities(List<Authority> authorities) {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
public void setAuthorities(List<Authority> authorities) {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
public void setLastname(String lastname) {
|
||||
|
||||
this.lastname = lastname;
|
||||
}
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.repositories;
|
||||
|
||||
/**
|
||||
* Temporary disabled
|
||||
*
|
||||
* @author Fabio
|
||||
*
|
||||
*/
|
||||
//public interface AuthorityRepository extends JpaRepository<Authority, Long> {
|
||||
// Authority findByName(String name);
|
||||
//}
|
||||
public interface AuthorityRepository {
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.repositories;
|
||||
|
||||
import it.fabioformosa.quartzmanager.security.models.User;
|
||||
|
||||
public interface UserRepository {
|
||||
User findByUsername( String username );
|
||||
}
|
||||
//public interface UserRepository extends JpaRepository<User, Long> {
|
||||
// User findByUsername( String username );
|
||||
//}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.services;
|
||||
|
||||
/**
|
||||
* temporary disabled
|
||||
* @author Fabio
|
||||
*
|
||||
*/
|
||||
public interface AuthorityService {
|
||||
// List<Authority> findById(Long id);
|
||||
//
|
||||
// List<Authority> findByname(String name);
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import it.fabioformosa.quartzmanager.security.models.User;
|
||||
import it.fabioformosa.quartzmanager.security.models.UserRequest;
|
||||
|
||||
public interface UserService {
|
||||
List<User> findAll();
|
||||
|
||||
User findById(Long id);
|
||||
|
||||
User findByUsername(String username);
|
||||
|
||||
void resetCredentials();
|
||||
|
||||
User save(UserRequest user);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.services.impl;
|
||||
|
||||
import it.fabioformosa.quartzmanager.security.services.AuthorityService;
|
||||
|
||||
/**
|
||||
* Temporary disabled
|
||||
* @author Fabio
|
||||
*
|
||||
*/
|
||||
|
||||
//@Service
|
||||
public class AuthorityServiceImpl implements AuthorityService {
|
||||
|
||||
// @Autowired
|
||||
// private AuthorityRepository authorityRepository;
|
||||
//
|
||||
// @Override
|
||||
// public List<Authority> findById(Long id) {
|
||||
// Authority auth = this.authorityRepository.getOne(id);
|
||||
// List<Authority> auths = new ArrayList<>();
|
||||
// auths.add(auth);
|
||||
// return auths;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Authority> findByname(String name) {
|
||||
// Authority auth = this.authorityRepository.findByName(name);
|
||||
// List<Authority> auths = new ArrayList<>();
|
||||
// auths.add(auth);
|
||||
// return auths;
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.services.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import it.fabioformosa.quartzmanager.security.models.User;
|
||||
import it.fabioformosa.quartzmanager.security.repositories.UserRepository;
|
||||
|
||||
/**
|
||||
* Temporary disabled
|
||||
* @author Fabio
|
||||
*
|
||||
*/
|
||||
//@Service
|
||||
public class CustomUserDetailsService implements UserDetailsService {
|
||||
|
||||
protected final Log LOGGER = LogFactory.getLog(getClass());
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Autowired
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
public void changePassword(String oldPassword, String newPassword) {
|
||||
|
||||
// Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
|
||||
// String username = currentUser.getName();
|
||||
//
|
||||
// if (authenticationManager != null) {
|
||||
// LOGGER.debug("Re-authenticating user '"+ username + "' for password change request.");
|
||||
//
|
||||
// authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, oldPassword));
|
||||
// } else {
|
||||
// LOGGER.debug("No authentication manager set. can't change Password!");
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// LOGGER.debug("Changing password for user '"+ username + "'");
|
||||
//
|
||||
// User user = (User) loadUserByUsername(username);
|
||||
//
|
||||
// user.setPassword(passwordEncoder.encode(newPassword));
|
||||
// userRepository.save(user);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
User user = userRepository.findByUsername(username);
|
||||
if (user == null)
|
||||
throw new UsernameNotFoundException(String.format("No user found with username '%s'.", username));
|
||||
else
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package it.fabioformosa.quartzmanager.security.services.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import it.fabioformosa.quartzmanager.security.models.User;
|
||||
import it.fabioformosa.quartzmanager.security.models.UserRequest;
|
||||
import it.fabioformosa.quartzmanager.security.repositories.UserRepository;
|
||||
import it.fabioformosa.quartzmanager.security.services.AuthorityService;
|
||||
import it.fabioformosa.quartzmanager.security.services.UserService;
|
||||
|
||||
/**
|
||||
* Temporary disabled
|
||||
* @author Fabio
|
||||
*
|
||||
*/
|
||||
//@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Autowired
|
||||
private AuthorityService authService;
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public List<User> findAll() throws AccessDeniedException {
|
||||
// List<User> result = userRepository.findAll();
|
||||
// return result;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public User findById(Long id) throws AccessDeniedException {
|
||||
// User u = userRepository.getOne(id);
|
||||
// return u;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
// @PreAuthorize("hasRole('USER')")
|
||||
public User findByUsername(String username) throws UsernameNotFoundException {
|
||||
User u = userRepository.findByUsername(username);
|
||||
return u;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetCredentials() {
|
||||
// List<User> users = userRepository.findAll();
|
||||
// for (User user : users) {
|
||||
// user.setPassword(passwordEncoder.encode("123"));
|
||||
// userRepository.save(user);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public User save(UserRequest userRequest) {
|
||||
User user = new User();
|
||||
// user.setUsername(userRequest.getUsername());
|
||||
// user.setPassword(passwordEncoder.encode(userRequest.getPassword()));
|
||||
// user.setFirstname(userRequest.getFirstname());
|
||||
// user.setLastname(userRequest.getLastname());
|
||||
// List<Authority> auth = authService.findByname("ROLE_USER");
|
||||
// user.setAuthorities(auth);
|
||||
// this.userRepository.save(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>it.fabioformosa.quartz-manager</groupId>
|
||||
<artifactId>quartz-manager-parent</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>quartz-manager-ui-webjar</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>it.fabioformosa.quartz-manager</groupId>
|
||||
<artifactId>quartz-manager-parent</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>quartz-manager-web-showcase</artifactId>
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
|
||||
-- the password hash is generated by BCrypt Calculator Generator(https://www.dailycred.com/article/bcrypt-calculator)
|
||||
INSERT INTO user (id, username, password, firstname, lastname) VALUES (1, 'user', '{bcrypt}$2a$04$Vbug2lwwJGrvUXTj6z7ff.97IzVBkrJ1XfApfGNl.Z695zqcnPYra', 'John', 'Doe');
|
||||
INSERT INTO user (id, username, password, firstname, lastname) VALUES (2, 'admin', '{bcrypt}$2a$04$Vbug2lwwJGrvUXTj6z7ff.97IzVBkrJ1XfApfGNl.Z695zqcnPYra', 'Admin', 'Admin');
|
||||
|
||||
INSERT INTO authority (id, name) VALUES (1, 'ROLE_USER');
|
||||
INSERT INTO authority (id, name) VALUES (2, 'ROLE_ADMIN');
|
||||
|
||||
INSERT INTO user_authority (user_id, authority_id) VALUES (1, 1);
|
||||
INSERT INTO user_authority (user_id, authority_id) VALUES (2, 1);
|
||||
INSERT INTO user_authority (user_id, authority_id) VALUES (2, 2);
|
||||
Reference in New Issue
Block a user