Search in sources :

Example 1 with Approval

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

the class ApprovalServiceTest method ensureRequiredApprovals_throwsWhenApprovalsExpired.

@Test
public void ensureRequiredApprovals_throwsWhenApprovalsExpired() {
    expectedException.expect(InvalidTokenException.class);
    expectedException.expectMessage("approvals expired");
    long approvalExpiry = 10L;
    Approval approval = new Approval();
    approval.setScope("foo.read");
    approval.setStatus(Approval.ApprovalStatus.APPROVED);
    approval.setExpiresAt(new Date(approvalExpiry));
    when(timeService.getCurrentTimeMillis()).thenReturn(approvalExpiry + 1L);
    when(timeService.getCurrentDate()).thenCallRealMethod();
    List<Approval> approvals = Lists.newArrayList(approval);
    when(approvalStore.getApprovals(eq(USER_ID), eq(CLIENT_ID), anyString())).thenReturn(approvals);
    approvalService.ensureRequiredApprovals(USER_ID, Lists.newArrayList("foo.read"), GRANT_TYPE_AUTHORIZATION_CODE, clientDetails);
}
Also used : Approval(org.cloudfoundry.identity.uaa.approval.Approval) Date(java.util.Date) Test(org.junit.Test)

Example 2 with Approval

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

the class ApprovalServiceTest method ensureRequiredApprovals_throwsIfAnyRequestedScopesAreNotApproved.

@Test
public void ensureRequiredApprovals_throwsIfAnyRequestedScopesAreNotApproved() {
    expectedException.expect(InvalidTokenException.class);
    expectedException.expectMessage("requested scopes are not approved");
    long approvalExpiry = 10L;
    Approval approval1 = new Approval();
    approval1.setScope("foo.read");
    approval1.setStatus(Approval.ApprovalStatus.APPROVED);
    approval1.setExpiresAt(new Date(approvalExpiry));
    Approval approval2 = new Approval();
    approval2.setScope("bar.read");
    approval2.setStatus(Approval.ApprovalStatus.DENIED);
    approval2.setExpiresAt(new Date(approvalExpiry));
    Approval approval3 = new Approval();
    approval3.setScope("baz.read");
    approval3.setStatus(Approval.ApprovalStatus.APPROVED);
    approval3.setExpiresAt(new Date(approvalExpiry));
    when(timeService.getCurrentTimeMillis()).thenReturn(approvalExpiry - 1L);
    when(timeService.getCurrentDate()).thenCallRealMethod();
    List<Approval> approvals = Lists.newArrayList(approval1, approval2, approval3);
    when(approvalStore.getApprovals(eq(USER_ID), eq(CLIENT_ID), anyString())).thenReturn(approvals);
    approvalService.ensureRequiredApprovals(USER_ID, Lists.newArrayList("foo.read", "bar.read"), GRANT_TYPE_AUTHORIZATION_CODE, clientDetails);
}
Also used : Approval(org.cloudfoundry.identity.uaa.approval.Approval) Date(java.util.Date) Test(org.junit.Test)

Example 3 with Approval

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

the class ScimUserEndpointDocs method setUp.

@BeforeEach
void setUp() throws Exception {
    userProvisioning = webApplicationContext.getBean(ScimUserProvisioning.class);
    scimReadToken = MockMvcUtils.getClientCredentialsOAuthAccessToken(mockMvc, "admin", "adminsecret", "scim.read", null, true);
    scimWriteToken = MockMvcUtils.getClientCredentialsOAuthAccessToken(mockMvc, "admin", "adminsecret", "scim.write", null, true);
    user = createScimUserObject();
    user = MockMvcUtils.createUser(mockMvc, scimWriteToken, user);
    ApprovalStore approvalStore = webApplicationContext.getBean(ApprovalStore.class);
    approvalStore.addApproval(new Approval().setClientId("client id").setUserId(user.getId()).setExpiresAt(new Date(System.currentTimeMillis() + 10000)).setScope("scim.read").setStatus(Approval.ApprovalStatus.APPROVED), IdentityZoneHolder.get().getId());
}
Also used : ApprovalStore(org.cloudfoundry.identity.uaa.approval.ApprovalStore) Approval(org.cloudfoundry.identity.uaa.approval.Approval) ScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Approval

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

the class ScimUserEndpointDocs method test_Update_User.

@Test
void test_Update_User() throws Exception {
    ApprovalStore store = webApplicationContext.getBean(ApprovalStore.class);
    Approval approval = new Approval().setUserId(user.getId()).setStatus(Approval.ApprovalStatus.DENIED).setScope("uaa.user").setClientId("identity").setExpiresAt(new Date(System.currentTimeMillis() + 30000)).setLastUpdatedAt(new Date(System.currentTimeMillis() + 30000));
    store.addApproval(approval, IdentityZoneHolder.get().getId());
    user.setGroups(Collections.emptyList());
    mockMvc.perform(RestDocumentationRequestBuilders.put("/Users/{userId}", user.getId()).accept(APPLICATION_JSON).header("Authorization", "Bearer " + scimWriteToken).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).header("If-Match", user.getVersion()).content(JsonUtils.writeValueAsString(user))).andExpect(status().isOk()).andDo(document("{ClassName}/{methodName}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), pathParameters(parameterWithName("userId").description(userIdDescription)), requestHeaders(headerWithName("Authorization").description(requiredUserUpdateScopes), headerWithName("If-Match").description("The version of the SCIM object to be updated. Wildcard (*) accepted."), IDENTITY_ZONE_ID_HEADER, IDENTITY_ZONE_SUBDOMAIN_HEADER), updateFields, responseFields(updateResponse)));
}
Also used : ApprovalStore(org.cloudfoundry.identity.uaa.approval.ApprovalStore) Approval(org.cloudfoundry.identity.uaa.approval.Approval) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with Approval

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

the class ScimUserEndpointDocs method test_Delete_User.

@Test
void test_Delete_User() throws Exception {
    ApprovalStore store = webApplicationContext.getBean(ApprovalStore.class);
    Approval approval = new Approval().setUserId(user.getId()).setStatus(Approval.ApprovalStatus.APPROVED).setScope("uaa.user").setClientId("identity").setExpiresAt(new Date(System.currentTimeMillis() + 30000)).setLastUpdatedAt(new Date(System.currentTimeMillis() + 30000));
    store.addApproval(approval, IdentityZoneHolder.get().getId());
    mockMvc.perform(RestDocumentationRequestBuilders.delete("/Users/{userId}", user.getId()).accept(APPLICATION_JSON).header("Authorization", "Bearer " + scimWriteToken).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).header("If-Match", user.getVersion())).andExpect(status().isOk()).andDo(document("{ClassName}/{methodName}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), pathParameters(parameterWithName("userId").description(userIdDescription)), requestHeaders(headerWithName("Authorization").description("Access token with `scim.write` or `uaa.admin` required"), headerWithName("If-Match").optional().description("The version of the SCIM object to be deleted. Optional."), IDENTITY_ZONE_ID_HEADER, IDENTITY_ZONE_SUBDOMAIN_HEADER), responseFields(updateResponse)));
}
Also used : ApprovalStore(org.cloudfoundry.identity.uaa.approval.ApprovalStore) Approval(org.cloudfoundry.identity.uaa.approval.Approval) Date(java.util.Date) 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