Search in sources :

Example 26 with UserInfo

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;
}
Also used : UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo)

Example 27 with UserInfo

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;
}
Also used : UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException) RedbackServiceException(org.apache.archiva.redback.rest.api.services.RedbackServiceException) UserManagerException(org.apache.archiva.redback.users.UserManagerException) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Aggregations

UserInfo (org.apache.archiva.redback.rest.api.model.v2.UserInfo)19 Test (org.junit.jupiter.api.Test)15 Response (io.restassured.response.Response)8 HashMap (java.util.HashMap)8 UserInfo (edu.uiuc.ncsa.security.oauth_2_0.UserInfo)7 BaseUserInfo (org.apache.archiva.redback.rest.api.model.v2.BaseUserInfo)7 UserService (org.apache.archiva.redback.rest.api.services.v2.UserService)6 NotFoundException (javax.ws.rs.NotFoundException)5 User (org.apache.archiva.redback.rest.api.model.v2.User)5 ForbiddenException (javax.ws.rs.ForbiddenException)4 JSONObject (net.sf.json.JSONObject)4 RoleInfo (org.apache.archiva.redback.rest.api.model.v2.RoleInfo)4 List (java.util.List)3 Map (java.util.Map)3 PagedResult (org.apache.archiva.components.rest.model.PagedResult)3 RoleTemplate (org.apache.archiva.redback.rest.api.model.v2.RoleTemplate)3 UserRegistrationRequest (org.apache.archiva.redback.rest.api.model.v2.UserRegistrationRequest)3 RedbackServiceException (org.apache.archiva.redback.rest.api.services.RedbackServiceException)3 EmailMessage (org.apache.archiva.redback.rest.services.mock.EmailMessage)3 ServicesAssert (org.apache.archiva.redback.rest.services.mock.ServicesAssert)3