Search in sources :

Example 6 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class NativeRoleServiceTest method getUnAssignedUsersNonRecursive.

@Test
void getUnAssignedUsersNonRecursive() {
    String token = getAdminToken();
    Map<String, Object> jsonAsMap = new HashMap<>();
    jsonAsMap.put("user_id", "aragorn");
    jsonAsMap.put("email", "aragorn@lordoftherings.org");
    jsonAsMap.put("full_name", "Aragorn King of Gondor ");
    jsonAsMap.put("password", "pAssw0rD");
    try {
        given().spec(getRequestSpec(token, getUserServicePath())).contentType(JSON).body(jsonAsMap).when().post().then().statusCode(201);
        given().spec(getRequestSpec(token)).contentType(JSON).when().put("archiva-global-repository-observer/user/aragorn").then().statusCode(200);
        Response result = given().spec(getRequestSpec(token)).contentType(JSON).when().get("archiva-global-repository-observer/unassigned").then().statusCode(200).extract().response();
        assertNotNull(result);
        PagedResult<UserInfo> userResult = result.getBody().jsonPath().getObject("", PagedResult.class);
        assertNotNull(userResult);
        assertEquals(2, userResult.getPagination().getTotalCount());
        List<UserInfo> users = result.getBody().jsonPath().getList("data", UserInfo.class);
        assertFalse(users.stream().filter(user -> "aragorn".equals(user.getUserId())).findAny().isPresent());
    } finally {
        given().spec(getRequestSpec(token, getUserServicePath())).contentType(JSON).when().delete("aragorn").then().statusCode(200);
    }
}
Also used : Response(io.restassured.response.Response) Arrays(java.util.Arrays) HashMap(java.util.HashMap) Nested(org.junit.jupiter.api.Nested) AfterAll(org.junit.jupiter.api.AfterAll) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) TestInstance(org.junit.jupiter.api.TestInstance) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) JSON(io.restassured.http.ContentType.JSON) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Permission(org.apache.archiva.redback.rest.api.model.v2.Permission) DisplayName(org.junit.jupiter.api.DisplayName) MethodOrderer(org.junit.jupiter.api.MethodOrderer) RoleTemplate(org.apache.archiva.redback.rest.api.model.v2.RoleTemplate) Test(org.junit.jupiter.api.Test) List(java.util.List) Response(io.restassured.response.Response) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Matchers.equalTo(org.hamcrest.Matchers.equalTo) DEFAULT_PAGE_LIMIT(org.apache.archiva.redback.rest.api.Constants.DEFAULT_PAGE_LIMIT) Assertions(org.junit.jupiter.api.Assertions) BaseUserInfo(org.apache.archiva.redback.rest.api.model.v2.BaseUserInfo) RestAssured.given(io.restassured.RestAssured.given) RoleInfo(org.apache.archiva.redback.rest.api.model.v2.RoleInfo) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Matchers.anyOf(org.hamcrest.Matchers.anyOf) HashMap(java.util.HashMap) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) BaseUserInfo(org.apache.archiva.redback.rest.api.model.v2.BaseUserInfo) Test(org.junit.jupiter.api.Test)

Example 7 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class NativeRoleServiceTest method getUnAssignedUsersRecursive.

@Test
void getUnAssignedUsersRecursive() {
    String token = getAdminToken();
    Map<String, Object> jsonAsMap = new HashMap<>();
    jsonAsMap.put("user_id", "aragorn");
    jsonAsMap.put("email", "aragorn@lordoftherings.org");
    jsonAsMap.put("full_name", "Aragorn King of Gondor ");
    jsonAsMap.put("password", "pAssw0rD");
    try {
        given().spec(getRequestSpec(token, getUserServicePath())).contentType(JSON).body(jsonAsMap).when().post().then().statusCode(201);
        given().spec(getRequestSpec(token)).contentType(JSON).when().put("archiva-global-repository-observer/user/aragorn").then().statusCode(200);
        Response result = given().spec(getRequestSpec(token)).contentType(JSON).when().param("recurse").get("archiva-global-repository-observer/unassigned").then().statusCode(200).extract().response();
        assertNotNull(result);
        PagedResult<UserInfo> userResult = result.getBody().jsonPath().getObject("", PagedResult.class);
        assertNotNull(userResult);
        assertEquals(1, userResult.getPagination().getTotalCount());
        List<UserInfo> users = result.getBody().jsonPath().getList("data", UserInfo.class);
        assertTrue("guest".equals(users.get(0).getUserId()));
    } finally {
        given().spec(getRequestSpec(token, getUserServicePath())).contentType(JSON).when().delete("aragorn").then().statusCode(200);
    }
}
Also used : Response(io.restassured.response.Response) HashMap(java.util.HashMap) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) BaseUserInfo(org.apache.archiva.redback.rest.api.model.v2.BaseUserInfo) Test(org.junit.jupiter.api.Test)

Example 8 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class NativeUserServiceTest method getUsers.

@Test
void getUsers() {
    String token = getAdminToken();
    Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get().then().statusCode(200).extract().response();
    assertNotNull(response);
    List<UserInfo> userData = response.body().jsonPath().getList("data", UserInfo.class);
    assertNotNull(userData);
    assertEquals(2, userData.size());
    assertEquals(Integer.valueOf(0), response.body().jsonPath().get("pagination.offset"));
    assertEquals(Integer.valueOf(DEFAULT_PAGE_LIMIT), response.body().jsonPath().get("pagination.limit"));
    assertEquals(Integer.valueOf(2), response.body().jsonPath().get("pagination.total_count"));
}
Also used : Response(io.restassured.response.Response) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) Test(org.junit.jupiter.api.Test)

