Search in sources :

Example 1 with ManagementPermissionReference

use of org.keycloak.representations.idm.ManagementPermissionReference in project keycloak by keycloak.

the class RoleByIdResource method toMgmtRef.

public static ManagementPermissionReference toMgmtRef(RoleModel role, AdminPermissionManagement permissions) {
    ManagementPermissionReference ref = new ManagementPermissionReference();
    ref.setEnabled(true);
    ref.setResource(permissions.roles().resource(role).getId());
    ref.setScopePermissions(permissions.roles().getPermissions(role));
    return ref;
}
Also used : ManagementPermissionReference(org.keycloak.representations.idm.ManagementPermissionReference)

Example 2 with ManagementPermissionReference

use of org.keycloak.representations.idm.ManagementPermissionReference in project keycloak by keycloak.

the class RoleByIdResource method getManagementPermissions.

/**
 * Return object stating whether role Authoirzation permissions have been initialized or not and a reference
 *
 * @param id
 * @return
 */
@Path("{role-id}/management/permissions")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public ManagementPermissionReference getManagementPermissions(@PathParam("role-id") final String id) {
    RoleModel role = getRoleModel(id);
    auth.roles().requireView(role);
    AdminPermissionManagement permissions = AdminPermissions.management(session, realm);
    if (!permissions.roles().isPermissionsEnabled(role)) {
        return new ManagementPermissionReference();
    }
    return toMgmtRef(role, permissions);
}
Also used : ManagementPermissionReference(org.keycloak.representations.idm.ManagementPermissionReference) RoleModel(org.keycloak.models.RoleModel) AdminPermissionManagement(org.keycloak.services.resources.admin.permissions.AdminPermissionManagement) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 3 with ManagementPermissionReference

use of org.keycloak.representations.idm.ManagementPermissionReference in project keycloak by keycloak.

the class ClientResource method toMgmtRef.

public static ManagementPermissionReference toMgmtRef(ClientModel client, AdminPermissionManagement permissions) {
    ManagementPermissionReference ref = new ManagementPermissionReference();
    ref.setEnabled(true);
    ref.setResource(permissions.clients().resource(client).getId());
    ref.setScopePermissions(permissions.clients().getPermissions(client));
    return ref;
}
Also used : ManagementPermissionReference(org.keycloak.representations.idm.ManagementPermissionReference)

Example 4 with ManagementPermissionReference

use of org.keycloak.representations.idm.ManagementPermissionReference in project keycloak by keycloak.

the class ClientResource method getManagementPermissions.

/**
 * Return object stating whether client Authorization permissions have been initialized or not and a reference
 *
 * @return
 */
@Path("management/permissions")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public ManagementPermissionReference getManagementPermissions() {
    auth.roles().requireView(client);
    AdminPermissionManagement permissions = AdminPermissions.management(session, realm);
    if (!permissions.clients().isPermissionsEnabled(client)) {
        return new ManagementPermissionReference();
    }
    return toMgmtRef(client, permissions);
}
Also used : ManagementPermissionReference(org.keycloak.representations.idm.ManagementPermissionReference) AdminPermissionManagement(org.keycloak.services.resources.admin.permissions.AdminPermissionManagement) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 5 with ManagementPermissionReference

use of org.keycloak.representations.idm.ManagementPermissionReference in project keycloak by keycloak.

the class RoleContainerResource method setManagementPermissionsEnabled.

/**
 * Return object stating whether role Authorization permissions have been initialized or not and a reference
 *
 * @param roleName
 * @return initialized manage permissions reference
 */
@Path("{role-name}/management/permissions")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@NoCache
public ManagementPermissionReference setManagementPermissionsEnabled(@PathParam("role-name") final String roleName, ManagementPermissionReference ref) {
    auth.roles().requireManage(roleContainer);
    RoleModel role = roleContainer.getRole(roleName);
    if (role == null) {
        throw new NotFoundException("Could not find role");
    }
    AdminPermissionManagement permissions = AdminPermissions.management(session, realm);
    permissions.roles().setPermissionsEnabled(role, ref.isEnabled());
    if (ref.isEnabled()) {
        return RoleByIdResource.toMgmtRef(role, permissions);
    } else {
        return new ManagementPermissionReference();
    }
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) ManagementPermissionReference(org.keycloak.representations.idm.ManagementPermissionReference) RoleModel(org.keycloak.models.RoleModel) AdminPermissionManagement(org.keycloak.services.resources.admin.permissions.AdminPermissionManagement) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache) PUT(javax.ws.rs.PUT)

Aggregations

ManagementPermissionReference (org.keycloak.representations.idm.ManagementPermissionReference)17 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 NoCache (org.jboss.resteasy.annotations.cache.NoCache)12 AdminPermissionManagement (org.keycloak.services.resources.admin.permissions.AdminPermissionManagement)12 Consumes (javax.ws.rs.Consumes)6 GET (javax.ws.rs.GET)6 PUT (javax.ws.rs.PUT)6 RoleModel (org.keycloak.models.RoleModel)4 NotFoundException (javax.ws.rs.NotFoundException)2