use of org.neo4j.ogm.domain.gh777.UserInfo in project OA4MP by ncsa.
the class XsedeClaimsSource method realProcessing.
@Override
protected JSONObject realProcessing(JSONObject claims, HttpServletRequest request, ServiceTransaction transaction) throws UnsupportedScopeException {
OA2ServiceTransaction t = (OA2ServiceTransaction) transaction;
myLogger.info("In XSEDE scope handler9: " + getScopes());
String subject = t.getUsername();
if (subject == null) {
myLogger.debug("No subject available in transaction");
// nothing can be done without subject info
return claims;
}
UserInfo userInfo = new UserInfo();
userInfo.setMap(claims);
// See if userInfo already has the requisite info
myLogger.debug("Profile:" + t.getScopes().contains(SCOPE_PROFILE) + ":" + userInfo.getGiven_name() + ":" + userInfo.getMiddle_name() + ":" + userInfo.getFamily_name());
myLogger.debug("EMAIL:" + userInfo.getEmail());
myLogger.debug("XSEDE:" + userInfo.getString("xsedeHomeOrganization".toString()));
if ((!t.getScopes().contains(SCOPE_PROFILE) || (userInfo.getGiven_name() != null && userInfo.getMiddle_name() != null && userInfo.getFamily_name() != null)) && (!t.getScopes().contains(SCOPE_EMAIL) || (userInfo.getEmail() != null)) && (!t.getScopes().contains(SCOPE_XSEDE) || (userInfo.getString("xsedeHomeOrganization".toString()) != null))) {
myLogger.info("Info for all claims in requested scopes already " + "available in userInfo; skipping call to XDCDB");
return (JSONObject) userInfo.getMap();
}
// One or more requisite info missing; retrieve from XCDB and set
JsonObject profile = getUserInfo(subject);
String firstName = profile.isNull("first_name".toString()) ? "".toString() : profile.getString("first_name".toString());
String middleName = profile.isNull("middle_name".toString()) ? "".toString() : profile.getString("middle_name".toString());
String lastName = profile.isNull("last_name".toString()) ? "".toString() : profile.getString("last_name".toString());
String email = profile.isNull("email".toString()) ? "".toString() : profile.getString("email".toString());
String organization = profile.isNull("organization".toString()) ? "".toString() : profile.getString("organization".toString());
if (t.getScopes().contains(SCOPE_PROFILE)) {
myLogger.info("Processing profile scope in XSEDE handler");
userInfo.setGiven_name(firstName);
userInfo.setMiddle_name(middleName);
userInfo.setFamily_name(lastName);
}
if (t.getScopes().contains(SCOPE_EMAIL)) {
myLogger.info("Processing email scope in XSEDE handler");
userInfo.setEmail(email);
}
if (t.getScopes().contains(SCOPE_XSEDE)) {
myLogger.info("Processing xsede scope in XSEDE handler");
userInfo.put("xsedeHomeOrganization".toString(), organization);
}
return (JSONObject) userInfo.getMap();
}
use of org.neo4j.ogm.domain.gh777.UserInfo in project security-lib by ncsa.
the class UII2 method processUIRequest.
/**
* @param request User info request
* @return User info response
*/
public UIIResponse2 processUIRequest(UIIRequest2 request) {
Map<String, String> reqParamMap = OA2Utilities.getParameters(request.getServletRequest());
UIIResponse2 uiiResponse2 = new UIIResponse2();
uiiResponse2.setParameters(reqParamMap);
uiiResponse2.setAccessToken(request.getAccessToken());
UserInfo userInfo = new UserInfo();
userInfo.setSub(request.getUsername());
uiiResponse2.setUserInfo(userInfo);
return uiiResponse2;
}
use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.
the class NativeRoleServiceTest method getAssignedUsersRecursive.
@Test
void getAssignedUsersRecursive() {
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/user").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);
assertArrayEquals(new String[] { "admin", "aragorn" }, users.stream().map(BaseUserInfo::getUserId).sorted().toArray(String[]::new));
} 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 getAssignedUsersRecursiveParentsOnly.
@Test
void getAssignedUsersRecursiveParentsOnly() {
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", "parentsOnly").get("archiva-global-repository-observer/user").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);
assertArrayEquals(new String[] { "admin" }, users.stream().map(BaseUserInfo::getUserId).sorted().toArray(String[]::new));
} 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 updateRoleWithAssignedUsers.
@Test
void updateRoleWithAssignedUsers() {
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");
String id = "";
try {
given().spec(getRequestSpec(token, getUserServicePath())).contentType(JSON).body(jsonAsMap).when().post().then().statusCode(201);
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().put("templates/archiva-repository-manager/repository14").then().statusCode(201).extract().response();
assertNotNull(response);
RoleInfo roleInfo = response.getBody().jsonPath().getObject("", RoleInfo.class);
id = roleInfo.getId();
jsonAsMap = new HashMap<>();
jsonAsMap.put("id", roleInfo.getId());
jsonAsMap.put("name", roleInfo.getName());
jsonAsMap.put("description", "New description");
jsonAsMap.put("assignable", "false");
jsonAsMap.put("permanent", "true");
HashMap<Object, Object> aragornMap = new HashMap<>();
aragornMap.put("id", "jpa:aragorn");
aragornMap.put("user_id", "aragorn");
jsonAsMap.put("assigned_users", Arrays.asList(aragornMap));
response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).patch(roleInfo.getId()).then().statusCode(200).extract().response();
assertNotNull(response);
RoleInfo updatedRole = response.getBody().jsonPath().getObject("", RoleInfo.class);
assertEquals(roleInfo.getId(), updatedRole.getId());
assertEquals(roleInfo.getName(), updatedRole.getName());
assertEquals("New description", updatedRole.getDescription());
assertEquals(false, updatedRole.isAssignable());
assertEquals(true, updatedRole.isPermanent());
response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("archiva-repository-manager.repository14/user").then().extract().response();
List<UserInfo> userList = response.getBody().jsonPath().getList("data", UserInfo.class);
assertEquals(1, userList.size());
assertTrue(userList.stream().filter(user -> "aragorn".equals(user.getUserId())).findAny().isPresent());
} finally {
// Switching back permanent flag
jsonAsMap = new HashMap<>();
jsonAsMap.put("id", id);
jsonAsMap.put("permanent", "false");
given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).patch(id).then().statusCode(200).extract().response();
given().spec(getRequestSpec(token, getUserServicePath())).contentType(JSON).when().delete("aragorn").then().statusCode(200);
given().spec(getRequestSpec(token)).contentType(JSON).when().delete("templates/archiva-repository-manager/repository14").then().statusCode(200);
given().spec(getRequestSpec(token)).contentType(JSON).when().delete("templates/archiva-repository-observer/repository14").then().statusCode(200);
}
}
Aggregations