Example 9 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class DefaultRoleService method getUnassignedUsers.

@Override
public PagedResult<UserInfo> getUnassignedUsers(String roleId, String recurse, String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order) throws RedbackServiceException {
    boolean ascending = isAscending(order);
    boolean recursePresent = RestUtil.isFlagSet(uriInfo, "recurse");
    boolean parentsOnly = "parentsOnly".equals(recurse);
    try {
        org.apache.archiva.redback.rbac.Role rbacRole = rbacManager.getRoleById(roleId);
        final Set<String> assignedUsers = (recursePresent ? getAssignedRedbackUsersRecursive(rbacRole, parentsOnly) : getAssignedRedbackUsers(rbacRole)).stream().map(user -> user.getId()).collect(Collectors.toSet());
        List<? extends User> rawUsers = userManager.getUsers(ascending).stream().filter(user -> !assignedUsers.contains(user.getId())).collect(Collectors.toList());
        return getUserInfoPagedResult(rawUsers, searchTerm, offset, limit, orderBy, ascending);
    } catch (RbacObjectNotFoundException e) {
        throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_ROLE_NOT_FOUND, e.getMessage()), 404);
    } catch (RbacManagerException e) {
        throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_RBACMANAGER_FAIL, e.getMessage()));
    } catch (UserManagerException e) {
        throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USERMANAGER_FAIL, e.getMessage()));
    }
}
Also used : RbacObjectNotFoundException(org.apache.archiva.redback.rbac.RbacObjectNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) PermanentRoleDeletionInvalid(org.apache.archiva.redback.role.PermanentRoleDeletionInvalid) StringUtils(org.apache.commons.lang3.StringUtils) RoleExistsException(org.apache.archiva.redback.role.RoleExistsException) RoleNotFoundException(org.apache.archiva.redback.role.RoleNotFoundException) RoleModelUtils(org.apache.archiva.redback.role.util.RoleModelUtils) Inject(javax.inject.Inject) UserManager(org.apache.archiva.redback.users.UserManager) BiPredicate(java.util.function.BiPredicate) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) HttpServletRequest(javax.servlet.http.HttpServletRequest) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException) RBACManager(org.apache.archiva.redback.rbac.RBACManager) Service(org.springframework.stereotype.Service) RestUtil(org.apache.archiva.components.rest.util.RestUtil) Map(java.util.Map) Role(org.apache.archiva.redback.rest.api.model.v2.Role) Named(javax.inject.Named) RedbackServiceException(org.apache.archiva.redback.rest.api.services.RedbackServiceException) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) QueryHelper(org.apache.archiva.components.rest.util.QueryHelper) User(org.apache.archiva.redback.users.User) Predicate(java.util.function.Predicate) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) RoleService(org.apache.archiva.redback.rest.api.services.v2.RoleService) UserManagerException(org.apache.archiva.redback.users.UserManagerException) RoleManager(org.apache.archiva.redback.role.RoleManager) Collectors(java.util.stream.Collectors) MessageKeys(org.apache.archiva.redback.rest.api.MessageKeys) ErrorMessage(org.apache.archiva.redback.rest.api.model.ErrorMessage) UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException) RoleTemplate(org.apache.archiva.redback.rest.api.model.v2.RoleTemplate) List(java.util.List) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) RoleInfo(org.apache.archiva.redback.rest.api.model.v2.RoleInfo) UriInfo(javax.ws.rs.core.UriInfo) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Comparator(java.util.Comparator) RbacObjectNotFoundException(org.apache.archiva.redback.rbac.RbacObjectNotFoundException) RedbackServiceException(org.apache.archiva.redback.rest.api.services.RedbackServiceException) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) UserManagerException(org.apache.archiva.redback.users.UserManagerException)

Example 10 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class DefaultUserService method createAdminUser.

@Override
public UserInfo createAdminUser(User adminUser) throws RedbackServiceException {
    UserInfo result;
    if (getAdminStatus().isExists()) {
        log.warn("Admin user exists already");
        httpServletResponse.setHeader("Location", uriInfo.getAbsolutePath().toString());
        throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USER_ADMIN_EXISTS), 303);
    }
    log.debug("Creating admin admin user '{}'", adminUser.getUserId());
    if (!RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME.equals(adminUser.getUserId())) {
        log.error("Wrong admin user name {}", adminUser.getUserId());
        throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USER_ADMIN_BAD_NAME), 422);
    }
    try {
        org.apache.archiva.redback.users.User user = userManager.createUser(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME, adminUser.getFullName(), adminUser.getEmail());
        user.setPassword(adminUser.getPassword());
        user.setLocked(false);
        user.setPasswordChangeRequired(false);
        user.setPermanent(true);
        user.setValidated(true);
        userManager.addUser(user);
        result = getRestUser(user);
        roleManager.assignRole("system-administrator", user.getUsername());
    } catch (RoleManagerException e) {
        throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_ROLEMANAGER_FAIL, e.getMessage()), 400);
    } catch (UserManagerException e) {
        throw new RedbackServiceException(ErrorMessage.of(MessageKeys.ERR_USERMANAGER_FAIL, e.getMessage()), 400);
    }
    httpServletResponse.setStatus(201);
    httpServletResponse.setHeader("Location", uriInfo.getAbsolutePath().toString());
    return result;
}
Also used : 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