Search in sources :

Example 61 with Approval

use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.

the class ClientAdminEndpointsMockMvcTests method testApprovalsAreDeleted2.

@Test
void testApprovalsAreDeleted2() throws Exception {
    ClientDetails details = createClient(adminToken, new RandomValueStringGenerator().generate(), SECRET, Collections.singleton("password"));
    String userToken = testClient.getUserOAuthAccessToken(details.getClientId(), "secret", testUser.getUserName(), testPassword, "oauth.approvals");
    Approval[] approvals = getApprovals(details.getClientId());
    assertEquals(0, approvals.length);
    addApprovals(userToken, details.getClientId());
    approvals = getApprovals(details.getClientId());
    assertEquals(3, approvals.length);
    MockHttpServletRequestBuilder deleteClientsPost = delete("/oauth/clients/" + details.getClientId()).header("Authorization", "Bearer " + adminToken).accept(APPLICATION_JSON);
    ResultActions result = mockMvc.perform(deleteClientsPost);
    result.andExpect(status().isOk());
    ClientDetails approvalsClient = createApprovalsLoginClient(adminToken);
    String loginToken = testClient.getUserOAuthAccessToken(approvalsClient.getClientId(), "secret", testUser.getUserName(), testPassword, "oauth.approvals");
    approvals = getApprovals(details.getClientId());
    assertEquals(0, approvals.length);
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ClientDetailsHelper.clientArrayFromString(org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientArrayFromString) ClientDetailsHelper.arrayFromString(org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.arrayFromString) ClientDetailsHelper.clientFromString(org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientFromString) ResultActions(org.springframework.test.web.servlet.ResultActions) Approval(org.cloudfoundry.identity.uaa.approval.Approval) Test(org.junit.jupiter.api.Test)

Example 62 with Approval

use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.

the class ScimUserJsonDeserializer method deserialize.

@Override
public ScimUser deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    ScimUser user = new ScimUser();
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
            String fieldName = jp.getCurrentName();
            jp.nextToken();
            if ("id".equalsIgnoreCase(fieldName)) {
                user.setId(jp.readValueAs(String.class));
            } else if ("userName".equalsIgnoreCase(fieldName)) {
                user.setUserName(jp.readValueAs(String.class));
            } else if ("externalId".equalsIgnoreCase(fieldName)) {
                user.setExternalId(jp.readValueAs(String.class));
            } else if ("meta".equalsIgnoreCase(fieldName)) {
                user.setMeta(jp.readValueAs(ScimMeta.class));
            } else if ("schemas".equalsIgnoreCase(fieldName)) {
                user.setSchemas(jp.readValueAs(String[].class));
            } else if ("userType".equalsIgnoreCase(fieldName)) {
                user.setUserType(jp.readValueAs(String.class));
            } else if ("title".equalsIgnoreCase(fieldName)) {
                user.setTitle(jp.readValueAs(String.class));
            } else if ("timezone".equalsIgnoreCase(fieldName)) {
                user.setTimezone(jp.readValueAs(String.class));
            } else if ("profileUrl".equalsIgnoreCase(fieldName)) {
                user.setProfileUrl(jp.readValueAs(String.class));
            } else if ("preferredLanguage".equalsIgnoreCase(fieldName)) {
                user.setPreferredLanguage(jp.readValueAs(String.class));
            } else if ("phoneNumbers".equalsIgnoreCase(fieldName)) {
                ScimUser.PhoneNumber[] phoneNumbers = jp.readValueAs(ScimUser.PhoneNumber[].class);
                if (phoneNumbers != null) {
                    user.setPhoneNumbers(Arrays.asList(phoneNumbers));
                } else {
                    user.setPhoneNumbers(new ArrayList<>());
                }
            } else if ("password".equalsIgnoreCase(fieldName)) {
                user.setPassword(jp.readValueAs(String.class));
            } else if ("nickname".equalsIgnoreCase(fieldName)) {
                user.setNickName(jp.readValueAs(String.class));
            } else if ("name".equalsIgnoreCase(fieldName)) {
                user.setName(jp.readValueAs(ScimUser.Name.class));
            } else if ("locale".equalsIgnoreCase(fieldName)) {
                user.setLocale(jp.readValueAs(String.class));
            } else if ("emails".equalsIgnoreCase(fieldName)) {
                user.setEmails(Arrays.asList(jp.readValueAs(ScimUser.Email[].class)));
            } else if ("groups".equalsIgnoreCase(fieldName)) {
                user.setGroups(Arrays.asList(jp.readValueAs(ScimUser.Group[].class)));
            } else if ("displayName".equalsIgnoreCase(fieldName)) {
                user.setDisplayName(jp.readValueAs(String.class));
            } else if ("active".equalsIgnoreCase(fieldName)) {
                user.setActive(jp.readValueAs(Boolean.class));
            } else if ("verified".equalsIgnoreCase(fieldName)) {
                user.setVerified(jp.readValueAs(Boolean.class));
            } else if (OriginKeys.ORIGIN.equalsIgnoreCase(fieldName)) {
                user.setOrigin(jp.readValueAs(String.class));
            } else if ("externalId".equalsIgnoreCase(fieldName)) {
                user.setExternalId(jp.readValueAs(String.class));
            } else if ("zoneId".equalsIgnoreCase(fieldName)) {
                user.setZoneId(jp.readValueAs(String.class));
            } else if ("salt".equalsIgnoreCase(fieldName)) {
                user.setSalt(jp.readValueAs(String.class));
            } else if ("passwordLastModified".equalsIgnoreCase(fieldName)) {
                if (jp.getValueAsString() != null) {
                    user.setPasswordLastModified(JsonDateDeserializer.getDate(jp.getValueAsString(), jp.getCurrentLocation()));
                }
            } else if ("approvals".equalsIgnoreCase(fieldName)) {
                user.setApprovals(new HashSet<>(Arrays.asList(jp.readValueAs(Approval[].class))));
            } else if ("lastLogonTime".equalsIgnoreCase(fieldName)) {
                if (jp.getValueAsString() != null) {
                    user.setLastLogonTime(jp.getValueAsLong());
                }
            } else if ("previousLogonTime".equalsIgnoreCase(fieldName)) {
                if (jp.getValueAsString() != null) {
                    user.setPreviousLogonTime(jp.getValueAsLong());
                }
            } else {
                throw new UnrecognizedPropertyException("unrecognized field", jp.getCurrentLocation(), ScimUser.class, fieldName, Collections.emptySet());
            }
        }
    }
    return user;
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) UnrecognizedPropertyException(com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException) Approval(org.cloudfoundry.identity.uaa.approval.Approval) HashSet(java.util.HashSet)

