Search in sources :

Example 16 with ForbiddenException

use of org.keycloak.services.ForbiddenException in project keycloak by keycloak.

the class UsersResource method user.

/**
 * Get representation of the user
 *
 * @param id User id
 * @return
 */
@Path("{id}")
public UserResource user(@PathParam("id") final String id) {
    UserModel user = session.users().getUserById(realm, id);
    if (user == null) {
        // we do this to make sure somebody can't phish ids
        if (auth.users().canQuery())
            throw new NotFoundException("User not found");
        else
            throw new ForbiddenException();
    }
    UserResource resource = new UserResource(realm, user, auth, adminEvent);
    ResteasyProviderFactory.getInstance().injectProperties(resource);
    // resourceContext.initResource(users);
    return resource;
}
Also used : UserModel(org.keycloak.models.UserModel) ForbiddenException(org.keycloak.services.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) KeycloakModelUtils.findGroupByPath(org.keycloak.models.utils.KeycloakModelUtils.findGroupByPath)

Example 17 with ForbiddenException

use of org.keycloak.services.ForbiddenException in project keycloak by keycloak.

the class AbstractClientRegistrationProvider method delete.

public void delete(String clientId) {
    event.event(EventType.CLIENT_DELETE).client(clientId);
    ClientModel client = session.getContext().getRealm().getClientByClientId(clientId);
    auth.requireDelete(client);
    if (new ClientManager(new RealmManager(session)).removeClient(session.getContext().getRealm(), client)) {
        event.client(client.getClientId()).success();
    } else {
        throw new ForbiddenException();
    }
}
Also used : ClientModel(org.keycloak.models.ClientModel) ForbiddenException(org.keycloak.services.ForbiddenException) ClientManager(org.keycloak.services.managers.ClientManager) RealmManager(org.keycloak.services.managers.RealmManager)

Aggregations

ForbiddenException (org.keycloak.services.ForbiddenException)17 Path (javax.ws.rs.Path)9 NotFoundException (javax.ws.rs.NotFoundException)7 POST (javax.ws.rs.POST)4 ClientModel (org.keycloak.models.ClientModel)4 Consumes (javax.ws.rs.Consumes)3 CredentialModel (org.keycloak.credential.CredentialModel)3 UserCredentialModel (org.keycloak.models.UserCredentialModel)3 UserModel (org.keycloak.models.UserModel)3 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)2 PUT (javax.ws.rs.PUT)2 Produces (javax.ws.rs.Produces)2 Cookie (javax.ws.rs.core.Cookie)2 Response (javax.ws.rs.core.Response)2 ModelDuplicateException (org.keycloak.models.ModelDuplicateException)2 ModelException (org.keycloak.models.ModelException)2 RealmModel (org.keycloak.models.RealmModel)2 UserSessionModel (org.keycloak.models.UserSessionModel)2 ErrorResponse (org.keycloak.services.ErrorResponse)2 RealmManager (org.keycloak.services.managers.RealmManager)2