Search in sources :

Example 91 with Profile

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

the class ProfileServiceImplTest method getTenant1ProfileNoAttributes.

private Profile getTenant1ProfileNoAttributes() {
    Profile profile = getTenant1Profile();
    profile.getAttributes().clear();
    return profile;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 92 with Profile

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

the class VerificationServiceImplTest method testSendEmail.

@Test
public void testSendEmail() throws Exception {
    Profile profile = new Profile();
    profile.setId(PROFILE_ID);
    profile.setEmail(PROFILE_EMAIL);
    VerificationToken token = new VerificationToken();
    token.setId(TOKEN_ID);
    verificationService.sendEmail(token, profile, VERIFICATION_BASE_URL, FROM, SUBJECT, TEMPLATE_NAME);
    verify(emailFactory).getEmail(FROM, TO, null, null, SUBJECT, TEMPLATE_NAME, VERIFICATION_TEMPLATE_ARGS, true);
    verify(email).send();
}
Also used : VerificationToken(org.craftercms.profile.api.VerificationToken) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 93 with Profile

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

the class VerificationServiceImplTest method testCreateToken.

@Test
public void testCreateToken() throws Exception {
    Profile profile = new Profile();
    profile.setId(PROFILE_ID);
    profile.setTenant(TENANT_NAME);
    VerificationToken token = verificationService.createToken(profile);
    assertEquals(TOKEN_ID, token.getId());
    assertEquals(TENANT_NAME, token.getTenant());
    assertEquals(PROFILE_ID.toString(), token.getProfileId());
    assertNotNull(token.getTimestamp());
    verify(tokenRepository).insert(any(VerificationToken.class));
}
Also used : VerificationToken(org.craftercms.profile.api.VerificationToken) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 94 with Profile

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

the class AddSecurityCookiesProcessorTest method testAddCookiesLoggedIn.

@Test
public void testAddCookiesLoggedIn() throws Exception {
    String ticket = new ObjectId().toString();
    Date lastModified = new Date();
    Profile profile = new Profile();
    profile.setLastModified(lastModified);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response, null);
    RequestSecurityProcessor flushResponseProcessor = new RequestSecurityProcessor() {

        @Override
        public void processRequest(RequestContext context, RequestSecurityProcessorChain processorChain) throws Exception {
            context.getResponse().getOutputStream().flush();
        }
    };
    RequestSecurityProcessorChain chain = new RequestSecurityProcessorChainImpl(Arrays.asList(processor, flushResponseProcessor).iterator());
    Authentication auth = new DefaultAuthentication(ticket, profile);
    SecurityUtils.setAuthentication(request, auth);
    processor.processRequest(context, chain);
    Cookie ticketCookie = response.getCookie(SecurityUtils.TICKET_COOKIE_NAME);
    assertNotNull(ticketCookie);
    assertEquals(ticket, ticketCookie.getValue());
    Cookie profileLastModifiedCookie = response.getCookie(SecurityUtils.PROFILE_LAST_MODIFIED_COOKIE_NAME);
    assertNotNull(profileLastModifiedCookie);
    assertEquals(profile.getLastModified().getTime(), Long.parseLong(profileLastModifiedCookie.getValue()));
}
Also used : Cookie(javax.servlet.http.Cookie) RequestSecurityProcessorChain(org.craftercms.security.processors.RequestSecurityProcessorChain) ObjectId(org.bson.types.ObjectId) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Date(java.util.Date) Profile(org.craftercms.profile.api.Profile) DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) Authentication(org.craftercms.security.authentication.Authentication) DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) RequestSecurityProcessor(org.craftercms.security.processors.RequestSecurityProcessor) RequestContext(org.craftercms.commons.http.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 95 with Profile

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

the class LoginProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    DefaultTenantsResolver resolver = new DefaultTenantsResolver();
    resolver.setDefaultTenantNames(TENANTS);
    processor = new LoginProcessor();
    processor.setTenantsResolver(resolver);
    processor.setAuthenticationManager(authenticationManager);
    processor.setLoginSuccessHandler(loginSuccessHandler);
    processor.setLoginFailureHandler(loginFailureHandler);
    processor.setRememberMeManager(rememberMeManager);
    Profile profile = new Profile();
    profile.setUsername(USERNAME);
    when(authenticationManager.authenticateUser(TENANTS, USERNAME, VALID_PASSWORD)).thenReturn(new DefaultAuthentication(TICKET, profile));
    doThrow(BadCredentialsException.class).when(authenticationManager).authenticateUser(TENANTS, USERNAME, INVALID_PASSWORD);
}
Also used : DefaultTenantsResolver(org.craftercms.security.utils.tenant.DefaultTenantsResolver) DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) Profile(org.craftercms.profile.api.Profile) Before(org.junit.Before)

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