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));
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations