Search in sources :

Example 1 with ResourceBean

use of org.keycloak.forms.account.freemarker.model.AuthorizationBean.ResourceBean in project keycloak by keycloak.

the class UmaRepresentationTest method testCanRepresentResourceBeanOfResourceOwnedByUser.

public static void testCanRepresentResourceBeanOfResourceOwnedByUser(KeycloakSession session) {
    session.getContext().setRealm(session.realms().getRealmByName("authz-test"));
    AuthorizationProvider authorization = session.getProvider(AuthorizationProvider.class);
    AuthorizationBean authorizationBean = new AuthorizationBean(session, null, session.getContext().getUri());
    ClientModel client = session.getContext().getRealm().getClientByClientId("resource-server-test");
    UserModel user = session.userStorageManager().getUserByUsername(session.getContext().getRealm(), "marta");
    ResourceBean resourceBean = authorizationBean.new ResourceBean(authorization.getStoreFactory().getResourceStore().findByName("Resource A", user.getId(), client.getId()));
    Assert.assertEquals("Resource A", resourceBean.getName());
    Assert.assertEquals("marta", resourceBean.getOwnerName());
    Assert.assertNotNull(resourceBean.getUserOwner());
    Assert.assertEquals("marta", resourceBean.getUserOwner().getUsername());
    Assert.assertNull(resourceBean.getClientOwner());
}
Also used : UserModel(org.keycloak.models.UserModel) ClientModel(org.keycloak.models.ClientModel) ResourceBean(org.keycloak.forms.account.freemarker.model.AuthorizationBean.ResourceBean) AuthorizationProvider(org.keycloak.authorization.AuthorizationProvider) AuthorizationBean(org.keycloak.forms.account.freemarker.model.AuthorizationBean)

Example 2 with ResourceBean

use of org.keycloak.forms.account.freemarker.model.AuthorizationBean.ResourceBean in project keycloak by keycloak.

the class UmaRepresentationTest method testCanRepresentResourceBeanOfResourceOwnedByClient.

public static void testCanRepresentResourceBeanOfResourceOwnedByClient(KeycloakSession session) {
    session.getContext().setRealm(session.realms().getRealmByName("authz-test"));
    AuthorizationProvider authorization = session.getProvider(AuthorizationProvider.class);
    AuthorizationBean authorizationBean = new AuthorizationBean(session, null, session.getContext().getUri());
    ClientModel client = session.getContext().getRealm().getClientByClientId("resource-server-test");
    ResourceBean resourceBean = authorizationBean.new ResourceBean(authorization.getStoreFactory().getResourceStore().findByName("Resource A", client.getId(), client.getId()));
    Assert.assertEquals("Resource A", resourceBean.getName());
    Assert.assertEquals("resource-server-test", resourceBean.getOwnerName());
    Assert.assertNotNull(resourceBean.getClientOwner());
    Assert.assertEquals("resource-server-test", resourceBean.getClientOwner().getClientId());
    Assert.assertNull(resourceBean.getUserOwner());
}
Also used : ClientModel(org.keycloak.models.ClientModel) ResourceBean(org.keycloak.forms.account.freemarker.model.AuthorizationBean.ResourceBean) AuthorizationProvider(org.keycloak.authorization.AuthorizationProvider) AuthorizationBean(org.keycloak.forms.account.freemarker.model.AuthorizationBean)

Aggregations

AuthorizationProvider (org.keycloak.authorization.AuthorizationProvider)2 AuthorizationBean (org.keycloak.forms.account.freemarker.model.AuthorizationBean)2 ResourceBean (org.keycloak.forms.account.freemarker.model.AuthorizationBean.ResourceBean)2 ClientModel (org.keycloak.models.ClientModel)2 UserModel (org.keycloak.models.UserModel)1