use of org.craftercms.profile.management.security.permissions.CurrentUserSubjectResolver 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();
}
use of org.craftercms.profile.management.security.permissions.CurrentUserSubjectResolver in project profile by craftercms.
the class TenantControllerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Tenant tenant1 = getTenant(TENANT_ID1, TENANT_NAME1, SUPERADMIN_ROLE, TENANT_ADMIN_ROLE, PROFILE_ADMIN_ROLE);
Tenant tenant2 = getTenant(TENANT_ID2, TENANT_NAME2, TENANT_ADMIN_ROLE, PROFILE_ADMIN_ROLE);
Tenant tenant3 = getTenant(TENANT_ID3, TENANT_NAME3, PROFILE_ADMIN_ROLE);
when(tenantService.getAllTenants()).thenReturn(Arrays.asList(tenant1, tenant2));
when(tenantService.getTenant(TENANT_NAME1)).thenReturn(tenant1);
when(tenantService.getTenant(TENANT_NAME2)).thenReturn(tenant2);
when(tenantService.createTenant(tenant3)).thenReturn(tenant3);
SubjectResolver<Profile> subjectResolver = new CurrentUserSubjectResolver();
TenantPermissionResolver permissionResolver = new TenantPermissionResolver();
PermissionEvaluatorImpl<Profile, String> permissionEvaluator = new PermissionEvaluatorImpl<>();
permissionEvaluator.setSubjectResolver(subjectResolver);
permissionEvaluator.setPermissionResolver(permissionResolver);
controller = new TenantController();
controller.setTenantService(tenantService);
controller.setTenantPermissionEvaluator(permissionEvaluator);
setCurrentRequestContext();
}
Aggregations