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"));
}
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"));
}
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);
}
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();
}
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());
}
Aggregations