Search in sources :

Example 11 with AdminPermissionManagement

use of org.keycloak.services.resources.admin.permissions.AdminPermissionManagement 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)

Example 12 with AdminPermissionManagement

use of org.keycloak.services.resources.admin.permissions.AdminPermissionManagement in project keycloak by keycloak.

the class IdentityProviderResource method setManagementPermissionsEnabled.

/**
 * Return object stating whether client Authorization permissions have been initialized or not and a reference
 *
 * @return initialized manage permissions reference
 */
@Path("management/permissions")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@NoCache
public ManagementPermissionReference setManagementPermissionsEnabled(ManagementPermissionReference ref) {
    this.auth.realm().requireManageIdentityProviders();
    AdminPermissionManagement permissions = AdminPermissions.management(session, realm);
    permissions.idps().setPermissionsEnabled(identityProviderModel, ref.isEnabled());
    if (ref.isEnabled()) {
        return toMgmtRef(identityProviderModel, permissions);
    } else {
        return new ManagementPermissionReference();
    }
}
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) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache) PUT(javax.ws.rs.PUT)

Example 13 with AdminPermissionManagement

use of org.keycloak.services.resources.admin.permissions.AdminPermissionManagement in project keycloak by keycloak.

the class RealmAdminResource method getUserMgmtPermissions.

@NoCache
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("users-management-permissions")
public ManagementPermissionReference getUserMgmtPermissions() {
    auth.realm().requireViewRealm();
    AdminPermissionManagement permissions = AdminPermissions.management(session, realm);
    if (permissions.users().isPermissionsEnabled()) {
        return toUsersMgmtRef(permissions);
    } else {
        return new ManagementPermissionReference();
    }
}
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 14 with AdminPermissionManagement

use of org.keycloak.services.resources.admin.permissions.AdminPermissionManagement in project keycloak by keycloak.

the class GroupResource method setManagementPermissionsEnabled.

/**
 * Return object stating whether client Authorization permissions have been initialized or not and a reference
 *
 * @return initialized manage permissions reference
 */
@Path("management/permissions")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@NoCache
public ManagementPermissionReference setManagementPermissionsEnabled(ManagementPermissionReference ref) {
    auth.groups().requireManage(group);
    AdminPermissionManagement permissions = AdminPermissions.management(session, realm);
    permissions.groups().setPermissionsEnabled(group, ref.isEnabled());
    if (ref.isEnabled()) {
        return toMgmtRef(group, permissions);
    } else {
        return new ManagementPermissionReference();
    }
}
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) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache) PUT(javax.ws.rs.PUT)

Example 15 with AdminPermissionManagement

use of org.keycloak.services.resources.admin.permissions.AdminPermissionManagement in project keycloak by keycloak.

the class GroupResource 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.groups().requireView(group);
    AdminPermissionManagement permissions = AdminPermissions.management(session, realm);
    if (!permissions.groups().isPermissionsEnabled(group)) {
        return new ManagementPermissionReference();
    }
    return toMgmtRef(group, 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)

Aggregations

AdminPermissionManagement (org.keycloak.services.resources.admin.permissions.AdminPermissionManagement)26 ClientModel (org.keycloak.models.ClientModel)14 RealmModel (org.keycloak.models.RealmModel)14 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 NoCache (org.jboss.resteasy.annotations.cache.NoCache)12 Policy (org.keycloak.authorization.model.Policy)12 RoleModel (org.keycloak.models.RoleModel)12 ManagementPermissionReference (org.keycloak.representations.idm.ManagementPermissionReference)12 ResourceServer (org.keycloak.authorization.model.ResourceServer)9 UserModel (org.keycloak.models.UserModel)8 ClientPolicyRepresentation (org.keycloak.representations.idm.authorization.ClientPolicyRepresentation)7 Consumes (javax.ws.rs.Consumes)6 GET (javax.ws.rs.GET)6 PUT (javax.ws.rs.PUT)6 GroupModel (org.keycloak.models.GroupModel)5 UserPolicyRepresentation (org.keycloak.representations.idm.authorization.UserPolicyRepresentation)4 Test (org.junit.Test)3 Keycloak (org.keycloak.admin.client.Keycloak)3 AuthorizationProvider (org.keycloak.authorization.AuthorizationProvider)3