use of org.craftercms.profile.api.Profile 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);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class AuthenticationServiceImplTest method getProfile2.
private Profile getProfile2() {
Profile profile = new Profile();
profile.setId(PROFILE2_ID);
profile.setUsername(USERNAME2);
profile.setPassword(CryptoUtils.hashPassword(PASSWORD));
profile.setEnabled(false);
profile.setTenant(TENANT_NAME);
return profile;
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class AuthenticationServiceImplTest method getProfile1.
private Profile getProfile1() {
Profile profile = new Profile();
profile.setId(PROFILE1_ID);
profile.setUsername(USERNAME1);
profile.setPassword(CryptoUtils.hashPassword(PASSWORD));
profile.setEnabled(true);
profile.setTenant(TENANT_NAME);
return profile;
}
use of org.craftercms.profile.api.Profile in project engine by craftercms.
the class ProfileHeadersAuthenticationFilter method doGetPreAuthenticatedPrincipal.
@Override
protected Object doGetPreAuthenticatedPrincipal(final HttpServletRequest request) {
String username = request.getHeader(getUsernameHeaderName());
String email = request.getHeader(getEmailHeaderName());
if (isNoneEmpty(username, email)) {
try {
String[] tenantNames = tenantsResolver.getTenants();
Tenant tenant = getSsoEnabledTenant(tenantNames);
if (tenant != null) {
Profile profile = profileService.getProfileByUsername(tenant.getName(), username);
if (profile == null) {
profile = createProfileWithSsoInfo(username, tenant, request);
}
return new ProfileUser(profile);
} else {
logger.warn("A SSO login was attempted, but none of the tenants [{}] is enabled for SSO", (Object) tenantNames);
}
} catch (ProfileException e) {
logger.error("Error processing headers authentication for '{}'", username, e);
}
}
return null;
}
use of org.craftercms.profile.api.Profile in project engine by craftercms.
the class TargetingPreAuthenticatedFilter method getPreAuthenticatedPrincipal.
@Override
@SuppressWarnings("unchecked")
protected Object getPreAuthenticatedPrincipal(final HttpServletRequest request) {
HttpSession session = request.getSession();
if (session != null) {
Map<String, String> attributes = (Map<String, String>) session.getAttribute(ProfileRestController.PROFILE_SESSION_ATTRIBUTE);
if (isNotEmpty(attributes)) {
if (logger.isDebugEnabled()) {
logger.debug("Non-anonymous persona set: " + attributes);
}
Profile profile = new Profile();
profile.setId(new ObjectId(attributes.get("id")));
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> customAttributes = new HashMap<>(attributes);
customAttributes.remove("id");
customAttributes.remove("username");
customAttributes.remove("roles");
profile.setAttributes(customAttributes);
return new TargetingUser(new TargetingAuthentication(profile));
}
}
if (logger.isDebugEnabled()) {
logger.debug("No persona set. Trying to resolve authentication normally");
}
return null;
}
Aggregations