Search in sources :

Example 86 with NoCache

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

the class ProtocolMappersResource method createMapper.

/**
 * Create multiple mappers
 */
@Path("add-models")
@POST
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
public void createMapper(List<ProtocolMapperRepresentation> reps) {
    managePermission.require();
    ProtocolMapperModel model = null;
    for (ProtocolMapperRepresentation rep : reps) {
        model = RepresentationToModel.toModel(rep);
        validateModel(model);
        model = client.addProtocolMapper(model);
    }
    adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri()).representation(reps).success();
}
Also used : ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 87 with NoCache

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

the class ProtocolMappersResource method delete.

/**
 * Delete the mapper
 *
 * @param id Mapper id
 */
@DELETE
@NoCache
@Path("models/{id}")
public void delete(@PathParam("id") String id) {
    managePermission.require();
    ProtocolMapperModel model = client.getProtocolMapperById(id);
    if (model == null)
        throw new NotFoundException("Model not found");
    client.removeProtocolMapper(model);
    adminEvent.operation(OperationType.DELETE).resourcePath(session.getContext().getUri()).success();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 88 with NoCache

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

the class ProtocolMappersResource method createMapper.

/**
 * Create a mapper
 *
 * @param rep
 */
@Path("models")
@POST
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
public Response createMapper(ProtocolMapperRepresentation rep) {
    managePermission.require();
    ProtocolMapperModel model = null;
    try {
        model = RepresentationToModel.toModel(rep);
        validateModel(model);
        model = client.addProtocolMapper(model);
        adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), model.getId()).representation(rep).success();
    } catch (ModelDuplicateException e) {
        return ErrorResponse.exists("Protocol mapper exists with same name");
    }
    return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(model.getId()).build()).build();
}
Also used : ModelDuplicateException(org.keycloak.models.ModelDuplicateException) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 89 with NoCache

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

the class RoleByIdResource method setManagementPermissionsEnabled.

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

Example 90 with NoCache

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

the class RealmAdminResource method getEvents.

/**
 * Get admin events
 *
 * Returns all admin events, or filters events based on URL query parameters listed here
 *
 * @param operationTypes
 * @param authRealm
 * @param authClient
 * @param authUser user id
 * @param authIpAddress
 * @param resourcePath
 * @param dateTo
 * @param dateFrom
 * @param firstResult
 * @param maxResults Maximum results size (defaults to 100)
 * @return
 */
@Path("admin-events")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Stream<AdminEventRepresentation> getEvents(@QueryParam("operationTypes") List<String> operationTypes, @QueryParam("authRealm") String authRealm, @QueryParam("authClient") String authClient, @QueryParam("authUser") String authUser, @QueryParam("authIpAddress") String authIpAddress, @QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") String dateFrom, @QueryParam("dateTo") String dateTo, @QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResults, @QueryParam("resourceTypes") List<String> resourceTypes) {
    auth.realm().requireViewEvents();
    EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
    AdminEventQuery query = eventStore.createAdminQuery().realm(realm.getId());
    ;
    if (authRealm != null) {
        query.authRealm(authRealm);
    }
    if (authClient != null) {
        query.authClient(authClient);
    }
    if (authUser != null) {
        query.authUser(authUser);
    }
    if (authIpAddress != null) {
        query.authIpAddress(authIpAddress);
    }
    if (resourcePath != null) {
        query.resourcePath(resourcePath);
    }
    if (operationTypes != null && !operationTypes.isEmpty()) {
        OperationType[] t = new OperationType[operationTypes.size()];
        for (int i = 0; i < t.length; i++) {
            t[i] = OperationType.valueOf(operationTypes.get(i));
        }
        query.operation(t);
    }
    if (resourceTypes != null && !resourceTypes.isEmpty()) {
        ResourceType[] t = new ResourceType[resourceTypes.size()];
        for (int i = 0; i < t.length; i++) {
            t[i] = ResourceType.valueOf(resourceTypes.get(i));
        }
        query.resourceType(t);
    }
    if (dateFrom != null) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date from = null;
        try {
            from = df.parse(dateFrom);
        } catch (ParseException e) {
            throw new BadRequestException("Invalid value for 'Date(From)', expected format is yyyy-MM-dd");
        }
        query.fromTime(from);
    }
    if (dateTo != null) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date to = null;
        try {
            to = df.parse(dateTo);
        } catch (ParseException e) {
            throw new BadRequestException("Invalid value for 'Date(To)', expected format is yyyy-MM-dd");
        }
        query.toTime(to);
    }
    if (firstResult != null) {
        query.firstResult(firstResult);
    }
    if (maxResults != null) {
        query.maxResults(maxResults);
    } else {
        query.maxResults(Constants.DEFAULT_MAX_RESULTS);
    }
    return query.getResultStream().map(ModelToRepresentation::toRepresentation);
}
Also used : AdminEventQuery(org.keycloak.events.admin.AdminEventQuery) BadRequestException(javax.ws.rs.BadRequestException) ResourceType(org.keycloak.events.admin.ResourceType) OperationType(org.keycloak.events.admin.OperationType) ParseException(java.text.ParseException) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) EventStoreProvider(org.keycloak.events.EventStoreProvider) 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