mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 15:25:49 +00:00
no change
This commit is contained in:
parent
47866a9f5d
commit
55da71a36a
13 changed files with 80 additions and 109 deletions
|
@ -8,6 +8,7 @@ package org.springframework.samples.petclinic.common;
|
||||||
public final class CommonAttribute {
|
public final class CommonAttribute {
|
||||||
|
|
||||||
public static final String DESCRIPTION = "description";
|
public static final String DESCRIPTION = "description";
|
||||||
|
|
||||||
public static final String ID = "id";
|
public static final String ID = "id";
|
||||||
|
|
||||||
public static final String NAME = "name";
|
public static final String NAME = "name";
|
||||||
|
|
|
@ -94,8 +94,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ClientRegistrationRepository clientRegistrationRepository() {
|
public ClientRegistrationRepository clientRegistrationRepository() {
|
||||||
List<String> clients = Arrays.asList("google", "facebook", "github");
|
List<String> clients = Arrays.asList("google", "facebook", "github");
|
||||||
|
|
|
@ -48,7 +48,8 @@ public class UserController extends WebSocketSender {
|
||||||
|
|
||||||
private final EmailService emailService;
|
private final EmailService emailService;
|
||||||
|
|
||||||
public UserController(UserService userService, CredentialService credentialService, RoleService roleService, SecurityServiceImpl securityService, EmailService emailService) {
|
public UserController(UserService userService, CredentialService credentialService, RoleService roleService,
|
||||||
|
SecurityServiceImpl securityService, EmailService emailService) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.credentialService = credentialService;
|
this.credentialService = credentialService;
|
||||||
this.roleService = roleService;
|
this.roleService = roleService;
|
||||||
|
@ -56,7 +57,6 @@ public class UserController extends WebSocketSender {
|
||||||
this.emailService = emailService;
|
this.emailService = emailService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@InitBinder("user")
|
@InitBinder("user")
|
||||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||||
dataBinder.setDisallowedFields(CommonAttribute.USER_ID);
|
dataBinder.setDisallowedFields(CommonAttribute.USER_ID);
|
||||||
|
@ -84,7 +84,7 @@ public class UserController extends WebSocketSender {
|
||||||
return CommonView.USER_REGISTRATION;
|
return CommonView.USER_REGISTRATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(userService.existByEmail(user.getEmail())) {
|
if (userService.existByEmail(user.getEmail())) {
|
||||||
result.rejectValue("email", "5", "Email already exist !");
|
result.rejectValue("email", "5", "Email already exist !");
|
||||||
sendErrorMessage(CommonWebSocket.USER_CREATION_ERROR);
|
sendErrorMessage(CommonWebSocket.USER_CREATION_ERROR);
|
||||||
return CommonView.USER_REGISTRATION;
|
return CommonView.USER_REGISTRATION;
|
||||||
|
@ -103,15 +103,13 @@ public class UserController extends WebSocketSender {
|
||||||
sendSuccessMessage(CommonWebSocket.USER_CREATED);
|
sendSuccessMessage(CommonWebSocket.USER_CREATED);
|
||||||
|
|
||||||
// send confirmation mail
|
// send confirmation mail
|
||||||
MessageDTO message = new MessageDTO(
|
MessageDTO message = new MessageDTO(user.getFirstName(), user.getLastName(), "admin@petclinic.com",
|
||||||
user.getFirstName(), user.getLastName(),
|
user.getEmail(), "New connexion",
|
||||||
"admin@petclinic.com",
|
"Your attempt to create new account. To confirm your account, please click here : ",
|
||||||
user.getEmail(),
|
"http://localhost:8080/confirm-account?token=" + credential.getToken());
|
||||||
"New connexion",
|
|
||||||
"Your attempt to create new account. To confirm your account, please click here : ",
|
|
||||||
"http://localhost:8080/confirm-account?token=" + credential.getToken());
|
|
||||||
|
|
||||||
// emailService.sendMailAsynch(message, Locale.getDefault());
|
// TODO
|
||||||
|
// emailService.sendMailAsynch(message, Locale.getDefault());
|
||||||
|
|
||||||
log.info(message.toString());
|
log.info(message.toString());
|
||||||
|
|
||||||
|
@ -137,7 +135,7 @@ public class UserController extends WebSocketSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
clientRegistrations.forEach(registration -> oauth2AuthenticationUrls.put(registration.getClientName(),
|
clientRegistrations.forEach(registration -> oauth2AuthenticationUrls.put(registration.getClientName(),
|
||||||
"oauth2/authorization/" + registration.getRegistrationId()));
|
"oauth2/authorization/" + registration.getRegistrationId()));
|
||||||
model.put("urls", oauth2AuthenticationUrls);
|
model.put("urls", oauth2AuthenticationUrls);
|
||||||
|
|
||||||
return CommonView.USER_LOGIN;
|
return CommonView.USER_LOGIN;
|
||||||
|
@ -161,7 +159,7 @@ public class UserController extends WebSocketSender {
|
||||||
|
|
||||||
CredentialDTO credential = credentialService.findByAuthentication(authentication);
|
CredentialDTO credential = credentialService.findByAuthentication(authentication);
|
||||||
|
|
||||||
if( credential.isNew()) {
|
if (credential.isNew()) {
|
||||||
|
|
||||||
// first time authentification with this provider
|
// first time authentification with this provider
|
||||||
credential = credentialService.saveNew(authentication);
|
credential = credentialService.saveNew(authentication);
|
||||||
|
@ -169,7 +167,7 @@ public class UserController extends WebSocketSender {
|
||||||
|
|
||||||
UserDTO user = userService.findByEmail(email);
|
UserDTO user = userService.findByEmail(email);
|
||||||
|
|
||||||
if(user == null) {
|
if (user == null) {
|
||||||
user = new UserDTO();
|
user = new UserDTO();
|
||||||
user.setEmail(email);
|
user.setEmail(email);
|
||||||
user.encode(credential.getPassword());
|
user.encode(credential.getPassword());
|
||||||
|
@ -181,13 +179,11 @@ public class UserController extends WebSocketSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
// send confirmation mail
|
// send confirmation mail
|
||||||
MessageDTO message = new MessageDTO(
|
MessageDTO message = new MessageDTO(firstName, lastName, "admin@petclinic.com", credential.getEmail(),
|
||||||
firstName, lastName,
|
"New connexion from " + credential.getProvider(),
|
||||||
"admin@petclinic.com",
|
"Your attempt to connect from " + credential.getProvider()
|
||||||
credential.getEmail(),
|
+ " To confirm this connection, please click the link below : ",
|
||||||
"New connexion from " + credential.getProvider(),
|
"http://localhost:8080/confirm-account?token=" + credential.getToken());
|
||||||
"Your attempt to connect from " + credential.getProvider() + " To confirm this connection, please click the link below : ",
|
|
||||||
"http://localhost:8080/confirm-account?token=" + credential.getToken());
|
|
||||||
|
|
||||||
log.info(message.toString());
|
log.info(message.toString());
|
||||||
emailService.sendMailAsynch(message, Locale.getDefault());
|
emailService.sendMailAsynch(message, Locale.getDefault());
|
||||||
|
@ -196,13 +192,13 @@ public class UserController extends WebSocketSender {
|
||||||
authentication.eraseCredentials();
|
authentication.eraseCredentials();
|
||||||
SecurityContextHolder.clearContext();
|
SecurityContextHolder.clearContext();
|
||||||
|
|
||||||
} else if( credential.isVerified()) {
|
}
|
||||||
securityService.autoLogin(credential.getEmail(),credential.getPassword());
|
else if (credential.isVerified()) {
|
||||||
|
securityService.autoLogin(credential.getEmail(), credential.getPassword());
|
||||||
String message = String.format(CommonWebSocket.USER_LOGGED_IN, firstName, lastName);
|
String message = String.format(CommonWebSocket.USER_LOGGED_IN, firstName, lastName);
|
||||||
sendSuccessMessage(message);
|
sendSuccessMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return CommonView.HOME;
|
return CommonView.HOME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +215,7 @@ public class UserController extends WebSocketSender {
|
||||||
// find corresponding user
|
// find corresponding user
|
||||||
UserDTO user = userService.findByEmail(credential.getEmail());
|
UserDTO user = userService.findByEmail(credential.getEmail());
|
||||||
|
|
||||||
securityService.autoLogin(credential.getEmail(),credential.getPassword());
|
securityService.autoLogin(credential.getEmail(), credential.getPassword());
|
||||||
model.addAttribute(CommonAttribute.USER, user);
|
model.addAttribute(CommonAttribute.USER, user);
|
||||||
return CommonView.USER_UPDATE;
|
return CommonView.USER_UPDATE;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +247,8 @@ public class UserController extends WebSocketSender {
|
||||||
model.addAttribute(CommonAttribute.USER, user);
|
model.addAttribute(CommonAttribute.USER, user);
|
||||||
model.addAttribute(CommonAttribute.USER_ID, user.getId());
|
model.addAttribute(CommonAttribute.USER_ID, user.getId());
|
||||||
return CommonView.USER_UPDATE;
|
return CommonView.USER_UPDATE;
|
||||||
} catch (Exception exception) {
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
// user don't have profile
|
// user don't have profile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +263,7 @@ public class UserController extends WebSocketSender {
|
||||||
return CommonView.USER_UPDATE;
|
return CommonView.USER_UPDATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!user.getPassword().equals(user.getMatchingPassword())) {
|
if (!user.getPassword().equals(user.getMatchingPassword())) {
|
||||||
sendErrorMessage(CommonWebSocket.USER_UPDATED_ERROR);
|
sendErrorMessage(CommonWebSocket.USER_UPDATED_ERROR);
|
||||||
return CommonView.USER_UPDATE;
|
return CommonView.USER_UPDATE;
|
||||||
}
|
}
|
||||||
|
@ -290,7 +287,7 @@ public class UserController extends WebSocketSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/user/{userId}/edit/password")
|
@GetMapping("/user/{userId}/edit/password")
|
||||||
public String editPassword(@PathVariable("userId") Integer userId, Model model){
|
public String editPassword(@PathVariable("userId") Integer userId, Model model) {
|
||||||
try {
|
try {
|
||||||
UserDTO operator = (UserDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
UserDTO operator = (UserDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
UserDTO user = userService.findById(userId);
|
UserDTO user = userService.findById(userId);
|
||||||
|
@ -300,7 +297,8 @@ public class UserController extends WebSocketSender {
|
||||||
model.addAttribute(CommonAttribute.USER_ID, user.getId());
|
model.addAttribute(CommonAttribute.USER_ID, user.getId());
|
||||||
return CommonView.USER_CHANGE_PASSWORD;
|
return CommonView.USER_CHANGE_PASSWORD;
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
// user don't have profile
|
// user don't have profile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,20 +307,19 @@ public class UserController extends WebSocketSender {
|
||||||
|
|
||||||
@PostMapping("/user/{userId}/edit/password")
|
@PostMapping("/user/{userId}/edit/password")
|
||||||
public String updatePassword(@ModelAttribute(CommonAttribute.USER) @Valid UserDTO user, BindingResult bindingResult,
|
public String updatePassword(@ModelAttribute(CommonAttribute.USER) @Valid UserDTO user, BindingResult bindingResult,
|
||||||
@PathVariable(CommonAttribute.USER_ID) Integer userId,
|
@PathVariable(CommonAttribute.USER_ID) Integer userId, @Param("oldPassword") String oldPassword,
|
||||||
@Param("oldPassword") String oldPassword,
|
@Param("newPassword") String newPassword, @Param("newMatchingPassword") String newMatchingPassword,
|
||||||
@Param("newPassword") String newPassword,
|
Model model) {
|
||||||
@Param("newMatchingPassword") String newMatchingPassword, Model model) {
|
|
||||||
|
|
||||||
// verify the matching with old password
|
// verify the matching with old password
|
||||||
if(!user.matches(oldPassword)){
|
if (!user.matches(oldPassword)) {
|
||||||
bindingResult.rejectValue("password", "6", "Bad password !");
|
bindingResult.rejectValue("password", "6", "Bad password !");
|
||||||
model.addAttribute(CommonAttribute.USER, user);
|
model.addAttribute(CommonAttribute.USER, user);
|
||||||
return CommonView.USER_CHANGE_PASSWORD;
|
return CommonView.USER_CHANGE_PASSWORD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify matching between two password
|
// verify matching between two password
|
||||||
if(!newPassword.equals(newMatchingPassword)){
|
if (!newPassword.equals(newMatchingPassword)) {
|
||||||
bindingResult.rejectValue("password", "7", "Bad matching password !");
|
bindingResult.rejectValue("password", "7", "Bad matching password !");
|
||||||
model.addAttribute(CommonAttribute.USER, user);
|
model.addAttribute(CommonAttribute.USER, user);
|
||||||
return CommonView.USER_CHANGE_PASSWORD;
|
return CommonView.USER_CHANGE_PASSWORD;
|
||||||
|
@ -339,12 +336,12 @@ public class UserController extends WebSocketSender {
|
||||||
model.addAttribute(CommonAttribute.USER, user);
|
model.addAttribute(CommonAttribute.USER, user);
|
||||||
return CommonView.USER_UPDATE_R;
|
return CommonView.USER_UPDATE_R;
|
||||||
}
|
}
|
||||||
} catch (NullPointerException exception) {
|
}
|
||||||
|
catch (NullPointerException exception) {
|
||||||
log.error(exception.getMessage());
|
log.error(exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommonView.HOME;
|
return CommonView.HOME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,9 @@ public class CredentialDTO extends BaseDTO {
|
||||||
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
public CredentialDTO() {
|
||||||
|
}
|
||||||
|
|
||||||
public CredentialDTO(UserDTO user) {
|
public CredentialDTO(UserDTO user) {
|
||||||
this.verified = false;
|
this.verified = false;
|
||||||
this.setToken();
|
this.setToken();
|
||||||
|
@ -61,7 +64,6 @@ public class CredentialDTO extends BaseDTO {
|
||||||
this.provider = CommonParameter.DEFAULT_PROVIDER;
|
this.provider = CommonParameter.DEFAULT_PROVIDER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
@ -119,4 +121,5 @@ public class CredentialDTO extends BaseDTO {
|
||||||
|
|
||||||
return this.expiration.after(Date.from(Instant.now()));
|
return this.expiration.after(Date.from(Instant.now()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,14 +113,9 @@ public class MessageDTO implements Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "MessageDTO{" +
|
return "MessageDTO{" + "first name='" + firstName + '\'' + ", last name='" + lastName + '\'' + ", from='" + from
|
||||||
"first name='" + firstName + '\'' +
|
+ '\'' + ", to='" + to + '\'' + ", subject='" + subject + '\'' + ", content='" + content + '\''
|
||||||
", last name='" + lastName + '\'' +
|
+ ", link='" + link + '\'' + '}';
|
||||||
", from='" + from + '\'' +
|
|
||||||
", to='" + to + '\'' +
|
|
||||||
", subject='" + subject + '\'' +
|
|
||||||
", content='" + content + '\'' +
|
|
||||||
", link='" + link + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,5 @@ import java.io.Serializable;
|
||||||
* @author Paul-Emmanuel DOS SANTOS FACAO
|
* @author Paul-Emmanuel DOS SANTOS FACAO
|
||||||
*/
|
*/
|
||||||
public class RoleDTO extends NamedDTO implements Serializable {
|
public class RoleDTO extends NamedDTO implements Serializable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,22 +25,25 @@ public class UserDTO extends PersonDTO implements Serializable, UserDetails {
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@Size(min = CommonParameter.PASSWORD_MIN, max = CommonParameter.PASSWORD_MAX, message = CommonError.FORMAT_BETWEEN
|
@Size(min = CommonParameter.PASSWORD_MIN, max = CommonParameter.PASSWORD_MAX, message = CommonError.FORMAT_BETWEEN
|
||||||
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@Size(min = CommonParameter.PASSWORD_MIN, max = CommonParameter.PASSWORD_MAX, message = CommonError.FORMAT_BETWEEN
|
@Size(min = CommonParameter.PASSWORD_MIN, max = CommonParameter.PASSWORD_MAX, message = CommonError.FORMAT_BETWEEN
|
||||||
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
||||||
private String matchingPassword;
|
private String matchingPassword;
|
||||||
|
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
private boolean accountNonExpired;
|
private boolean accountNonExpired;
|
||||||
|
|
||||||
private boolean accountNonLocked;
|
private boolean accountNonLocked;
|
||||||
|
|
||||||
private boolean credentialsNonExpired;
|
private boolean credentialsNonExpired;
|
||||||
|
|
||||||
private Set<RoleDTO> roles;
|
private Set<RoleDTO> roles;
|
||||||
|
|
||||||
|
|
||||||
@Size(max = CommonParameter.PHONE_MAX, message = CommonError.FORMAT_LESS + CommonParameter.PHONE_MAX)
|
@Size(max = CommonParameter.PHONE_MAX, message = CommonError.FORMAT_LESS + CommonParameter.PHONE_MAX)
|
||||||
// @Pattern(regexp = CommonParameter.PHONE_REGEXP, message = CommonError.PHONE_FORMAT)
|
// @Pattern(regexp = CommonParameter.PHONE_REGEXP, message = CommonError.PHONE_FORMAT)
|
||||||
private String telephone;
|
private String telephone;
|
||||||
|
|
||||||
@Size(max = CommonParameter.STREET_MAX, message = CommonError.FORMAT_LESS + CommonParameter.STREET_MAX + " !")
|
@Size(max = CommonParameter.STREET_MAX, message = CommonError.FORMAT_LESS + CommonParameter.STREET_MAX + " !")
|
||||||
|
@ -140,7 +143,7 @@ public class UserDTO extends PersonDTO implements Serializable, UserDetails {
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
||||||
|
|
||||||
this.roles.forEach(role -> grantedAuthorities.add(new SimpleGrantedAuthority(role.getName())));
|
this.roles.forEach(role -> grantedAuthorities.add(new SimpleGrantedAuthority(role.getName())));
|
||||||
|
|
||||||
return grantedAuthorities;
|
return grantedAuthorities;
|
||||||
}
|
}
|
||||||
|
@ -183,7 +186,6 @@ public class UserDTO extends PersonDTO implements Serializable, UserDetails {
|
||||||
this.telephone = telephone;
|
this.telephone = telephone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getStreet1() {
|
public String getStreet1() {
|
||||||
return street1;
|
return street1;
|
||||||
}
|
}
|
||||||
|
@ -234,23 +236,12 @@ public class UserDTO extends PersonDTO implements Serializable, UserDetails {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "UserDTO{" +
|
return "UserDTO{" + "email='" + email + '\'' + ", password='" + password + '\'' + ", matchingPassword='"
|
||||||
"email='" + email + '\'' +
|
+ matchingPassword + '\'' + ", user enabled=" + enabled + ", account not expired=" + accountNonExpired
|
||||||
", password='" + password + '\'' +
|
+ ", account not locked=" + accountNonLocked + ", credentials not xxpired=" + credentialsNonExpired
|
||||||
", matchingPassword='" + matchingPassword + '\'' +
|
+ ", roles=" + roles + ", telephone='" + telephone + '\'' + ", street1='" + street1 + '\''
|
||||||
", user enabled=" + enabled +
|
+ ", street2='" + street2 + '\'' + ", street3='" + street3 + '\'' + ", zipCode='" + zipCode + '\''
|
||||||
", account not expired=" + accountNonExpired +
|
+ ", city='" + city + '\'' + ", country='" + country + '\'' + '}';
|
||||||
", account not locked=" + accountNonLocked +
|
|
||||||
", credentials not xxpired=" + credentialsNonExpired +
|
|
||||||
", roles=" + roles +
|
|
||||||
", telephone='" + telephone + '\'' +
|
|
||||||
", street1='" + street1 + '\'' +
|
|
||||||
", street2='" + street2 + '\'' +
|
|
||||||
", street3='" + street3 + '\'' +
|
|
||||||
", zipCode='" + zipCode + '\'' +
|
|
||||||
", city='" + city + '\'' +
|
|
||||||
", country='" + country + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encode(String rawPassword) {
|
public void encode(String rawPassword) {
|
||||||
|
@ -265,4 +256,5 @@ public class UserDTO extends PersonDTO implements Serializable, UserDetails {
|
||||||
|
|
||||||
return bCryptPasswordEncoder.matches(rawPassword, this.password);
|
return bCryptPasswordEncoder.matches(rawPassword, this.password);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.UUID;
|
||||||
@Entity(name = "Credential")
|
@Entity(name = "Credential")
|
||||||
@Table(name = "credentials")
|
@Table(name = "credentials")
|
||||||
public class Credential extends BaseEntity {
|
public class Credential extends BaseEntity {
|
||||||
|
|
||||||
private static final int TOKEN_EXPIRATION = 60 * 24;
|
private static final int TOKEN_EXPIRATION = 60 * 24;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -35,7 +36,7 @@ public class Credential extends BaseEntity {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Size(min = CommonParameter.PASSWORD_MIN, max = CommonParameter.PASSWORD_MAX, message = CommonError.FORMAT_BETWEEN
|
@Size(min = CommonParameter.PASSWORD_MIN, max = CommonParameter.PASSWORD_MAX, message = CommonError.FORMAT_BETWEEN
|
||||||
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
||||||
@Column(name = "password", length = CommonParameter.PASSWORD_MAX)
|
@Column(name = "password", length = CommonParameter.PASSWORD_MAX)
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@ -49,7 +50,6 @@ public class Credential extends BaseEntity {
|
||||||
@Column(name = "expiration")
|
@Column(name = "expiration")
|
||||||
private Date expiration;
|
private Date expiration;
|
||||||
|
|
||||||
|
|
||||||
public Integer getProviderId() {
|
public Integer getProviderId() {
|
||||||
return providerId;
|
return providerId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class User extends Person implements Serializable, UserDetails {
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@Size(min = CommonParameter.PASSWORD_MIN, max = CommonParameter.PASSWORD_MAX, message = CommonError.FORMAT_BETWEEN
|
@Size(min = CommonParameter.PASSWORD_MIN, max = CommonParameter.PASSWORD_MAX, message = CommonError.FORMAT_BETWEEN
|
||||||
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
+ CommonParameter.PASSWORD_MIN + " AND " + CommonParameter.PASSWORD_MAX + " !")
|
||||||
@Column(name = "password", length = CommonParameter.PASSWORD_MAX)
|
@Column(name = "password", length = CommonParameter.PASSWORD_MAX)
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@ -55,15 +55,14 @@ public class User extends Person implements Serializable, UserDetails {
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany(fetch = FetchType.EAGER)
|
||||||
@JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_id"),
|
@JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_id"),
|
||||||
inverseJoinColumns = @JoinColumn(name = "role_id"))
|
inverseJoinColumns = @JoinColumn(name = "role_id"))
|
||||||
private Set<Role> roles;
|
private Set<Role> roles;
|
||||||
|
|
||||||
@Size(max = CommonParameter.PHONE_MAX, message = CommonError.FORMAT_LESS + CommonParameter.PHONE_MAX)
|
@Size(max = CommonParameter.PHONE_MAX, message = CommonError.FORMAT_LESS + CommonParameter.PHONE_MAX)
|
||||||
// @Pattern(regexp = CommonParameter.PHONE_REGEXP, message = CommonError.PHONE_FORMAT)
|
// @Pattern(regexp = CommonParameter.PHONE_REGEXP, message = CommonError.PHONE_FORMAT)
|
||||||
@Column(name = "telephone", length = CommonParameter.EMAIL_MAX)
|
@Column(name = "telephone", length = CommonParameter.EMAIL_MAX)
|
||||||
private String telephone;
|
private String telephone;
|
||||||
|
|
||||||
|
|
||||||
@Size(max = CommonParameter.STREET_MAX, message = CommonError.FORMAT_LESS + CommonParameter.STREET_MAX + " !")
|
@Size(max = CommonParameter.STREET_MAX, message = CommonError.FORMAT_LESS + CommonParameter.STREET_MAX + " !")
|
||||||
@Column(name = "street1", length = CommonParameter.STREET_MAX)
|
@Column(name = "street1", length = CommonParameter.STREET_MAX)
|
||||||
private String street1;
|
private String street1;
|
||||||
|
@ -146,12 +145,11 @@ public class User extends Person implements Serializable, UserDetails {
|
||||||
this.credentialsNonExpired = credentialsNonExpired;
|
this.credentialsNonExpired = credentialsNonExpired;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
||||||
|
|
||||||
this.roles.forEach(role -> grantedAuthorities.add(new SimpleGrantedAuthority(role.getName())));
|
this.roles.forEach(role -> grantedAuthorities.add(new SimpleGrantedAuthority(role.getName())));
|
||||||
|
|
||||||
return grantedAuthorities;
|
return grantedAuthorities;
|
||||||
}
|
}
|
||||||
|
@ -182,7 +180,6 @@ public class User extends Person implements Serializable, UserDetails {
|
||||||
getRolesInternal().add(role);
|
getRolesInternal().add(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setRoles(Set<Role> roles) {
|
public void setRoles(Set<Role> roles) {
|
||||||
this.roles = roles;
|
this.roles = roles;
|
||||||
}
|
}
|
||||||
|
@ -195,7 +192,6 @@ public class User extends Person implements Serializable, UserDetails {
|
||||||
this.telephone = telephone;
|
this.telephone = telephone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getStreet1() {
|
public String getStreet1() {
|
||||||
return street1;
|
return street1;
|
||||||
}
|
}
|
||||||
|
@ -244,5 +240,4 @@ public class User extends Person implements Serializable, UserDetails {
|
||||||
this.country = country;
|
this.country = country;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ public class CredentialService {
|
||||||
|
|
||||||
private final ModelMapper modelMapper = new ModelMapper();
|
private final ModelMapper modelMapper = new ModelMapper();
|
||||||
|
|
||||||
public CredentialService(CredentialRepository credentialRepository, BCryptPasswordEncoder bCryptPasswordEncoder, AuthProviderRepository authProviderRepository) {
|
public CredentialService(CredentialRepository credentialRepository, BCryptPasswordEncoder bCryptPasswordEncoder,
|
||||||
|
AuthProviderRepository authProviderRepository) {
|
||||||
this.credentialRepository = credentialRepository;
|
this.credentialRepository = credentialRepository;
|
||||||
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
||||||
this.authProviderRepository = authProviderRepository;
|
this.authProviderRepository = authProviderRepository;
|
||||||
|
@ -86,7 +87,6 @@ public class CredentialService {
|
||||||
return entityToDTO(credential);
|
return entityToDTO(credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CredentialDTO save(CredentialDTO dto) {
|
public CredentialDTO save(CredentialDTO dto) {
|
||||||
Credential credential = dtoToEntity(dto);
|
Credential credential = dtoToEntity(dto);
|
||||||
credential = credentialRepository.save(credential);
|
credential = credentialRepository.save(credential);
|
||||||
|
@ -112,7 +112,8 @@ public class CredentialService {
|
||||||
public CredentialDTO saveNew(OAuth2AuthenticationToken authentication) {
|
public CredentialDTO saveNew(OAuth2AuthenticationToken authentication) {
|
||||||
Credential credential = new Credential();
|
Credential credential = new Credential();
|
||||||
|
|
||||||
AuthProvider authProvider = authProviderRepository.findByName(authentication.getAuthorizedClientRegistrationId());
|
AuthProvider authProvider = authProviderRepository
|
||||||
|
.findByName(authentication.getAuthorizedClientRegistrationId());
|
||||||
|
|
||||||
credential.setEmail(authentication.getPrincipal().getAttribute("email"));
|
credential.setEmail(authentication.getPrincipal().getAttribute("email"));
|
||||||
credential.setProviderId(authProvider.getId());
|
credential.setProviderId(authProvider.getId());
|
||||||
|
@ -125,5 +126,4 @@ public class CredentialService {
|
||||||
return entityToDTO(credential);
|
return entityToDTO(credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,16 +40,13 @@ public class EmailService {
|
||||||
@Autowired
|
@Autowired
|
||||||
protected ITemplateEngine templateEngine;
|
protected ITemplateEngine templateEngine;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sendMailAsynch : for the controller MailController
|
* sendMailAsynch : for the controller MailController send mail asynchronously
|
||||||
* send mail asynchronously
|
|
||||||
*
|
|
||||||
* @param messageDTO : message to be send by mail
|
* @param messageDTO : message to be send by mail
|
||||||
* @param locale : not used now
|
* @param locale : not used now
|
||||||
*/
|
*/
|
||||||
@Async
|
@Async
|
||||||
public void sendMailAsynch(MessageDTO messageDTO, Locale locale){
|
public void sendMailAsynch(MessageDTO messageDTO, Locale locale) {
|
||||||
sendMail(messageDTO, locale);
|
sendMail(messageDTO, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,9 @@ public class UserService implements BaseService<User, UserDTO> {
|
||||||
user.setPassword(dto.getPassword());
|
user.setPassword(dto.getPassword());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (dto.getRoles() != null) {
|
* if (dto.getRoles() != null) { for (RoleDTO roleDTO : dto.getRoles()) { Role
|
||||||
for (RoleDTO roleDTO : dto.getRoles()) {
|
* role = modelMapper.map(roleDTO, Role.class); user.addRole(role); } }
|
||||||
Role role = modelMapper.map(roleDTO, Role.class);
|
*/
|
||||||
user.addRole(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,14 +54,10 @@ public class UserService implements BaseService<User, UserDTO> {
|
||||||
UserDTO userDto = modelMapper.map(entity, UserDTO.class);
|
UserDTO userDto = modelMapper.map(entity, UserDTO.class);
|
||||||
userDto.setPassword(entity.getPassword());
|
userDto.setPassword(entity.getPassword());
|
||||||
userDto.setMatchingPassword(entity.getPassword());
|
userDto.setMatchingPassword(entity.getPassword());
|
||||||
/*
|
/*
|
||||||
if (entity.getRoles() != null) {
|
* if (entity.getRoles() != null) { for (Role role : entity.getRoles()) { RoleDTO
|
||||||
for (Role role : entity.getRoles()) {
|
* roleDTO = modelMapper.map(role, RoleDTO.class); userDto.addRole(roleDTO); } }
|
||||||
RoleDTO roleDTO = modelMapper.map(role, RoleDTO.class);
|
*/
|
||||||
userDto.addRole(roleDTO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return userDto;
|
return userDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@ spring.h2.console.path=/h2-console
|
||||||
spring.security.oauth2.client.registration.google.client-id=${OAUTH2_GOOGLE_CLIENT_ID}
|
spring.security.oauth2.client.registration.google.client-id=${OAUTH2_GOOGLE_CLIENT_ID}
|
||||||
spring.security.oauth2.client.registration.google.client-secret=${OAUTH2_GOOGLE_CLIENT_SECRET}
|
spring.security.oauth2.client.registration.google.client-secret=${OAUTH2_GOOGLE_CLIENT_SECRET}
|
||||||
|
|
||||||
spring.security.oauth2.client.registration.github.client-id=${OAUTH2_GITHUB_CLIENT_ID}
|
#spring.security.oauth2.client.registration.github.client-id=${OAUTH2_GITHUB_CLIENT_ID}
|
||||||
spring.security.oauth2.client.registration.github.client-secret=${OAUTH2_GITHUB_CLIENT_SECRET}
|
#spring.security.oauth2.client.registration.github.client-secret=${OAUTH2_GITHUB_CLIENT_SECRET}
|
||||||
|
|
||||||
|
|
||||||
#spring.security.oauth2.client.registration.facebook.client-id=<your client id>
|
#spring.security.oauth2.client.registration.facebook.client-id=<your client id>
|
||||||
|
|
Loading…
Reference in a new issue