Search in sources :

Example 26 with NoCache

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

the class SamlService method soapBinding.

/**
 * Handles SOAP messages. Chooses the correct response path depending on whether the message is of type ECP
 * @param inputStream the data of the request.
 * @return The response to the SOAP message
 */
@POST
@NoCache
@Consumes({ "application/soap+xml", MediaType.TEXT_XML })
public Response soapBinding(InputStream inputStream) {
    SamlEcpProfileService bindingService = new SamlEcpProfileService(realm, event, destinationValidator);
    ResteasyProviderFactory.getInstance().injectProperties(bindingService);
    return bindingService.authenticate(inputStream);
}
Also used : SamlEcpProfileService(org.keycloak.protocol.saml.profile.ecp.SamlEcpProfileService) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 27 with NoCache

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

the class TestingResourceProvider method getAdminEvents.

/**
 * Get admin events
 *
 * Returns all admin events, or filters events based on URL query parameters listed here
 *
 * @param realmId
 * @param operationTypes
 * @param authRealm
 * @param authClient
 * @param authUser user id
 * @param authIpAddress
 * @param resourcePath
 * @param dateFrom
 * @param dateTo
 * @param firstResult
 * @param maxResults
 * @return
 */
@Path("query-admin-events")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Stream<AdminEventRepresentation> getAdminEvents(@QueryParam("realmId") String realmId, @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) {
    EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
    AdminEventQuery query = eventStore.createAdminQuery();
    if (realmId != null) {
        query.realm(realmId);
    }
    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 (dateFrom != null) {
        Date from = formatDate(dateFrom, "Date(From)");
        query.fromTime(from);
    }
    if (dateTo != null) {
        Date to = formatDate(dateTo, "Date(To)");
        query.toTime(to);
    }
    if (firstResult != null || maxResults != null) {
        if (firstResult == null) {
            firstResult = 0;
        }
        if (maxResults == null) {
            maxResults = 100;
        }
        query.firstResult(firstResult);
        query.maxResults(maxResults);
    }
    return query.getResultStream().map(ModelToRepresentation::toRepresentation);
}
Also used : AdminEventQuery(org.keycloak.events.admin.AdminEventQuery) OperationType(org.keycloak.events.admin.OperationType) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) 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)

Example 28 with NoCache

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

the class TestingResourceProvider method generateAudienceClientScope.

/**
 * Generate new client scope for specified service client. The "Frontend" clients, who will use this client scope, will be able to
 * send their access token to authenticate against specified service client
 *
 * @param clientId Client ID of service client (typically bearer-only client)
 * @return ID of the newly generated clientScope
 */
@Path("generate-audience-client-scope")
@POST
@NoCache
public String generateAudienceClientScope(@QueryParam("realm") final String realmName, @QueryParam("clientId") final String clientId) {
    try {
        RealmModel realm = getRealmByName(realmName);
        ClientModel serviceClient = realm.getClientByClientId(clientId);
        if (serviceClient == null) {
            throw new NotFoundException("Referenced service client doesn't exist");
        }
        ClientScopeModel clientScopeModel = realm.addClientScope(clientId);
        clientScopeModel.setProtocol(serviceClient.getProtocol() == null ? OIDCLoginProtocol.LOGIN_PROTOCOL : serviceClient.getProtocol());
        clientScopeModel.setDisplayOnConsentScreen(true);
        clientScopeModel.setConsentScreenText(clientId);
        clientScopeModel.setIncludeInTokenScope(true);
        // Add audience protocol mapper
        ProtocolMapperModel audienceMapper = AudienceProtocolMapper.createClaimMapper("Audience for " + clientId, clientId, null, true, false);
        clientScopeModel.addProtocolMapper(audienceMapper);
        return clientScopeModel.getId();
    } catch (ModelDuplicateException e) {
        throw new BadRequestException("Client Scope " + clientId + " already exists");
    }
}
Also used : RealmModel(org.keycloak.models.RealmModel) ClientModel(org.keycloak.models.ClientModel) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) ClientScopeModel(org.keycloak.models.ClientScopeModel) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 29 with NoCache

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

the class TestingResourceProvider method queryEvents.

/**
 * Query events
 * <p>
 * Returns all events, or filters them based on URL query parameters listed here
 *
 * @param realmId     The realm
 * @param types       The types of events to return
 * @param client      App or oauth client name
 * @param user        User id
 * @param dateFrom    From date
 * @param dateTo      To date
 * @param ipAddress   IP address
 * @param firstResult Paging offset
 * @param maxResults  Paging size
 * @return
 */
@Path("query-events")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Stream<EventRepresentation> queryEvents(@QueryParam("realmId") String realmId, @QueryParam("type") List<String> types, @QueryParam("client") String client, @QueryParam("user") String user, @QueryParam("dateFrom") String dateFrom, @QueryParam("dateTo") String dateTo, @QueryParam("ipAddress") String ipAddress, @QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResults) {
    EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
    EventQuery query = eventStore.createQuery();
    if (realmId != null) {
        query.realm(realmId);
    }
    if (client != null) {
        query.client(client);
    }
    if (types != null & !types.isEmpty()) {
        EventType[] t = new EventType[types.size()];
        for (int i = 0; i < t.length; i++) {
            t[i] = EventType.valueOf(types.get(i));
        }
        query.type(t);
    }
    if (user != null) {
        query.user(user);
    }
    if (dateFrom != null) {
        Date from = formatDate(dateFrom, "Date(From)");
        query.fromDate(from);
    }
    if (dateTo != null) {
        Date to = formatDate(dateTo, "Date(To)");
        query.toDate(to);
    }
    if (ipAddress != null) {
        query.ipAddress(ipAddress);
    }
    if (firstResult != null) {
        query.firstResult(firstResult);
    }
    if (maxResults != null) {
        query.maxResults(maxResults);
    }
    return query.getResultStream().map(ModelToRepresentation::toRepresentation);
}
Also used : EventType(org.keycloak.events.EventType) AdminEventQuery(org.keycloak.events.admin.AdminEventQuery) EventQuery(org.keycloak.events.EventQuery) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) 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)

Example 30 with NoCache

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

the class TestingOIDCEndpointsApplicationResource method cibaClientNotificationEndpoint.

@POST
@Path("/push-ciba-client-notification")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public Response cibaClientNotificationEndpoint(@Context HttpHeaders headers, ClientNotificationEndpointRequest request) {
    String clientNotificationToken = AppAuthManager.extractAuthorizationHeaderToken(headers);
    ClientNotificationEndpointRequest existing = cibaClientNotifications.putIfAbsent(clientNotificationToken, request);
    if (existing != null) {
        throw new ErrorResponseException(OAuthErrorException.INVALID_REQUEST, "There is already entry for clientNotification " + clientNotificationToken + ". Make sure to cleanup after previous tests.", Response.Status.BAD_REQUEST);
    }
    return Response.noContent().build();
}
Also used : ClientNotificationEndpointRequest(org.keycloak.protocol.oidc.grants.ciba.endpoints.ClientNotificationEndpointRequest) ErrorResponseException(org.keycloak.services.ErrorResponseException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) 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