Commit d55ef37c authored by Jan Marchel's avatar Jan Marchel Committed by Marta Różańska
Browse files

User data

parent 2f5885b5
......@@ -432,6 +432,7 @@ deploy:adapter:
- morphemic-rc1.5
- morphemic-rc2.0
- proactive-dev
- fix-cloud-id
image: $DOCKER_DIND_IMAGE
services:
- $DOCKER_DIND_SERVICE
......
......@@ -6,6 +6,7 @@ import eu.paasage.upperware.security.authapi.SecurityConstants;
import eu.paasage.upperware.security.server.controller.request.ChangePasswordRequest;
import eu.paasage.upperware.security.server.controller.request.NewUserRequest;
import eu.paasage.upperware.security.server.controller.response.ExceptionResponse;
import eu.paasage.upperware.security.server.controller.response.UserDataResponse;
import eu.paasage.upperware.security.server.controller.response.UserResponse;
import eu.paasage.upperware.security.server.data.repository.RefreshToken;
import eu.paasage.upperware.security.server.data.repository.User;
......@@ -105,6 +106,13 @@ public class UserController {
return userService.getUsersList();
}
@GetMapping("/auth/{username}")
@ResponseStatus(HttpStatus.OK)
public UserDataResponse getUserData(@PathVariable("username") String username) {
log.info("GET request for user data for user: {}", username);
return userService.getUserDataResponse(username);
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ExceptionResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
String defaultMessage = ex.getBindingResult().getAllErrors().get(0).getDefaultMessage();
......
......@@ -20,6 +20,10 @@ public class NewUserRequest {
@ValidPassword()
private String password;
private String fullName;
private String mail;
private String passwordConfirmation;
private UserRole userRole;
......
package eu.paasage.upperware.security.server.controller.response;
import eu.paasage.upperware.security.server.data.repository.UserRole;
import lombok.*;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserDataResponse {
private String username;
private String fullName;
private String mail;
private UserRole userRole;
}
......@@ -24,6 +24,12 @@ public class User {
@Attribute(name = "sn")
private String username;
@Attribute(name = "displayName")
private String fullName;
@Attribute(name = "mail")
private String mail;
@JsonIgnore
@Attribute(name = "userPassword")
private String password;
......@@ -34,8 +40,10 @@ public class User {
@Transient
private boolean lockedAccount;
public User(String username, String password, UserRole userRole, boolean lockedAccount) {
public User(String username, String fullName, String mail, String password, UserRole userRole, boolean lockedAccount) {
this.username = username;
this.fullName = fullName;
this.mail = mail;
this.password = password;
this.userRole = userRole;
this.lockedAccount = lockedAccount;
......
......@@ -4,6 +4,7 @@ import eu.paasage.upperware.security.authapi.SecurityConstants;
import eu.paasage.upperware.security.authapi.token.JWTService;
import eu.paasage.upperware.security.server.controller.request.ChangePasswordRequest;
import eu.paasage.upperware.security.server.controller.request.NewUserRequest;
import eu.paasage.upperware.security.server.controller.response.UserDataResponse;
import eu.paasage.upperware.security.server.controller.response.UserResponse;
import eu.paasage.upperware.security.server.data.repository.User;
import eu.paasage.upperware.security.server.data.repository.UserLdapRepository;
......@@ -64,15 +65,18 @@ public class UserService {
public UserResponse create(NewUserRequest userRequest) {
User newUser = new User(userRequest.getUsername(), digestSHA(userRequest.getPassword()), userRequest.getUserRole(), false);
User newUser = new User(userRequest.getUsername(), userRequest.getFullName(), userRequest.getMail(), digestSHA(userRequest.getPassword()), userRequest.getUserRole(), false);
String userDN = createUserDN(newUser.getUsername(), newUser.getUserRole());
DirContextAdapter context = new DirContextAdapter(userDN);
context.setAttributeValues("objectclass", new String[] {"person"});
context.setAttributeValues("objectclass", new String[] {"InetOrgPerson"});
context.setAttributeValue("cn", newUser.getUsername());
context.setAttributeValue("sn", newUser.getUsername());
context.setAttributeValue("fullName", newUser.getFullName());
context.setAttributeValue("mail", newUser.getMail());
context.setAttributeValue("userPassword", newUser.getPassword());
context.setAttributeValue("pwdPolicySubentry", "cn=ppolicy,dc=example,dc=org");
......@@ -187,4 +191,15 @@ public class UserService {
.userRole(findUserRole(user.getId()))
.build();
}
public UserDataResponse getUserDataResponse(String username) {
User user = userLdapRepository.findByUsername(username)
.orElseThrow(UserNotFoundException::new);
return UserDataResponse.builder()
.username(username)
.fullName(user.getFullName())
.mail(user.getMail())
.userRole(findUserRole(user.getId()))
.build();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment