Search in sources :

Example 96 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class SecurityExceptionProcessorTest method testAccessDeniedWithAuthentication.

@Test
public void testAccessDeniedWithAuthentication() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response, null);
    RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
    doThrow(AccessDeniedException.class).when(chain).processRequest(context);
    SecurityUtils.setAuthentication(request, new DefaultAuthentication(new ObjectId().toString(), new Profile()));
    processor.processRequest(context, chain);
    verify(chain).processRequest(context);
    verify(accessDeniedHandler).handle(eq(context), any(AccessDeniedException.class));
}
Also used : DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) AccessDeniedException(org.craftercms.security.exception.AccessDeniedException) RequestSecurityProcessorChain(org.craftercms.security.processors.RequestSecurityProcessorChain) ObjectId(org.bson.types.ObjectId) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RequestContext(org.craftercms.commons.http.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 97 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImpl method getProfileByQuery.

@Override
public Profile getProfileByQuery(String tenantName, String query, String... attributesToReturn) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    Tenant tenant = getTenant(tenantName);
    try {
        Profile profile = profileRepository.findOneByQuery(getFinalQuery(tenant, query), attributesToReturn);
        filterNonReadableAttributes(tenant, profile);
        return profile;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILE_BY_QUERY_ERROR, e, query);
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 98 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImpl method getProfilesByIds.

@Override
public List<Profile> getProfilesByIds(List<String> profileIds, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws ProfileException {
    try {
        List<Profile> profiles = IterableUtils.toList(profileRepository.findByIds(profileIds, sortBy, sortOrder, attributesToReturn));
        if (profiles != null) {
            for (Profile profile : profiles) {
                checkIfManageProfilesIsAllowed(profile.getTenant());
                filterNonReadableAttributes(profile);
            }
        }
        return profiles;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILES_ERROR, e, profileIds);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 99 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImpl method addRoles.

@Override
public Profile addRoles(String profileId, final Collection<String> roles, String... attributesToReturn) throws ProfileException {
    Profile profile = updateProfile(profileId, profileUpdater -> profileUpdater.addRoles(roles), attributesToReturn);
    logger.debug(LOG_KEY_PROFILE_ROLES_ADDED, roles, profileId);
    return profile;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 100 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImpl method deleteProfile.

@Override
public void deleteProfile(String profileId) throws ProfileException {
    try {
        Profile profile = getProfile(profileId);
        if (profile != null) {
            profileRepository.removeById(profileId);
        }
        logger.debug(LOG_KEY_PROFILE_DELETED, profileId);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_DELETE_PROFILE_ERROR, e, profileId);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Aggregations

Profile (org.craftercms.profile.api.Profile)111 Test (org.junit.Test)54 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)19 MongoDataException (org.craftercms.commons.mongo.MongoDataException)15 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)15 LinkedHashMap (java.util.LinkedHashMap)13 VerificationToken (org.craftercms.profile.api.VerificationToken)13 DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)12 Date (java.util.Date)11 Map (java.util.Map)11 ObjectId (org.bson.types.ObjectId)10 RequestContext (org.craftercms.commons.http.RequestContext)9 Authentication (org.craftercms.security.authentication.Authentication)9 ArgumentMatcher (org.mockito.ArgumentMatcher)9 Mockito.anyString (org.mockito.Mockito.anyString)9 RequestSecurityProcessorChain (org.craftercms.security.processors.RequestSecurityProcessorChain)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 Tenant (org.craftercms.profile.api.Tenant)6 HashMap (java.util.HashMap)4