Search in sources :

Example 61 with NoCache

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

the class GroupResource method getManagementPermissions.

/**
 * Return object stating whether client Authorization permissions have been initialized or not and a reference
 *
 * @return
 */
@Path("management/permissions")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public ManagementPermissionReference getManagementPermissions() {
    auth.groups().requireView(group);
    AdminPermissionManagement permissions = AdminPermissions.management(session, realm);
    if (!permissions.groups().isPermissionsEnabled(group)) {
        return new ManagementPermissionReference();
    }
    return toMgmtRef(group, permissions);
}
Also used : ManagementPermissionReference(org.keycloak.representations.idm.ManagementPermissionReference) AdminPermissionManagement(org.keycloak.services.resources.admin.permissions.AdminPermissionManagement) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 62 with NoCache

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

the class RealmAdminResource method testSMTPConnection.

@Path("testSMTPConnection")
@POST
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
public Response testSMTPConnection(Map<String, String> settings) throws Exception {
    try {
        UserModel user = auth.adminAuth().getUser();
        if (user.getEmail() == null) {
            return ErrorResponse.error("Logged in user does not have an e-mail.", Response.Status.INTERNAL_SERVER_ERROR);
        }
        if (ComponentRepresentation.SECRET_VALUE.equals(settings.get("password"))) {
            settings.put("password", realm.getSmtpConfig().get("password"));
        }
        session.getProvider(EmailTemplateProvider.class).sendSmtpTestEmail(settings, user);
    } catch (Exception e) {
        e.printStackTrace();
        logger.errorf("Failed to send email \n %s", e.getCause());
        return ErrorResponse.error("Failed to send email", Response.Status.INTERNAL_SERVER_ERROR);
    }
    return Response.noContent().build();
}
Also used : UserModel(org.keycloak.models.UserModel) EmailTemplateProvider(org.keycloak.email.EmailTemplateProvider) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) BadRequestException(javax.ws.rs.BadRequestException) ParseException(java.text.ParseException) VerificationException(org.keycloak.common.VerificationException) NotFoundException(javax.ws.rs.NotFoundException) ModelException(org.keycloak.models.ModelException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 63 with NoCache

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

the class RealmAdminResource method getRealm.

/**
 * Get the top-level representation of the realm
 *
 * It will not include nested information like User and Client representations.
 *
 * @return
 */
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public RealmRepresentation getRealm() {
    if (auth.realm().canViewRealm()) {
        return ModelToRepresentation.toRepresentation(session, realm, false);
    } else {
        auth.realm().requireViewRealmNameList();
        RealmRepresentation rep = new RealmRepresentation();
        rep.setRealm(realm.getName());
        if (auth.realm().canViewIdentityProviders()) {
            RealmRepresentation r = ModelToRepresentation.toRepresentation(session, realm, false);
            rep.setIdentityProviders(r.getIdentityProviders());
            rep.setIdentityProviderMappers(r.getIdentityProviderMappers());
        }
        return rep;
    }
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 64 with NoCache

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

the class RoleContainerResource method getManagementPermissions.

/**
 * Return object stating whether role Authorization permissions have been initialized or not and a reference
 *
 * @param roleName
 * @return
 */
@Path("{role-name}/management/permissions")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public ManagementPermissionReference getManagementPermissions(@PathParam("role-name") final String roleName) {
    auth.roles().requireView(roleContainer);
    RoleModel role = roleContainer.getRole(roleName);
    if (role == null) {
        throw new NotFoundException("Could not find role");
    }
    AdminPermissionManagement permissions = AdminPermissions.management(session, realm);
    if (!permissions.roles().isPermissionsEnabled(role)) {
        return new ManagementPermissionReference();
    }
    return RoleByIdResource.toMgmtRef(role, permissions);
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) 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) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 65 with NoCache

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

the class RoleContainerResource method deleteRole.

/**
 * Delete a role by name
 *
 * @param roleName role's name (not id!)
 */
@Path("{role-name}")
@DELETE
@NoCache
public void deleteRole(@PathParam("role-name") final String roleName) {
    auth.roles().requireManage(roleContainer);
    RoleModel role = roleContainer.getRole(roleName);
    if (role == null) {
        throw new NotFoundException("Could not find role");
    } else if (realm.getDefaultRole().getId().equals(role.getId())) {
        throw new ErrorResponseException(ErrorResponse.error(roleName + " is default role of the realm and cannot be removed.", Response.Status.BAD_REQUEST));
    }
    deleteRole(role);
    if (role.isClientRole()) {
        adminEvent.resource(ResourceType.CLIENT_ROLE);
    } else {
        adminEvent.resource(ResourceType.REALM_ROLE);
    }
    adminEvent.operation(OperationType.DELETE).resourcePath(uriInfo).success();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) RoleModel(org.keycloak.models.RoleModel) ErrorResponseException(org.keycloak.services.ErrorResponseException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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