use of org.keycloak.authorization.client.resource.ProtectionResource in project keycloak by keycloak.
the class AuthzClientCredentialsTest method testNoRefreshToken.
@Test
public void testNoRefreshToken() throws Exception {
ClientsResource clients = getAdminClient().realm("authz-test-no-rt").clients();
AuthzClient authzClient = getAuthzClient("default-session-keycloak-no-rt.json");
org.keycloak.authorization.client.resource.AuthorizationResource authorization = authzClient.authorization();
AuthorizationResponse response = authorization.authorize();
AccessToken accessToken = toAccessToken(response.getToken());
assertEquals(1, accessToken.getAuthorization().getPermissions().size());
assertEquals("Default Resource", accessToken.getAuthorization().getPermissions().iterator().next().getResourceName());
ProtectionResource protection = authzClient.protection();
assertEquals(1, protection.resource().findAll().length);
try {
// force token expiration on the client side
Time.setOffset(1000);
// should refresh tokens by doing client credentials again
assertEquals(1, protection.resource().findAll().length);
} finally {
Time.setOffset(0);
}
}
use of org.keycloak.authorization.client.resource.ProtectionResource in project keycloak by keycloak.
the class AuthzClientCredentialsTest method testSuccessfulClientSecret.
@Test
public void testSuccessfulClientSecret() {
ProtectionResource protection = getAuthzClient("default-keycloak.json").protection();
assertAccessProtectionAPI(protection);
}
use of org.keycloak.authorization.client.resource.ProtectionResource in project keycloak by keycloak.
the class AuthzClientCredentialsTest method testSuccessfulAuthorizationRequest.
@Test
public void testSuccessfulAuthorizationRequest() throws Exception {
AuthzClient authzClient = getAuthzClient("keycloak-with-jwt-authentication.json");
ProtectionResource protection = authzClient.protection();
PermissionRequest request = new PermissionRequest("Default Resource");
PermissionResponse ticketResponse = protection.permission().create(request);
String ticket = ticketResponse.getTicket();
AuthorizationResponse authorizationResponse = authzClient.authorization("marta", "password").authorize(new AuthorizationRequest(ticket));
String rpt = authorizationResponse.getToken();
assertNotNull(rpt);
AccessToken accessToken = new JWSInput(rpt).readJsonContent(AccessToken.class);
AccessToken.Authorization authorization = accessToken.getAuthorization();
assertNotNull(authorization);
List<Permission> permissions = new ArrayList<>(authorization.getPermissions());
assertFalse(permissions.isEmpty());
assertEquals("Default Resource", permissions.get(0).getResourceName());
}
Aggregations