Search in sources :

Example 6 with RoleModel

use of org.keycloak.models.RoleModel in project keycloak by keycloak.

the class RoleByIdResource method getRole.

/**
 * Get a specific role's representation
 *
 * @param id id of role
 * @return
 */
@Path("{role-id}")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public RoleRepresentation getRole(@PathParam("role-id") final String id) {
    RoleModel roleModel = getRoleModel(id);
    auth.roles().requireView(roleModel);
    return getRole(roleModel);
}
Also used : RoleModel(org.keycloak.models.RoleModel) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 7 with RoleModel

use of org.keycloak.models.RoleModel in project keycloak by keycloak.

the class RoleByIdResource method addComposites.

/**
 * Make the role a composite role by associating some child roles
 *
 * @param id
 * @param roles
 */
@Path("{role-id}/composites")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public void addComposites(@PathParam("role-id") final String id, List<RoleRepresentation> roles) {
    RoleModel role = getRoleModel(id);
    auth.roles().requireManage(role);
    addComposites(auth, adminEvent, session.getContext().getUri(), roles, role);
}
Also used : RoleModel(org.keycloak.models.RoleModel) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 8 with RoleModel

use of org.keycloak.models.RoleModel in project keycloak by keycloak.

the class RoleByIdResource method getRoleComposites.

/**
 * Get role's children
 *
 * Returns a set of role's children provided the role is a composite.
 *
 * @param id
 * @return
 */
@Path("{role-id}/composites")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Stream<RoleRepresentation> getRoleComposites(@PathParam("role-id") final String id, @QueryParam("search") final String search, @QueryParam("first") final Integer first, @QueryParam("max") final Integer max) {
    if (logger.isDebugEnabled())
        logger.debug("*** getRoleComposites: '" + id + "'");
    RoleModel role = getRoleModel(id);
    auth.roles().requireView(role);
    if (search == null && first == null && max == null) {
        return role.getCompositesStream().map(ModelToRepresentation::toBriefRepresentation);
    }
    return role.getCompositesStream(search, first, max).map(ModelToRepresentation::toBriefRepresentation);
}
Also used : RoleModel(org.keycloak.models.RoleModel) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 9 with RoleModel

use of org.keycloak.models.RoleModel in project keycloak by keycloak.

the class RoleByIdResource method getClientRoleComposites.

/**
 * Get client-level roles for the client that are in the role's composite
 *
 * @param id
 * @param clientUuid
 * @return
 */
@Path("{role-id}/composites/clients/{clientUuid}")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Stream<RoleRepresentation> getClientRoleComposites(@PathParam("role-id") final String id, @PathParam("clientUuid") final String clientUuid) {
    RoleModel role = getRoleModel(id);
    auth.roles().requireView(role);
    ClientModel clientModel = realm.getClientById(clientUuid);
    if (clientModel == null) {
        throw new NotFoundException("Could not find client");
    }
    return getClientRoleComposites(clientModel, role);
}
Also used : ClientModel(org.keycloak.models.ClientModel) NotFoundException(javax.ws.rs.NotFoundException) RoleModel(org.keycloak.models.RoleModel) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 10 with RoleModel

use of org.keycloak.models.RoleModel in project keycloak by keycloak.

the class RoleByIdResource method deleteComposites.

/**
 * Remove a set of roles from the role's composite
 *
 * @param id Role id
 * @param roles A set of roles to be removed
 */
@Path("{role-id}/composites")
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
public void deleteComposites(@PathParam("role-id") final String id, List<RoleRepresentation> roles) {
    RoleModel role = getRoleModel(id);
    auth.roles().requireManage(role);
    deleteComposites(adminEvent, session.getContext().getUri(), roles, role);
}
Also used : RoleModel(org.keycloak.models.RoleModel) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Aggregations

RoleModel (org.keycloak.models.RoleModel)153 ClientModel (org.keycloak.models.ClientModel)73 RealmModel (org.keycloak.models.RealmModel)69 UserModel (org.keycloak.models.UserModel)36 Path (javax.ws.rs.Path)29 Test (org.junit.Test)29 NotFoundException (javax.ws.rs.NotFoundException)25 NoCache (org.jboss.resteasy.annotations.cache.NoCache)20 KeycloakSession (org.keycloak.models.KeycloakSession)19 Consumes (javax.ws.rs.Consumes)17 List (java.util.List)16 GET (javax.ws.rs.GET)16 Produces (javax.ws.rs.Produces)16 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)15 LinkedList (java.util.LinkedList)14 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 GroupModel (org.keycloak.models.GroupModel)12 RoleContainerModel (org.keycloak.models.RoleContainerModel)12 Policy (org.keycloak.authorization.model.Policy)11