Search in sources :

Example 16 with UserInfo

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();
}
Also used : JSONObject(net.sf.json.JSONObject) OA2ServiceTransaction(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2ServiceTransaction) JsonObject(javax.json.JsonObject) UserInfo(edu.uiuc.ncsa.security.oauth_2_0.UserInfo)

Example 17 with UserInfo

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;
}
Also used : UserInfo(edu.uiuc.ncsa.security.oauth_2_0.UserInfo)

Example 18 with UserInfo

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);
    }
}
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 19 with UserInfo

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);
    }
}
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 20 with UserInfo

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

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