Example 63 with Approval

use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.

the class ApprovalsJsonDeserializer method deserialize.

@Override
public Approval deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    Approval approval = new Approval();
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
            String fieldName = jp.getCurrentName();
            jp.nextToken();
            if ("userId".equalsIgnoreCase(fieldName)) {
                approval.setUserId(jp.readValueAs(String.class));
            } else if ("clientId".equalsIgnoreCase(fieldName)) {
                approval.setClientId(jp.readValueAs(String.class));
            } else if ("scope".equalsIgnoreCase(fieldName)) {
                approval.setScope(jp.readValueAs(String.class));
            } else if ("status".equalsIgnoreCase(fieldName)) {
                approval.setStatus(jp.readValueAs(ApprovalStatus.class));
            } else if ("expiresAt".equalsIgnoreCase(fieldName)) {
                approval.setExpiresAt(jp.readValueAs(Date.class));
            } else if ("lastUpdatedAt".equalsIgnoreCase(fieldName)) {
                approval.setLastUpdatedAt(jp.readValueAs(Date.class));
            }
        }
    }
    return approval;
}
Also used : Approval(org.cloudfoundry.identity.uaa.approval.Approval) Date(java.util.Date)

Example 64 with Approval

use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.

the class ScimUserEndpointsTests method approvalsIsSyncedCorrectlyOnUpdate.

@Test
void approvalsIsSyncedCorrectlyOnUpdate() {
    ScimUser user = new ScimUser(null, "vidya", "Vidya", "V");
    user.addEmail("vidya@vmware.com");
    user.setPassword("password");
    user.setApprovals(Collections.singleton(new Approval().setUserId("vidya").setClientId("c1").setScope("s1").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.APPROVED)));
    ScimUser created = scimUserEndpoints.createUser(user, new MockHttpServletRequest(), new MockHttpServletResponse());
    final Approval approval1 = new Approval().setUserId(created.getId()).setClientId("c1").setScope("s1").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.APPROVED);
    final Approval approval2 = new Approval().setUserId(created.getId()).setClientId("c1").setScope("s2").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.DENIED);
    when(mockApprovalStore.getApprovalsForUser(anyString(), anyString())).thenReturn(Arrays.asList(approval1, approval2));
    created.setApprovals(Collections.singleton(new Approval().setUserId("vidya").setClientId("c1").setScope("s1").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.APPROVED)));
    ScimUser updated = scimUserEndpoints.updateUser(created, created.getId(), "*", new MockHttpServletRequest(), new MockHttpServletResponse(), null);
    assertEquals(2, updated.getApprovals().size());
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Approval(org.cloudfoundry.identity.uaa.approval.Approval) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 65 with Approval

use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.

the class ScimUserEndpointsTests method approvalsIsSyncedCorrectlyOnGet.

@Test
void approvalsIsSyncedCorrectlyOnGet() {
    assertEquals(0, scimUserEndpoints.getUser(joel.getId(), new MockHttpServletResponse()).getApprovals().size());
    final Approval approval1 = new Approval().setUserId(joel.getId()).setClientId("c1").setScope("s1").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.APPROVED);
    final Approval approval2 = new Approval().setUserId(joel.getId()).setClientId("c1").setScope("s2").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.DENIED);
    when(mockApprovalStore.getApprovalsForUser(anyString(), anyString())).thenReturn(Arrays.asList(approval1, approval2));
    assertEquals(2, scimUserEndpoints.getUser(joel.getId(), new MockHttpServletResponse()).getApprovals().size());
}
Also used : Approval(org.cloudfoundry.identity.uaa.approval.Approval) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

Approval (org.cloudfoundry.identity.uaa.approval.Approval)80 Test (org.junit.jupiter.api.Test)34 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)29 Date (java.util.Date)26 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)21 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)19 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)18 Authentication (org.springframework.security.core.Authentication)17 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)17 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)16 Test (org.junit.Test)16 ApprovalStore (org.cloudfoundry.identity.uaa.approval.ApprovalStore)7 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)6 ClientDetailsModification (org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification)5 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)5 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)5 ArrayList (java.util.ArrayList)4 ClientDetailsHelper.arrayFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.arrayFromString)4 ClientDetailsHelper.clientArrayFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientArrayFromString)4 ClientDetailsHelper.clientFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientFromString)4