Search in sources :

Example 1 with ProfilePermissionResolver

use of org.craftercms.profile.management.security.permissions.ProfilePermissionResolver in project profile by craftercms.

the class ProfileControllerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    String query = String.format(FINAL_QUERY_FORMAT, USERNAME1);
    Profile profile1 = getProfile(TENANT_NAME1, PROFILE_ID1, USERNAME1, PROFILE_ADMIN_ROLE);
    Profile profile2 = getProfile(TENANT_NAME1, PROFILE_ID2, USERNAME2, PROFILE_ADMIN_ROLE);
    Profile profile3 = getProfile(TENANT_NAME1, PROFILE_ID3, USERNAME3, SUPERADMIN_ROLE);
    Profile profile4 = getProfile(TENANT_NAME1, PROFILE_ID4, USERNAME4, TENANT_ADMIN_ROLE);
    when(profileService.getProfileCountByQuery(TENANT_NAME1, query)).thenReturn(1L);
    when(profileService.getProfilesByQuery(TENANT_NAME1, query, null, null, null, null, new String[0])).thenReturn(Arrays.asList(profile1));
    when(profileService.getProfile(PROFILE_ID1.toString(), new String[0])).thenReturn(profile1);
    when(profileService.getProfile(PROFILE_ID3.toString(), new String[0])).thenReturn(profile3);
    when(profileService.getProfile(PROFILE_ID4.toString(), new String[0])).thenReturn(profile4);
    when(profileService.createProfile(TENANT_NAME1, USERNAME2, null, null, false, SetUtils.asSet(PROFILE_ADMIN_ROLE), new HashMap<String, Object>(), null)).thenReturn(profile2);
    SubjectResolver<Profile> subjectResolver = new CurrentUserSubjectResolver();
    TenantPermissionResolver tenantPermissionResolver = new TenantPermissionResolver();
    ProfilePermissionResolver profilePermissionResolver = new ProfilePermissionResolver();
    PermissionEvaluatorImpl<Profile, String> tenantPermissionEvaluator = new PermissionEvaluatorImpl<>();
    tenantPermissionEvaluator.setSubjectResolver(subjectResolver);
    tenantPermissionEvaluator.setPermissionResolver(tenantPermissionResolver);
    PermissionEvaluatorImpl<Profile, Profile> profilePermissionEvaluator = new PermissionEvaluatorImpl<>();
    profilePermissionEvaluator.setSubjectResolver(subjectResolver);
    profilePermissionEvaluator.setPermissionResolver(profilePermissionResolver);
    controller = new ProfileController();
    controller.setProfileService(profileService);
    controller.setTenantPermissionEvaluator(tenantPermissionEvaluator);
    controller.setProfilePermissionEvaluator(profilePermissionEvaluator);
    setCurrentRequestContext();
}
Also used : CurrentUserSubjectResolver(org.craftercms.profile.management.security.permissions.CurrentUserSubjectResolver) TenantPermissionResolver(org.craftercms.profile.management.security.permissions.TenantPermissionResolver) ProfilePermissionResolver(org.craftercms.profile.management.security.permissions.ProfilePermissionResolver) PermissionEvaluatorImpl(org.craftercms.commons.security.permissions.impl.PermissionEvaluatorImpl) Profile(org.craftercms.profile.api.Profile) Before(org.junit.Before)

Aggregations

PermissionEvaluatorImpl (org.craftercms.commons.security.permissions.impl.PermissionEvaluatorImpl)1 Profile (org.craftercms.profile.api.Profile)1 CurrentUserSubjectResolver (org.craftercms.profile.management.security.permissions.CurrentUserSubjectResolver)1 ProfilePermissionResolver (org.craftercms.profile.management.security.permissions.ProfilePermissionResolver)1 TenantPermissionResolver (org.craftercms.profile.management.security.permissions.TenantPermissionResolver)1 Before (org.junit.Before)1