Search in sources :

Example 1 with DefaultAuthentication

use of org.craftercms.security.authentication.impl.DefaultAuthentication 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 2 with DefaultAuthentication

use of org.craftercms.security.authentication.impl.DefaultAuthentication in project profile by craftercms.

the class TenantControllerTest method setCurrentUser.

private void setCurrentUser(Profile profile) {
    DefaultAuthentication auth = new DefaultAuthentication(null, profile);
    SecurityUtils.setCurrentAuthentication(auth);
}
Also used : DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication)

Example 3 with DefaultAuthentication

use of org.craftercms.security.authentication.impl.DefaultAuthentication in project profile by craftercms.

the class CurrentAuthenticationResolvingProcessorTest method testGetAuthenticationProfileLastModifiedChanged.

@Test
public void testGetAuthenticationProfileLastModifiedChanged() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response, null);
    RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
    Date profileLastModified = new Date();
    Cookie ticketCookie = new Cookie(SecurityUtils.TICKET_COOKIE_NAME, TICKET);
    Cookie profileLastModifiedCookie = new Cookie(SecurityUtils.PROFILE_LAST_MODIFIED_COOKIE_NAME, String.valueOf(profileLastModified.getTime() + 60000));
    request.setCookies(ticketCookie, profileLastModifiedCookie);
    Profile profile = new Profile();
    profile.setLastModified(profileLastModified);
    Profile modifiedProfile = new Profile();
    modifiedProfile.setLastModified(new Date(profileLastModified.getTime() + 60000));
    Authentication auth = new DefaultAuthentication(TICKET, profile);
    Authentication modifiedAuth = new DefaultAuthentication(TICKET, modifiedProfile);
    when(authenticationManager.getAuthentication(TICKET, false)).thenReturn(auth);
    when(authenticationManager.getAuthentication(TICKET, true)).thenReturn(modifiedAuth);
    processor.processRequest(context, chain);
    verify(chain).processRequest(context);
    Authentication newAuth = SecurityUtils.getAuthentication(request);
    assertNotNull(newAuth);
    assertEquals(modifiedAuth.getTicket(), newAuth.getTicket());
    assertEquals(modifiedAuth.getProfile().getLastModified(), newAuth.getProfile().getLastModified());
}
Also used : Cookie(javax.servlet.http.Cookie) DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) RequestSecurityProcessorChain(org.craftercms.security.processors.RequestSecurityProcessorChain) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Authentication(org.craftercms.security.authentication.Authentication) DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) RequestContext(org.craftercms.commons.http.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 4 with DefaultAuthentication

use of org.craftercms.security.authentication.impl.DefaultAuthentication in project profile by craftercms.

the class UrlAccessRestrictionCheckingProcessorTest method testUnAllowedAccess.

@Test(expected = AccessDeniedException.class)
public void testUnAllowedAccess() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", URL);
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response, null);
    RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
    SecurityUtils.setAuthentication(request, new DefaultAuthentication(new ObjectId().toString(), new Profile()));
    processor.processRequest(context, chain);
}
Also used : DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) RequestSecurityProcessorChain(org.craftercms.security.processors.RequestSecurityProcessorChain) ObjectId(org.bson.types.ObjectId) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RequestContext(org.craftercms.commons.http.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 5 with DefaultAuthentication

use of org.craftercms.security.authentication.impl.DefaultAuthentication in project engine by craftercms.

the class ConfigAwareLoginSuccessHandlerTest method testProcessRequest.

@Test
public void testProcessRequest() throws Exception {
    handler.handle(RequestContext.getCurrent(), new DefaultAuthentication(null, new Profile()));
    assertEquals(config.getString(LOGIN_DEFAULT_SUCCESS_URL_KEY), ((MockHttpServletResponse) RequestContext.getCurrent().getResponse()).getRedirectedUrl());
}
Also used : DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Aggregations

DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)14 Profile (org.craftercms.profile.api.Profile)12 Test (org.junit.Test)9 RequestContext (org.craftercms.commons.http.RequestContext)8 RequestSecurityProcessorChain (org.craftercms.security.processors.RequestSecurityProcessorChain)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 ObjectId (org.bson.types.ObjectId)5 Authentication (org.craftercms.security.authentication.Authentication)5 Date (java.util.Date)3 Cookie (javax.servlet.http.Cookie)3 Before (org.junit.Before)2 AfterReturning (org.aspectj.lang.annotation.AfterReturning)1 AccessDeniedException (org.craftercms.security.exception.AccessDeniedException)1 RequestSecurityProcessor (org.craftercms.security.processors.RequestSecurityProcessor)1 DefaultTenantsResolver (org.craftercms.security.utils.tenant.DefaultTenantsResolver)1