Search in sources :

Example 76 with NoCache

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

the class AuthenticationManagementResource method registerRequiredAction.

/**
 * Register a new required actions
 *
 * @param data JSON containing 'providerId', and 'name' attributes.
 */
@Path("register-required-action")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@NoCache
public void registerRequiredAction(Map<String, String> data) {
    auth.realm().requireManageRealm();
    String providerId = data.get("providerId");
    String name = data.get("name");
    RequiredActionProviderModel requiredAction = new RequiredActionProviderModel();
    requiredAction.setAlias(providerId);
    requiredAction.setName(name);
    requiredAction.setProviderId(providerId);
    requiredAction.setDefaultAction(false);
    requiredAction.setPriority(getNextRequiredActionPriority());
    requiredAction.setEnabled(true);
    requiredAction = realm.addRequiredActionProvider(requiredAction);
    data.put("id", requiredAction.getId());
    adminEvent.operation(OperationType.CREATE).resource(ResourceType.REQUIRED_ACTION).resourcePath(session.getContext().getUri()).representation(data).success();
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 77 with NoCache

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

the class AuthenticationManagementResource method raisePriority.

/**
 * Raise execution's priority
 *
 * @param execution Execution id
 */
@Path("/executions/{executionId}/raise-priority")
@POST
@NoCache
public void raisePriority(@PathParam("executionId") String execution) {
    auth.realm().requireManageRealm();
    AuthenticationExecutionModel model = realm.getAuthenticationExecutionById(execution);
    if (model == null) {
        session.getTransactionManager().setRollbackOnly();
        throw new NotFoundException("Illegal execution");
    }
    AuthenticationFlowModel parentFlow = getParentFlow(model);
    if (parentFlow.isBuiltIn()) {
        throw new BadRequestException("It is illegal to modify execution in a built in flow");
    }
    AuthenticationExecutionModel previous = null;
    for (AuthenticationExecutionModel exe : realm.getAuthenticationExecutionsStream(parentFlow.getId()).collect(Collectors.toList())) {
        if (exe.getId().equals(model.getId())) {
            break;
        }
        previous = exe;
    }
    if (previous == null)
        return;
    int tmp = previous.getPriority();
    previous.setPriority(model.getPriority());
    realm.updateAuthenticatorExecution(previous);
    model.setPriority(tmp);
    realm.updateAuthenticatorExecution(model);
    adminEvent.operation(OperationType.UPDATE).resource(ResourceType.AUTH_EXECUTION).resourcePath(session.getContext().getUri()).success();
}
Also used : AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) NotFoundException(javax.ws.rs.NotFoundException) AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 78 with NoCache

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

the class AuthenticationManagementResource method getUnregisteredRequiredActions.

/**
 * Get unregistered required actions
 *
 * Returns a stream of unregistered required actions.
 */
