Search in sources :

Example 6 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class AuthorizationRequestEndpointTest method createPendingRequest.

private UmaPendingRequest createPendingRequest(String... scopes) {
    UmaPendingRequest pendingRequest = mock(UmaPendingRequest.class);
    given(pendingRequest.getScopes()).willReturn(new HashSet<>(Arrays.asList(scopes)));
    return pendingRequest;
}
Also used : UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest)

Example 7 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class PendingRequestsServiceTest method shouldCreatePendingRequest.

@Test
public void shouldCreatePendingRequest() throws Exception {
    //Given
    HttpServletRequest httpRequest = mock(HttpServletRequest.class);
    //When
    service.createPendingRequest(httpRequest, RESOURCE_SET_ID, RESOURCE_SET_NAME, RESOURCE_OWNER_ID, REQUESTING_PARTY_ID, REALM, Collections.singleton(SCOPE));
    //Then
    ArgumentCaptor<UmaPendingRequest> pendingRequestCaptor = ArgumentCaptor.forClass(UmaPendingRequest.class);
    verify(store).create(pendingRequestCaptor.capture());
    UmaPendingRequest pendingRequest = pendingRequestCaptor.getValue();
    assertThat(pendingRequest.getResourceSetId()).isEqualTo(RESOURCE_SET_ID);
    assertThat(pendingRequest.getResourceSetName()).isEqualTo(RESOURCE_SET_NAME);
    assertThat(pendingRequest.getResourceOwnerId()).isEqualTo(RESOURCE_OWNER_ID);
    assertThat(pendingRequest.getRequestingPartyId()).isEqualTo(REQUESTING_PARTY_ID);
    assertThat(pendingRequest.getRealm()).isEqualTo(REALM);
    assertThat(pendingRequest.getScopes()).containsExactly(SCOPE);
    assertThat(pendingRequest.getRequestedAt()).isNotNull();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) Test(org.testng.annotations.Test)

Example 8 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class PendingRequestsServiceTest method createPendingRequest.

private void createPendingRequest(String id, String resourceSetId, String resourceSetName, String resourceOwnerId, String realm, String requestingPartyId, Set<String> scopes) throws NotFoundException, ServerException {
    UmaPendingRequest pendingRequest = new UmaPendingRequest(resourceSetId, resourceSetName, resourceOwnerId, realm, requestingPartyId, scopes);
    pendingRequest.setId(id);
    given(store.read(id)).willReturn(pendingRequest);
}
Also used : UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest)

Example 9 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class PendingRequestsServiceTest method shouldSendEmailOnPendingRequestCreation.

@Test
public void shouldSendEmailOnPendingRequestCreation() throws Exception {
    //Given
    HttpServletRequest httpRequest = mock(HttpServletRequest.class);
    given(settings.isEmailResourceOwnerOnPendingRequestCreationEnabled()).willReturn(true);
    mockPendingRequestCreationEmailTemplate(RESOURCE_OWNER_ID, REALM);
    //When
    service.createPendingRequest(httpRequest, RESOURCE_SET_ID, RESOURCE_SET_NAME, RESOURCE_OWNER_ID, REQUESTING_PARTY_ID, REALM, Collections.singleton(SCOPE));
    //Then
    verify(emailService).email(REALM, RESOURCE_OWNER_ID, "CREATION_SUBJECT", "CREATION_BODY " + REQUESTING_PARTY_ID + " " + RESOURCE_SET_NAME + " " + SCOPE);
    ArgumentCaptor<UmaPendingRequest> pendingRequestCaptor = ArgumentCaptor.forClass(UmaPendingRequest.class);
    verify(store).create(pendingRequestCaptor.capture());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) Test(org.testng.annotations.Test)

Example 10 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class PendingRequestResourceTest method mockPendingRequestsForUser.

private void mockPendingRequestsForUser(String username, String realm, int numberOfPendingRequests) throws ResourceException {
    given(contextHelper.getUserId(any(Context.class))).willReturn(username);
    Set<UmaPendingRequest> pendingRequests = new HashSet<>();
    for (int i = 0; i < numberOfPendingRequests; i++) {
        UmaPendingRequest pendingRequest = new UmaPendingRequest();
        pendingRequest.setId("ID" + i);
        pendingRequests.add(pendingRequest);
    }
    given(service.queryPendingRequests(username, realm)).willReturn(pendingRequests);
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) HashSet(java.util.HashSet)

Aggregations

UmaPendingRequest (org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest)11 ArrayList (java.util.ArrayList)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)2 NotSupportedException (org.forgerock.json.resource.NotSupportedException)2 ResourceException (org.forgerock.json.resource.ResourceException)2 NotFoundException (org.forgerock.openam.sm.datalayer.store.NotFoundException)2 ServerException (org.forgerock.openam.sm.datalayer.store.ServerException)2 Test (org.testng.annotations.Test)2 AMIdentity (com.sun.identity.idm.AMIdentity)1 HashSet (java.util.HashSet)1 MessagingException (javax.mail.MessagingException)1 JsonValue (org.forgerock.json.JsonValue)1 ResourceResponse (org.forgerock.json.resource.ResourceResponse)1 RealmContext (org.forgerock.openam.rest.RealmContext)1 Context (org.forgerock.services.context.Context)1 Promise (org.forgerock.util.promise.Promise)1