Search in sources :

Example 1 with ResourceNotFoundException

use of org.craftercms.profile.management.exceptions.ResourceNotFoundException in project profile by craftercms.

the class TenantController method getTenant.

@RequestMapping(value = URL_GET_TENANT, method = RequestMethod.GET)
@ResponseBody
public Tenant getTenant(@PathVariable(PATH_VAR_NAME) String name) throws ProfileException {
    checkIfAllowed(name, Action.GET_TENANT);
    Tenant tenant = tenantService.getTenant(name);
    if (tenant != null) {
        return tenant;
    } else {
        throw new ResourceNotFoundException("No tenant found with name '" + name + "'");
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) ResourceNotFoundException(org.craftercms.profile.management.exceptions.ResourceNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with ResourceNotFoundException

use of org.craftercms.profile.management.exceptions.ResourceNotFoundException in project profile by craftercms.

the class TenantController method updateTenant.

@RequestMapping(value = URL_UPDATE_TENANT, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateTenant(@RequestBody Tenant tenant) throws ProfileException {
    String name = tenant.getName();
    checkIfAllowed(name, Action.UPDATE_TENANT);
    Tenant currentTenant = tenantService.getTenant(name);
    if (currentTenant != null) {
        if (!currentTenant.getAvailableRoles().contains(AuthorizationUtils.SUPERADMIN_ROLE) && tenant.getAvailableRoles().contains(AuthorizationUtils.SUPERADMIN_ROLE)) {
            throw new ActionDeniedException(Action.UPDATE_TENANT.toString(), name);
        }
        if (currentTenant.getAvailableRoles().contains(AuthorizationUtils.SUPERADMIN_ROLE) && !tenant.getAvailableRoles().contains(AuthorizationUtils.SUPERADMIN_ROLE)) {
            throw new ActionDeniedException(Action.UPDATE_TENANT.toString(), name);
        }
        tenantService.updateTenant(tenant);
        return Collections.singletonMap(MODEL_MESSAGE, String.format(MSG_TENANT_UPDATED_FORMAT, name));
    } else {
        throw new ResourceNotFoundException("No tenant found with name '" + name + "'");
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) ActionDeniedException(org.craftercms.commons.security.exception.ActionDeniedException) ResourceNotFoundException(org.craftercms.profile.management.exceptions.ResourceNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with ResourceNotFoundException

use of org.craftercms.profile.management.exceptions.ResourceNotFoundException in project profile by craftercms.

the class TenantController method deleteTenant.

@RequestMapping(value = URL_DELETE_TENANT, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> deleteTenant(@PathVariable(PATH_VAR_NAME) String name) throws ProfileException {
    checkIfAllowed(name, Action.DELETE_TENANT);
    Tenant tenant = tenantService.getTenant(name);
    if (tenant != null) {
        tenantService.deleteTenant(name);
        return Collections.singletonMap(MODEL_MESSAGE, String.format(MSG_TENANT_DELETED_FORMAT, name));
    } else {
        throw new ResourceNotFoundException("No tenant found with name '" + name + "'");
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) ResourceNotFoundException(org.craftercms.profile.management.exceptions.ResourceNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ResourceNotFoundException

use of org.craftercms.profile.management.exceptions.ResourceNotFoundException in project profile by craftercms.

the class AccessTokenController method getAccessToken.

@RequestMapping(value = URL_GET_ACCESS_TOKEN, method = RequestMethod.GET)
@ResponseBody
public AccessToken getAccessToken(@PathVariable(PATH_VAR_ID) String id) throws ProfileException {
    checkIfAllowed(id, Action.GET_PROFILE);
    AccessToken token = accessTokenService.getToken(id);
    if (token != null) {
        return token;
    } else {
        throw new ResourceNotFoundException("No access token found with ID '" + id + "'");
    }
}
Also used : AccessToken(org.craftercms.profile.api.AccessToken) ResourceNotFoundException(org.craftercms.profile.management.exceptions.ResourceNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with ResourceNotFoundException

use of org.craftercms.profile.management.exceptions.ResourceNotFoundException in project profile by craftercms.

the class ProfileController method updateProfile.

@RequestMapping(value = URL_UPDATE_PROFILE, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateProfile(@RequestBody Profile profile) throws ProfileException {
    String id = profile.getId().toString();
    Profile currentProfile = profileService.getProfile(id);
    if (currentProfile != null) {
        checkIfAllowed(currentProfile, Action.UPDATE_PROFILE);
        profileService.updateProfile(id, profile.getUsername(), profile.getPassword(), profile.getEmail(), profile.isEnabled(), profile.getRoles(), profile.getAttributes(), ProfileConstants.NO_ATTRIBUTE);
        return Collections.singletonMap(MODEL_MESSAGE, String.format(MSG_PROFILE_UPDATED_FORMAT, id));
    } else {
        throw new ResourceNotFoundException("No profile found for ID '" + id + "'");
    }
}
Also used : ResourceNotFoundException(org.craftercms.profile.management.exceptions.ResourceNotFoundException) Profile(org.craftercms.profile.api.Profile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResourceNotFoundException (org.craftercms.profile.management.exceptions.ResourceNotFoundException)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Tenant (org.craftercms.profile.api.Tenant)3 Profile (org.craftercms.profile.api.Profile)2 ActionDeniedException (org.craftercms.commons.security.exception.ActionDeniedException)1 AccessToken (org.craftercms.profile.api.AccessToken)1