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);
}
}
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);
}
}
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"));
}
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()));
}
}
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;
}
Aggregations