Search in sources :

Example 81 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.

the class AuthenticationManagementResource method addExecutionFlow.

/**
 * Add new flow with new execution to existing flow
 *
 * @param flowAlias Alias of parent authentication flow
 * @param data New authentication flow / execution JSON data containing 'alias', 'type', 'provider', and 'description' attributes
 */
@Path("/flows/{flowAlias}/executions/flow")
@POST
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
public Response addExecutionFlow(@PathParam("flowAlias") String flowAlias, Map<String, String> data) {
    auth.realm().requireManageRealm();
    AuthenticationFlowModel parentFlow = realm.getFlowByAlias(flowAlias);
    if (parentFlow == null) {
        return ErrorResponse.error("Parent flow doesn't exist", Response.Status.BAD_REQUEST);
    }
    String alias = data.get("alias");
    String type = data.get("type");
    String provider = data.get("provider");
    String description = data.get("description");
    AuthenticationFlowModel newFlow = realm.getFlowByAlias(alias);
    if (newFlow != null) {
        return ErrorResponse.exists("New flow alias name already exists");
    }
    newFlow = new AuthenticationFlowModel();
    newFlow.setAlias(alias);
    newFlow.setDescription(description);
    newFlow.setProviderId(type);
    newFlow = realm.addAuthenticationFlow(newFlow);
    AuthenticationExecutionModel execution = new AuthenticationExecutionModel();
    execution.setParentFlow(parentFlow.getId());
    execution.setFlowId(newFlow.getId());
    execution.setRequirement(AuthenticationExecutionModel.Requirement.DISABLED);
    execution.setAuthenticatorFlow(true);
    if (type.equals("form-flow")) {
        execution.setAuthenticator(provider);
    }
    execution.setPriority(getNextPriority(parentFlow));
    execution = realm.addAuthenticatorExecution(execution);
    data.put("id", execution.getId());
    adminEvent.operation(OperationType.CREATE).resource(ResourceType.AUTH_EXECUTION_FLOW).resourcePath(session.getContext().getUri()).representation(data).success();
    String addExecutionPathSegment = UriBuilder.fromMethod(AuthenticationManagementResource.class, "addExecutionFlow").build(parentFlow.getAlias()).getPath();
    return Response.created(session.getContext().getUri().getBaseUriBuilder().path(session.getContext().getUri().getPath().replace(addExecutionPathSegment, "")).path("flows").path(newFlow.getId()).build()).build();
}
Also used : AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 82 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.

the class AuthenticationManagementResource method lowerRequiredActionPriority.

/**
 * Lower required action's priority
 *
 * @param alias Alias of required action
 */
