use of org.keycloak.representations.idm.authorization.PermissionResponse in project keycloak by keycloak.
the class PermissionManagementTest method testCreatePermissionTicketWithResourceWithoutManagedAccess.
@Test
public void testCreatePermissionTicketWithResourceWithoutManagedAccess() throws Exception {
ResourceRepresentation resource = addResource("Resource A");
PermissionResponse response = getAuthzClient().protection().permission().create(new PermissionRequest(resource.getName()));
assertNotNull(response.getTicket());
assertTrue(getAuthzClient().protection().permission().findByResource(resource.getId()).isEmpty());
}
use of org.keycloak.representations.idm.authorization.PermissionResponse in project keycloak by keycloak.
the class PermissionManagementTest method testCreatePermissionTicketWithScopes.
@Test
public void testCreatePermissionTicketWithScopes() throws Exception {
ResourceRepresentation resource = addResource("Resource A", "kolo", true, "ScopeA", "ScopeB", "ScopeC");
AuthzClient authzClient = getAuthzClient();
PermissionResponse response = authzClient.protection("marta", "password").permission().create(new PermissionRequest(resource.getId(), "ScopeA", "ScopeB", "ScopeC"));
AuthorizationRequest request = new AuthorizationRequest();
request.setTicket(response.getTicket());
request.setClaimToken(authzClient.obtainAccessToken("marta", "password").getToken());
try {
authzClient.authorization().authorize(request);
} catch (Exception e) {
}
assertPersistence(response, resource, "ScopeA", "ScopeB", "ScopeC");
}
use of org.keycloak.representations.idm.authorization.PermissionResponse in project keycloak by keycloak.
the class PermissionManagementTest method testRemoveScopeFromResource.
@Test
public void testRemoveScopeFromResource() throws Exception {
ResourceRepresentation resource = addResource("Resource A", "kolo", true, "ScopeA", "ScopeB");
PermissionRequest permissionRequest = new PermissionRequest(resource.getId(), "ScopeA", "ScopeB");
AuthzClient authzClient = getAuthzClient();
PermissionResponse response = authzClient.protection("marta", "password").permission().create(permissionRequest);
assertNotNull(response.getTicket());
AuthorizationRequest request = new AuthorizationRequest();
request.setTicket(response.getTicket());
request.setClaimToken(authzClient.obtainAccessToken("marta", "password").getToken());
try {
authzClient.authorization().authorize(request);
} catch (Exception e) {
}
AuthorizationResource authorization = getClient(getRealm()).authorization();
ResourceScopesResource scopes = authorization.scopes();
ScopeRepresentation removedScope = scopes.findByName("ScopeA");
List permissions = authzClient.protection().permission().findByScope(removedScope.getId());
assertFalse(permissions.isEmpty());
resource.setScopes(new HashSet<>());
resource.addScope("ScopeB");
authorization.resources().resource(resource.getId()).update(resource);
permissions = authzClient.protection().permission().findByScope(removedScope.getId());
assertTrue(permissions.isEmpty());
ScopeRepresentation scopeB = scopes.findByName("ScopeB");
permissions = authzClient.protection().permission().findByScope(scopeB.getId());
assertFalse(permissions.isEmpty());
}
use of org.keycloak.representations.idm.authorization.PermissionResponse in project keycloak by keycloak.
the class PermissionManagementTest method removeUserWithPermissionTicketTest.
@Test
public void removeUserWithPermissionTicketTest() throws Exception {
String userToRemoveID = createUser(REALM_NAME, "user-to-remove", "password");
ResourceRepresentation resource = addResource("Resource A", "kolo", true);
AuthzClient authzClient = getAuthzClient();
PermissionResponse response = authzClient.protection("user-to-remove", "password").permission().create(new PermissionRequest(resource.getId()));
AuthorizationRequest request = new AuthorizationRequest();
request.setTicket(response.getTicket());
request.setClaimToken(authzClient.obtainAccessToken("user-to-remove", "password").getToken());
try {
authzClient.authorization().authorize(request);
} catch (Exception e) {
}
assertPersistence(response, resource);
// Remove the user and expect the user and also hers permission tickets are successfully removed
adminClient.realm(REALM_NAME).users().delete(userToRemoveID);
assertThat(adminClient.realm(REALM_NAME).users().list().stream().map(UserRepresentation::getId).collect(Collectors.toList()), not(hasItem(userToRemoveID)));
assertThat(getAuthzClient().protection().permission().findByResource(resource.getId()), is(empty()));
}
use of org.keycloak.representations.idm.authorization.PermissionResponse in project keycloak by keycloak.
the class PermissionManagementTest method testDeleteResourceAndPermissionTicket.
@Test
public void testDeleteResourceAndPermissionTicket() throws Exception {
ResourceRepresentation resource = addResource("Resource A", "kolo", true, "ScopeA", "ScopeB", "ScopeC");
AuthzClient authzClient = getAuthzClient();
PermissionResponse response = authzClient.protection("marta", "password").permission().create(new PermissionRequest(resource.getId(), "ScopeA", "ScopeB", "ScopeC"));
AuthorizationRequest request = new AuthorizationRequest();
request.setTicket(response.getTicket());
request.setClaimToken(authzClient.obtainAccessToken("marta", "password").getToken());
try {
authzClient.authorization().authorize(request);
} catch (Exception e) {
}
assertPersistence(response, resource, "ScopeA", "ScopeB", "ScopeC");
getAuthzClient().protection().resource().delete(resource.getId());
assertTrue(getAuthzClient().protection().permission().findByResource(resource.getId()).isEmpty());
}
Aggregations