Search in sources :

Example 1 with PermissionTicket

use of io.gravitee.am.model.uma.PermissionTicket in project gravitee-access-management by gravitee-io.

the class PermissionEndpointTest method success_simpleRequest.

@Test
public void success_simpleRequest() {
    PermissionTicket success = new PermissionTicket().setId("success");
    final String simpleRequest = "{\"resource_id\":\"{{set_one}}\", \"resource_scopes\":[\"profile:read\"]}";
    when(context.getBody()).thenReturn(Buffer.buffer(simpleRequest));
    when(context.response()).thenReturn(response);
    when(response.putHeader(anyString(), anyString())).thenReturn(response);
    when(response.setStatusCode(anyInt())).thenReturn(response);
    when(permissionTicketService.create(anyList(), eq(DOMAIN_ID), eq(CLIENT_ID))).thenReturn(Single.just(success));
    endpoint.handle(context);
    verify(response, times(1)).putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    verify(context.response(), times(1)).setStatusCode(intCaptor.capture());
    verify(context.response(), times(1)).end(strCaptor.capture());
    Assert.assertEquals("Expecting 201 creation status", intCaptor.getValue().intValue(), 201);
    Assert.assertTrue("Expect success id", strCaptor.getValue().contains("success"));
}
Also used : PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) Test(org.junit.Test)

Example 2 with PermissionTicket

use of io.gravitee.am.model.uma.PermissionTicket in project gravitee-access-management by gravitee-io.

the class PermissionEndpointTest method success_extendedRequest.

@Test
public void success_extendedRequest() {
    PermissionTicket success = new PermissionTicket().setId("success");
    final String extendedRequest = "[{\"resource_id\":\"{{set_one}}\", \"resource_scopes\":[\"profile:read\"]}, {\"resource_id\":\"{{set_two}}\",\"resource_scopes\":[\"avatar:write\"]}]";
    when(context.getBody()).thenReturn(Buffer.buffer(extendedRequest));
    when(context.response()).thenReturn(response);
    when(response.putHeader(anyString(), anyString())).thenReturn(response);
    when(response.setStatusCode(anyInt())).thenReturn(response);
    when(permissionTicketService.create(anyList(), eq(DOMAIN_ID), eq(CLIENT_ID))).thenReturn(Single.just(success));
    endpoint.handle(context);
    verify(response, times(1)).putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    verify(context.response(), times(1)).setStatusCode(intCaptor.capture());
    verify(context.response(), times(1)).end(strCaptor.capture());
    Assert.assertEquals("Expecting 201 creation status", intCaptor.getValue().intValue(), 201);
    Assert.assertTrue("Expect success id", strCaptor.getValue().contains("success"));
}
Also used : PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) Test(org.junit.Test)

Example 3 with PermissionTicket

use of io.gravitee.am.model.uma.PermissionTicket in project gravitee-access-management by gravitee-io.

the class JdbcPermissionTicketRepository method findById.

@Override
public Maybe<PermissionTicket> findById(String id) {
    LOGGER.debug("findById({})", id);
    LocalDateTime now = LocalDateTime.now(UTC);
    return permissionTicketRepository.findById(id).filter(bean -> bean.getExpireAt() == null || bean.getExpireAt().isAfter(now)).map(this::toEntity);
}
Also used : LocalDateTime(java.time.LocalDateTime) PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) PermissionTicketRepository(io.gravitee.am.repository.management.api.PermissionTicketRepository) RxJava2Adapter.monoToCompletable(reactor.adapter.rxjava.RxJava2Adapter.monoToCompletable) Completable(io.reactivex.Completable) Maybe(io.reactivex.Maybe) Query(org.springframework.data.relational.core.query.Query) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Criteria.where(org.springframework.data.relational.core.query.Criteria.where) Mono(reactor.core.publisher.Mono) JdbcPermissionTicket(io.gravitee.am.repository.jdbc.management.api.model.JdbcPermissionTicket) Single(io.reactivex.Single) RandomString(io.gravitee.am.common.utils.RandomString) InitializingBean(org.springframework.beans.factory.InitializingBean) DatabaseClient(org.springframework.r2dbc.core.DatabaseClient) AbstractJdbcRepository(io.gravitee.am.repository.jdbc.management.AbstractJdbcRepository) List(java.util.List) UTC(java.time.ZoneOffset.UTC) RxJava2Adapter.monoToSingle(reactor.adapter.rxjava.RxJava2Adapter.monoToSingle) SpringPermissionTicketRepository(io.gravitee.am.repository.jdbc.management.api.spring.SpringPermissionTicketRepository) Repository(org.springframework.stereotype.Repository)

Example 4 with PermissionTicket

use of io.gravitee.am.model.uma.PermissionTicket in project gravitee-access-management by gravitee-io.

the class PermissionTicketRepositoryTest method delete.

@Test
public void delete() throws TechnicalException {
    // create permission_ticket
    PermissionTicket permissionTicket = new PermissionTicket().setPermissionRequest(Arrays.asList(permission));
    PermissionTicket ptCreated = repository.create(permissionTicket).blockingGet();
    // fetch permission_ticket
    TestObserver<Void> testObserver = repository.delete(ptCreated.getId()).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertNoValues();
}
Also used : PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 5 with PermissionTicket