@Path("/required-actions/{alias}/lower-priority")
@POST
@NoCache
public void lowerRequiredActionPriority(@PathParam("alias") String alias) {
    auth.realm().requireManageRealm();
    RequiredActionProviderModel model = realm.getRequiredActionProviderByAlias(alias);
    if (model == null) {
        throw new NotFoundException("Failed to find required action.");
    }
    List<RequiredActionProviderModel> actions = realm.getRequiredActionProvidersStream().collect(Collectors.toList());
    int i;
    for (i = 0; i < actions.size(); i++) {
        if (actions.get(i).getId().equals(model.getId())) {
            break;
        }
    }
    if (i + 1 >= actions.size())
        return;
    RequiredActionProviderModel next = actions.get(i + 1);
    int tmp = model.getPriority();
    model.setPriority(next.getPriority());
    realm.updateRequiredActionProvider(model);
    next.setPriority(tmp);
    realm.updateRequiredActionProvider(next);
    adminEvent.operation(OperationType.UPDATE).resource(ResourceType.REQUIRED_ACTION).resourcePath(session.getContext().getUri()).success();
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 83 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.

the class RoleMapperResource method getRoleMappings.

/**
 * Get role mappings
 *
 * @return
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public MappingsRepresentation getRoleMappings() {
    viewPermission.require();
    List<RoleRepresentation> realmRolesRepresentation = new ArrayList<>();
    Map<String, ClientMappingsRepresentation> appMappings = new HashMap<>();
    final AtomicReference<ClientMappingsRepresentation> mappings = new AtomicReference<>();
    roleMapper.getRoleMappingsStream().forEach(roleMapping -> {
        RoleContainerModel container = roleMapping.getContainer();
        if (container instanceof RealmModel) {
            realmRolesRepresentation.add(ModelToRepresentation.toBriefRepresentation(roleMapping));
        } else if (container instanceof ClientModel) {
            ClientModel clientModel = (ClientModel) container;
            mappings.set(appMappings.get(clientModel.getClientId()));
            if (mappings.get() == null) {
                mappings.set(new ClientMappingsRepresentation());
                mappings.get().setId(clientModel.getId());
                mappings.get().setClient(clientModel.getClientId());
                mappings.get().setMappings(new ArrayList<>());
                appMappings.put(clientModel.getClientId(), mappings.get());
            }
            mappings.get().getMappings().add(ModelToRepresentation.toBriefRepresentation(roleMapping));
        }
    });
    MappingsRepresentation all = new MappingsRepresentation();
    if (!realmRolesRepresentation.isEmpty())
        all.setRealmMappings(realmRolesRepresentation);
    if (!appMappings.isEmpty())
        all.setClientMappings(appMappings);
    return all;
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) RealmModel(org.keycloak.models.RealmModel) ClientModel(org.keycloak.models.ClientModel) MappingsRepresentation(org.keycloak.representations.idm.MappingsRepresentation) ClientMappingsRepresentation(org.keycloak.representations.idm.ClientMappingsRepresentation) ClientMappingsRepresentation(org.keycloak.representations.idm.ClientMappingsRepresentation) RoleContainerModel(org.keycloak.models.RoleContainerModel) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 84 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.

the class UserResource method removeMembership.

@DELETE
@Path("groups/{groupId}")
@NoCache
public void removeMembership(@PathParam("groupId") String groupId) {
    auth.users().requireManageGroupMembership(user);
    GroupModel group = session.groups().getGroupById(realm, groupId);
    if (group == null) {
        throw new NotFoundException("Group not found");
    }
    auth.groups().requireManageMembership(group);
    try {
        if (user.isMemberOf(group)) {
            user.leaveGroup(group);
            adminEvent.operation(OperationType.DELETE).resource(ResourceType.GROUP_MEMBERSHIP).representation(ModelToRepresentation.toRepresentation(group, true)).resourcePath(session.getContext().getUri()).success();
        }
    } catch (ModelException me) {
        Properties messages = AdminRoot.getMessages(session, realm, auth.adminAuth().getToken().getLocale());
        throw new ErrorResponseException(me.getMessage(), MessageFormat.format(messages.getProperty(me.getMessage(), me.getMessage()), me.getParameters()), Status.BAD_REQUEST);
    }
}
Also used : ModelException(org.keycloak.models.ModelException) GroupModel(org.keycloak.models.GroupModel) NotFoundException(javax.ws.rs.NotFoundException) ErrorResponseException(org.keycloak.services.ErrorResponseException) Properties(java.util.Properties) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 85 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.

the class ProtocolMappersResource method getMapperById.

/**
 * Get mapper by id
 *
 * @param id Mapper id
 * @return
 */
@GET
@NoCache
@Path("models/{id}")
@Produces(MediaType.APPLICATION_JSON)
public ProtocolMapperRepresentation getMapperById(@PathParam("id") String id) {
    viewPermission.require();
    ProtocolMapperModel model = client.getProtocolMapperById(id);
    if (model == null)
        throw new NotFoundException("Model not found");
    return ModelToRepresentation.toRepresentation(model);
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

NoCache (org.jboss.resteasy.annotations.cache.NoCache)152 Path (javax.ws.rs.Path)128 Produces (javax.ws.rs.Produces)100 GET (javax.ws.rs.GET)82 NotFoundException (javax.ws.rs.NotFoundException)67 POST (javax.ws.rs.POST)49 Consumes (javax.ws.rs.Consumes)48 PUT (javax.ws.rs.PUT)24 DELETE (javax.ws.rs.DELETE)23 HashMap (java.util.HashMap)20 RoleModel (org.keycloak.models.RoleModel)18 UserModel (org.keycloak.models.UserModel)18 BadRequestException (javax.ws.rs.BadRequestException)17 Response (javax.ws.rs.core.Response)16 ErrorResponseException (org.keycloak.services.ErrorResponseException)16 ClientModel (org.keycloak.models.ClientModel)15 AuthenticationFlowModel (org.keycloak.models.AuthenticationFlowModel)14 RealmModel (org.keycloak.models.RealmModel)14 List (java.util.List)12 Map (java.util.Map)12