use of org.keycloak.representations.idm.authorization.ResourceRepresentation in project keycloak by keycloak.
the class PolicyEnforcerTest method testUsingSubjectToken.
@Test
public void testUsingSubjectToken() {
ClientResource clientResource = getClientResource(RESOURCE_SERVER_CLIENT_ID);
ResourceRepresentation resource = createResource(clientResource, "Resource Subject Token", "/api/check-subject-token");
ResourcePermissionRepresentation permission = new ResourcePermissionRepresentation();
permission.setName(resource.getName() + " Permission");
permission.addResource(resource.getName());
permission.addPolicy("Only User Policy");
PermissionsResource permissions = clientResource.authorization().permissions();
permissions.resource().create(permission).close();
KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(getAdapterConfiguration("enforcer-bearer-only.json"));
PolicyEnforcer policyEnforcer = deployment.getPolicyEnforcer();
OIDCHttpFacade httpFacade = createHttpFacade("/api/check-subject-token");
AuthorizationContext context = policyEnforcer.enforce(httpFacade);
assertFalse(context.isGranted());
assertEquals(403, TestResponse.class.cast(httpFacade.getResponse()).getStatus());
oauth.realm(REALM_NAME);
oauth.clientId("public-client-test");
oauth.doLogin("marta", "password");
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
OAuthClient.AccessTokenResponse response = oauth.doAccessTokenRequest(code, null);
String token = response.getAccessToken();
httpFacade = createHttpFacade("/api/check-subject-token", token);
context = policyEnforcer.enforce(httpFacade);
assertTrue(context.isGranted());
}
use of org.keycloak.representations.idm.authorization.ResourceRepresentation in project keycloak by keycloak.
the class ResourceManagementTest method testCreate.
@Test
public void testCreate() {
ResourceRepresentation newResource = createResource();
assertEquals("Test Resource", newResource.getName());
assertEquals("/test/*", newResource.getUri());
assertEquals("test-resource", newResource.getType());
assertEquals("icon-test-resource", newResource.getIconUri());
Map<String, List<String>> attributes = newResource.getAttributes();
assertEquals(2, attributes.size());
assertTrue(attributes.containsKey("a"));
assertTrue(attributes.containsKey("b"));
assertTrue(attributes.get("a").containsAll(Arrays.asList("a1", "a2", "a3")));
assertEquals(3, attributes.get("a").size());
assertTrue(attributes.get("b").containsAll(Arrays.asList("b1")));
assertEquals(1, attributes.get("b").size());
}
use of org.keycloak.representations.idm.authorization.ResourceRepresentation in project keycloak by keycloak.
the class ResourceManagementTest method testAssociateScopes.
@Test
public void testAssociateScopes() {
ResourceRepresentation updated = createResourceWithDefaultScopes();
assertEquals(3, updated.getScopes().size());
assertTrue(containsScope("Scope A", updated));
assertTrue(containsScope("Scope B", updated));
assertTrue(containsScope("Scope C", updated));
}
use of org.keycloak.representations.idm.authorization.ResourceRepresentation in project keycloak by keycloak.
the class ResourceManagementTest method testDelete.
@Test(expected = NotFoundException.class)
public void testDelete() {
ResourceRepresentation resource = createResource();
doRemoveResource(resource);
getClientResource().authorization().resources().resource(resource.getId()).toRepresentation();
}
use of org.keycloak.representations.idm.authorization.ResourceRepresentation in project keycloak by keycloak.
the class ResourceManagementTest method testUpdate.
@Test
public void testUpdate() {
ResourceRepresentation resource = createResource();
resource.setType("changed");
resource.setIconUri("changed");
resource.setUri("changed");
Map<String, List<String>> attributes = resource.getAttributes();
attributes.remove("a");
attributes.put("c", Arrays.asList("c1", "c2"));
attributes.put("b", Arrays.asList("changed"));
resource = doUpdateResource(resource);
assertEquals("changed", resource.getIconUri());
assertEquals("changed", resource.getType());
assertEquals("changed", resource.getUri());
attributes = resource.getAttributes();
assertEquals(2, attributes.size());
assertFalse(attributes.containsKey("a"));
assertTrue(attributes.containsKey("b"));
assertTrue(attributes.get("b").containsAll(Arrays.asList("changed")));
assertEquals(1, attributes.get("b").size());
assertTrue(attributes.get("c").containsAll(Arrays.asList("c1", "c2")));
assertEquals(2, attributes.get("c").size());
}
Aggregations