use of org.craftercms.profile.api.Profile 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());
}
use of org.craftercms.profile.api.Profile in project engine by craftercms.
the class ConfigAwareUrlAccessRestrictionCheckingProcessorTest method testProcessRequest.
@Test(expected = AccessDeniedException.class)
public void testProcessRequest() throws Exception {
RequestContext requestContext = RequestContext.getCurrent();
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
SecurityUtils.setAuthentication(requestContext.getRequest(), new DefaultAuthentication(ObjectId.get().toString(), new Profile()));
processor.processRequest(requestContext, chain);
}
use of org.craftercms.profile.api.Profile in project engine by craftercms.
the class PreviewCurrentAuthenticationResolvingProcessor method processRequest.
@Override
@SuppressWarnings("unchecked")
public void processRequest(RequestContext context, RequestSecurityProcessorChain processorChain) throws Exception {
HttpServletRequest request = context.getRequest();
Map<String, String> attributes = (Map<String, String>) request.getSession(true).getAttribute(ProfileRestController.PROFILE_SESSION_ATTRIBUTE);
if (MapUtils.isNotEmpty(attributes)) {
if (logger.isDebugEnabled()) {
logger.debug("Non-anonymous persona set: " + attributes);
}
Profile profile = new Profile();
profile.setUsername("preview");
profile.setEnabled(true);
profile.setCreatedOn(new Date());
profile.setLastModified(new Date());
profile.setTenant("preview");
String rolesStr = attributes.get("roles");
if (rolesStr != null) {
String[] roles = rolesStr.split(",");
profile.getRoles().addAll(Arrays.asList(roles));
}
Map<String, Object> attributesNoUsernameNoRoles = new HashMap<String, Object>(attributes);
attributesNoUsernameNoRoles.remove("username");
attributesNoUsernameNoRoles.remove("roles");
profile.setAttributes(attributesNoUsernameNoRoles);
SecurityUtils.setAuthentication(request, new PersonaAuthentication(profile));
processorChain.processRequest(context);
} else {
if (logger.isDebugEnabled()) {
logger.debug("No persona set. Trying to resolve authentication normally");
}
super.processRequest(context, processorChain);
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class CurrentAuthenticationResolvingProcessorTest method testGetAuthentication.
@Test
public void testGetAuthentication() 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()));
request.setCookies(ticketCookie, profileLastModifiedCookie);
Profile profile = new Profile();
profile.setLastModified(profileLastModified);
Authentication auth = new DefaultAuthentication(TICKET, profile);
when(authenticationManager.getAuthentication(TICKET, false)).thenReturn(auth);
processor.processRequest(context, chain);
verify(chain).processRequest(context);
Authentication newAuth = SecurityUtils.getAuthentication(request);
assertNotNull(newAuth);
assertEquals(auth.getTicket(), newAuth.getTicket());
assertEquals(auth.getProfile().getLastModified(), newAuth.getProfile().getLastModified());
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class LogoutProcessorTest method testLogout.
@Test
public void testLogout() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(LogoutProcessor.DEFAULT_LOGOUT_METHOD, LogoutProcessor.DEFAULT_LOGOUT_URL);
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
Profile profile = new Profile();
profile.setUsername(USERNAME);
Authentication auth = new DefaultAuthentication(new ObjectId().toString(), profile);
SecurityUtils.setAuthentication(request, auth);
processor.processRequest(context, chain);
verify(chain, never()).processRequest(context);
assertNull(SecurityUtils.getAuthentication(request));
verify(logoutSuccessHandler).handle(context);
}
Aggregations