use of io.gravitee.am.model.uma.PermissionTicket in project gravitee-access-management by gravitee-io.

the class UmaTokenGranterTest method setUp.

@Before
public void setUp() {
    // Init parameters
    parameters.add(TICKET, TICKET_ID);
    parameters.add(CLAIM_TOKEN, RQP_ID_TOKEN);
    parameters.add(CLAIM_TOKEN_FORMAT, TokenType.ID_TOKEN);
    tokenRequest = new TokenRequest();
    tokenRequest.setParameters(parameters);
    List<PermissionRequest> permissions = Arrays.asList(new PermissionRequest().setResourceId(RS_ONE).setResourceScopes(new ArrayList<>(Arrays.asList("scopeA"))), new PermissionRequest().setResourceId(RS_TWO).setResourceScopes(new ArrayList<>(Arrays.asList("scopeA"))));
    Map permission = new HashMap();
    permission.put("resourceId", RS_ONE);
    permission.put("resourceScopes", Arrays.asList("scopeB"));
    // Init mocks
    when(domain.getUma()).thenReturn(new UMASettings().setEnabled(true));
    when(client.getClientId()).thenReturn(CLIENT_ID);
    when(client.getScopeSettings()).thenReturn(Arrays.asList(new ApplicationScopeSettings("scopeA"), new ApplicationScopeSettings("scopeB"), new ApplicationScopeSettings("scopeC"), new ApplicationScopeSettings("scopeD")));
    when(client.getAuthorizedGrantTypes()).thenReturn(Arrays.asList(GrantType.UMA, GrantType.REFRESH_TOKEN));
    when(user.getId()).thenReturn(USER_ID);
    when(jwt.getSub()).thenReturn(USER_ID);
    when(rpt.getSub()).thenReturn(USER_ID);
    when(rpt.getAud()).thenReturn(CLIENT_ID);
    when(rpt.get("permissions")).thenReturn(new LinkedList(Arrays.asList(permission)));
    when(jwtService.decodeAndVerify(RQP_ID_TOKEN, client)).thenReturn(Single.just(jwt));
    when(jwtService.decodeAndVerify(RPT_OLD_TOKEN, client)).thenReturn(Single.just(rpt));
    when(userAuthenticationManager.loadPreAuthenticatedUser(USER_ID, tokenRequest)).thenReturn(Maybe.just(user));
    when(permissionTicketService.remove(TICKET_ID)).thenReturn(Single.just(new PermissionTicket().setId(TICKET_ID).setPermissionRequest(permissions)));
    when(resourceService.findByResources(Arrays.asList(RS_ONE, RS_TWO))).thenReturn(Flowable.just(new Resource().setId(RS_ONE).setResourceScopes(Arrays.asList("scopeA", "scopeB", "scopeC")), new Resource().setId(RS_TWO).setResourceScopes(Arrays.asList("scopeA", "scopeB", "scopeD"))));
    when(tokenService.create(oauth2RequestCaptor.capture(), eq(client), any())).thenReturn(Single.just(new AccessToken("success")));
    when(resourceService.findAccessPoliciesByResources(anyList())).thenReturn(Flowable.empty());
}
Also used : PermissionRequest(io.gravitee.am.model.uma.PermissionRequest) PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) AccessToken(io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken) TokenRequest(io.gravitee.am.gateway.handler.oauth2.service.request.TokenRequest) ApplicationScopeSettings(io.gravitee.am.model.application.ApplicationScopeSettings) Resource(io.gravitee.am.model.uma.Resource) MultiValueMap(io.gravitee.common.util.MultiValueMap) LinkedMultiValueMap(io.gravitee.common.util.LinkedMultiValueMap) UMASettings(io.gravitee.am.model.uma.UMASettings) Before(org.junit.Before)

Aggregations

PermissionTicket (io.gravitee.am.model.uma.PermissionTicket)18 Test (org.junit.Test)15 PermissionRequest (io.gravitee.am.model.uma.PermissionRequest)11 Resource (io.gravitee.am.model.uma.Resource)9 InvalidPermissionRequestException (io.gravitee.am.service.exception.InvalidPermissionRequestException)6 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)4 PermissionTicketRepository (io.gravitee.am.repository.management.api.PermissionTicketRepository)2 Maybe (io.reactivex.Maybe)2 Single (io.reactivex.Single)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 RandomString (io.gravitee.am.common.utils.RandomString)1 TokenRequest (io.gravitee.am.gateway.handler.oauth2.service.request.TokenRequest)1 AccessToken (io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken)1 ApplicationScopeSettings (io.gravitee.am.model.application.ApplicationScopeSettings)1 UMASettings (io.gravitee.am.model.uma.UMASettings)1 AbstractJdbcRepository (io.gravitee.am.repository.jdbc.management.AbstractJdbcRepository)1 JdbcPermissionTicket (io.gravitee.am.repository.jdbc.management.api.model.JdbcPermissionTicket)1