@Path("unregistered-required-actions")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public Stream<Map<String, String>> getUnregisteredRequiredActions() {
    auth.realm().requireViewRealm();
    Set<String> providerIds = realm.getRequiredActionProvidersStream().map(RequiredActionProviderModel::getProviderId).collect(Collectors.toSet());
    return session.getKeycloakSessionFactory().getProviderFactoriesStream(RequiredActionProvider.class).filter(factory -> !providerIds.contains(factory.getId())).map(factory -> {
        RequiredActionFactory r = (RequiredActionFactory) factory;
        Map<String, String> m = new HashMap<>();
        m.put("name", r.getDisplayText());
        m.put("providerId", r.getId());
        return m;
    });
}
Also used : ConfigPropertyRepresentation(org.keycloak.representations.idm.ConfigPropertyRepresentation) ResourceType(org.keycloak.events.admin.ResourceType) Produces(javax.ws.rs.Produces) RequiredActionFactory(org.keycloak.authentication.RequiredActionFactory) Path(javax.ws.rs.Path) ClientAuthenticatorFactory(org.keycloak.authentication.ClientAuthenticatorFactory) DefaultAuthenticationFlows(org.keycloak.models.utils.DefaultAuthenticationFlows) RepresentationToModel(org.keycloak.models.utils.RepresentationToModel) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation) FormAuthenticator(org.keycloak.authentication.FormAuthenticator) BadRequestException(javax.ws.rs.BadRequestException) UriBuilder(javax.ws.rs.core.UriBuilder) DELETE(javax.ws.rs.DELETE) RealmModel(org.keycloak.models.RealmModel) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) CredentialHelper(org.keycloak.utils.CredentialHelper) Set(java.util.Set) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) ReservedCharValidator(org.keycloak.utils.ReservedCharValidator) Objects(java.util.Objects) ClientAuthenticator(org.keycloak.authentication.ClientAuthenticator) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) List(java.util.List) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel) OperationType(org.keycloak.events.admin.OperationType) PathParam(javax.ws.rs.PathParam) AuthenticationFlow(org.keycloak.authentication.AuthenticationFlow) AuthenticatorConfigInfoRepresentation(org.keycloak.representations.idm.AuthenticatorConfigInfoRepresentation) GET(javax.ws.rs.GET) Logger(org.jboss.logging.Logger) ProviderConfigProperty(org.keycloak.provider.ProviderConfigProperty) HashMap(java.util.HashMap) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) AuthenticatorConfigModel(org.keycloak.models.AuthenticatorConfigModel) AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel) ConfigurableAuthenticatorFactory(org.keycloak.authentication.ConfigurableAuthenticatorFactory) LinkedList(java.util.LinkedList) ProviderFactory(org.keycloak.provider.ProviderFactory) FormAction(org.keycloak.authentication.FormAction) POST(javax.ws.rs.POST) Authenticator(org.keycloak.authentication.Authenticator) AdminPermissionEvaluator(org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator) KeycloakSession(org.keycloak.models.KeycloakSession) RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) RequiredActionProvider(org.keycloak.authentication.RequiredActionProvider) AuthenticatorConfigRepresentation(org.keycloak.representations.idm.AuthenticatorConfigRepresentation) NoCache(org.jboss.resteasy.annotations.cache.NoCache) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) ErrorResponse(org.keycloak.services.ErrorResponse) RequiredActionFactory(org.keycloak.authentication.RequiredActionFactory) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 79 with NoCache

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

the class AuthenticationManagementResource method createFlow.

/**
 * Create a new authentication flow
 *
 * @param flow Authentication flow representation
 * @return
 */
@Path("/flows")
@POST
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
public Response createFlow(AuthenticationFlowRepresentation flow) {
    auth.realm().requireManageRealm();
    if (flow.getAlias() == null || flow.getAlias().isEmpty()) {
        return ErrorResponse.exists("Failed to create flow with empty alias name");
    }
    if (realm.getFlowByAlias(flow.getAlias()) != null) {
        return ErrorResponse.exists("Flow " + flow.getAlias() + " already exists");
    }
    ReservedCharValidator.validate(flow.getAlias());
    AuthenticationFlowModel createdModel = realm.addAuthenticationFlow(RepresentationToModel.toModel(flow));
    flow.setId(createdModel.getId());
    adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), createdModel.getId()).representation(flow).success();
    return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(flow.getId()).build()).build();
}
Also used : 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 80 with NoCache

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

the class AuthenticationManagementResource method updateAuthenticatorConfig.

/**
 * Update authenticator configuration
 * @param id Configuration id
 * @param rep JSON describing new state of authenticator configuration
 */
@Path("config/{id}")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@NoCache
public void updateAuthenticatorConfig(@PathParam("id") String id, AuthenticatorConfigRepresentation rep) {
    auth.realm().requireManageRealm();
    ReservedCharValidator.validate(rep.getAlias());
    AuthenticatorConfigModel exists = realm.getAuthenticatorConfigById(id);
    if (exists == null) {
        throw new NotFoundException("Could not find authenticator config");
    }
    exists.setAlias(rep.getAlias());
    exists.setConfig(RepresentationToModel.removeEmptyString(rep.getConfig()));
    realm.updateAuthenticatorConfig(exists);
    adminEvent.operation(OperationType.UPDATE).resource(ResourceType.AUTHENTICATOR_CONFIG).resourcePath(session.getContext().getUri()).representation(rep).success();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) AuthenticatorConfigModel(org.keycloak.models.AuthenticatorConfigModel) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache) PUT(javax.ws.rs.PUT)

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