use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.
the class DefaultAuthenticationService method buildRestUser.
private UserInfo buildRestUser(org.apache.archiva.redback.users.User user) {
UserInfo restUser = new UserInfo();
restUser.setEmail(user.getEmail());
restUser.setUserId(user.getUsername());
restUser.setPasswordChangeRequired(user.isPasswordChangeRequired());
restUser.setLocked(user.isLocked());
restUser.setValidated(user.isValidated());
restUser.setFullName(user.getFullName());
return restUser;
}
use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.
the class DefaultUserService method createUser.
@Override
public UserInfo createUser(User user) throws RedbackServiceException {
if (user == null) {
throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USER_ID_EMPTY), 422);
}
UserInfo result;
if (Arrays.binarySearch(INVALID_CREATE_USER_NAMES, user.getUserId()) >= 0) {
throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USER_ID_INVALID, user.getUserId()), 422);
}
try {
org.apache.archiva.redback.users.User u = userManager.findUser(user.getUserId());
if (u != null) {
httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(u.getUsername()).build().toString());
throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USER_EXISTS, user.getUserId()), 303);
}
} catch (UserNotFoundException e) {
// ignore we just want to prevent non human readable error message from backend :-)
log.debug("User {} does not exist", user.getUserId());
} catch (UserManagerException e) {
throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_UNKNOWN, e.getMessage()));
}
// data validation
if (StringUtils.isEmpty(user.getUserId())) {
throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USER_ID_EMPTY), 422);
}
if (StringUtils.isEmpty(user.getFullName())) {
throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USER_FULL_NAME_EMPTY), 422);
}
if (StringUtils.isEmpty(user.getEmail())) {
throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USER_EMAIL_EMPTY), 422);
}
try {
org.apache.archiva.redback.users.User u = userManager.createUser(user.getUserId(), user.getFullName(), user.getEmail());
u.setPassword(user.getPassword());
u.setLocked(user.isLocked());
u.setPasswordChangeRequired(user.isPasswordChangeRequired());
u.setValidated(user.isValidated());
u = userManager.addUser(u);
if (!user.isPasswordChangeRequired()) {
u.setPasswordChangeRequired(false);
try {
u = userManager.updateUser(u);
log.debug("User {} created", u.getUsername());
} catch (UserNotFoundException e) {
throw new RedbackServiceException(e.getMessage());
}
}
roleManager.assignRole(RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername());
result = getRestUser(u);
httpServletResponse.setStatus(201);
httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(user.getUserId()).build().toString());
} catch (RoleManagerException rpe) {
log.error("RoleProfile Error: {}", rpe.getMessage(), rpe);
throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USER_ASSIGN_ROLE));
} catch (UserManagerException e) {
log.error("UserManagerException: {}", e.getMessage(), e);
throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_UNKNOWN, e.getMessage()));
}
return result;
}
Aggregations