Search in sources :

Example 31 with Profile

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

the class MellonAutoLoginProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Profile profile = getProfile();
    when(tenantService.getTenant(TENANT_NAME)).thenReturn(getTenant());
    when(profileService.createProfile(TENANT_NAME, USERNAME, null, EMAIL, true, null, getAttributes(), null)).thenReturn(profile);
    when(tenantsResolver.getTenants()).thenReturn(new String[] { TENANT_NAME });
    when(authenticationManager.authenticateUser(profile)).thenReturn(new DefaultAuthentication(TICKET, profile));
    processor = new MellonAutoLoginProcessor();
    processor.setTenantService(tenantService);
    processor.setProfileService(profileService);
    processor.setTenantsResolver(tenantsResolver);
    processor.setAuthenticationManager(authenticationManager);
}
Also used : DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) Profile(org.craftercms.profile.api.Profile) Before(org.junit.Before)

Example 32 with Profile

use of org.craftercms.profile.api.Profile 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)

Example 33 with Profile

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

the class ProfileControllerTest method getProfile.

private Profile getProfile(String tenantName, ObjectId id, String username, String role) {
    Profile profile = new Profile();
    profile.setId(id);
    profile.setTenant(tenantName);
    profile.setUsername(username);
    profile.getRoles().add(role);
    return profile;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 34 with Profile

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

the class ProfileControllerTest method testUpdateProfile.

@Test
public void testUpdateProfile() throws Exception {
    Profile currentUser = getProfile(TENANT_NAME1, PROFILE_ID1, USERNAME1, PROFILE_ADMIN_ROLE);
    setCurrentUser(currentUser);
    Map<String, String> model = controller.updateProfile(currentUser);
    assertNotNull(model);
    assertEquals(1, model.size());
    assertEquals(String.format(MSG_PROFILE_UPDATED_FORMAT, PROFILE_ID1.toString()), model.get(MODEL_MESSAGE));
    verify(profileService).updateProfile(PROFILE_ID1.toString(), USERNAME1, null, null, false, SetUtils.asSet(PROFILE_ADMIN_ROLE), new HashMap<String, Object>(), ProfileConstants.NO_ATTRIBUTE);
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 35 with Profile

use of org.craftercms.profile.api.Profile 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();
}
Also used : CurrentUserSubjectResolver(org.craftercms.profile.management.security.permissions.CurrentUserSubjectResolver) Tenant(org.craftercms.profile.api.Tenant) TenantPermissionResolver(org.craftercms.profile.management.security.permissions.TenantPermissionResolver) PermissionEvaluatorImpl(org.craftercms.commons.security.permissions.impl.PermissionEvaluatorImpl) Profile(org.craftercms.profile.api.Profile) Before(org.junit.Before)

Aggregations

Profile (org.craftercms.profile.api.Profile)110 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 Authentication (org.craftercms.security.authentication.Authentication)11 Date (java.util.Date)10 Map (java.util.Map)10 ObjectId (org.bson.types.ObjectId)9 RequestContext (org.craftercms.commons.http.RequestContext)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)5 Ticket (org.craftercms.profile.api.Ticket)4