use of org.craftercms.security.authentication.impl.DefaultAuthentication in project profile by craftercms.
the class ProfileControllerTest method setCurrentUser.
private void setCurrentUser(Profile profile) {
DefaultAuthentication auth = new DefaultAuthentication(null, profile);
SecurityUtils.setCurrentAuthentication(auth);
}
use of org.craftercms.security.authentication.impl.DefaultAuthentication 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()));
}
use of org.craftercms.security.authentication.impl.DefaultAuthentication 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);
}
use of org.craftercms.security.authentication.impl.DefaultAuthentication in project profile by craftercms.
the class SecurityExceptionProcessorTest method testAccessDeniedWithAuthentication.
@Test
public void testAccessDeniedWithAuthentication() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
doThrow(AccessDeniedException.class).when(chain).processRequest(context);
SecurityUtils.setAuthentication(request, new DefaultAuthentication(new ObjectId().toString(), new Profile()));
processor.processRequest(context, chain);
verify(chain).processRequest(context);
verify(accessDeniedHandler).handle(eq(context), any(AccessDeniedException.class));
}
Aggregations