use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceIT method testEnableProfile.
@Test
public void testEnableProfile() throws Exception {
Profile profile = profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1, AVASQUEZ_EMAIL1, false, AVASQUEZ_ROLES1, null, VERIFICATION_URL);
try {
assertNotNull(profile);
assertFalse(profile.isEnabled());
Profile updatedProfile = profileService.enableProfile(profile.getId().toString());
assertNotNull(updatedProfile);
assertEquals(profile.getId(), updatedProfile.getId());
assertEquals(profile.getUsername(), updatedProfile.getUsername());
assertNull(updatedProfile.getPassword());
assertEquals(profile.getEmail(), updatedProfile.getEmail());
assertEquals(profile.isVerified(), updatedProfile.isVerified());
assertTrue(updatedProfile.isEnabled());
assertEquals(profile.getCreatedOn(), updatedProfile.getCreatedOn());
assertTrue(profile.getLastModified().before(updatedProfile.getLastModified()));
assertEquals(profile.getTenant(), updatedProfile.getTenant());
assertEquals(profile.getRoles(), updatedProfile.getRoles());
assertEquals(profile.getAttributes(), updatedProfile.getAttributes());
} finally {
profileService.deleteProfile(profile.getId().toString());
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class MellonAutoLoginProcessor method processRequest.
@Override
public void processRequest(RequestContext context, RequestSecurityProcessorChain processorChain) throws Exception {
HttpServletRequest request = context.getRequest();
String username = request.getHeader(usernameHeaderName);
Authentication auth = SecurityUtils.getAuthentication(request);
if (StringUtils.isNotEmpty(username) && (auth == null || !auth.getProfile().getUsername().equals(username))) {
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);
}
SecurityUtils.setAuthentication(request, authenticationManager.authenticateUser(profile));
} else {
logger.warn("An SSO login was attempted, but none of the tenants [{}] is enabled for SSO", tenantNames);
}
}
processorChain.processRequest(context);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class RefreshCurrentAuthenticationOnProfileUpdateAspect method refreshCurrentAuthentication.
@AfterReturning(value = "execution(* org.craftercms.profile.api.services.ProfileService.updateProfile(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.verifyProfile(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.enableProfile(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.disableProfile(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.addRoles(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.removeRoles(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.updateAttributes(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.removeAttributes(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.changePassword(..))", returning = "updatedProfile")
public void refreshCurrentAuthentication(Profile updatedProfile) {
Authentication auth = SecurityUtils.getCurrentAuthentication();
if (auth != null) {
Profile profile = auth.getProfile();
if (profile.equals(updatedProfile)) {
String ticket = auth.getTicket();
auth = new DefaultAuthentication(ticket, updatedProfile);
// Put updated authentication in cache
authenticationCache.putAuthentication(auth);
// Update current authentication object
SecurityUtils.setCurrentAuthentication(auth);
}
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProviderLoginSupportImpl method complete.
@Override
public Authentication complete(String tenant, String providerId, HttpServletRequest request, Set<String> newUserRoles, Map<String, Object> newUserAttributes, ConnectSupport connectSupport) throws AuthenticationException {
if (connectSupport == null) {
connectSupport = this.connectSupport;
}
Connection<?> connection = completeConnection(connectSupport, providerId, request);
if (connection != null) {
Profile userData = ConnectionUtils.createProfile(connection);
Profile profile = getProfile(tenant, userData);
if (profile == null) {
if (CollectionUtils.isNotEmpty(newUserRoles)) {
userData.getRoles().addAll(newUserRoles);
}
if (MapUtils.isNotEmpty(newUserAttributes)) {
userData.getAttributes().putAll(newUserAttributes);
}
profile = createProfile(tenant, connection, userData);
} else {
profile = updateProfileConnectionData(tenant, connection, profile);
}
Authentication auth = authenticationManager.authenticateUser(profile);
SecurityUtils.setAuthentication(request, auth);
return auth;
} else {
return null;
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ConnectionUtils method createProfile.
/**
* Creates a profile from the specified connection.
*
* @param connection the connection where to retrieve the profile info from
*
* @return the created profile
*/
public static Profile createProfile(Connection<?> connection) {
Profile profile = new Profile();
UserProfile providerProfile = connection.fetchUserProfile();
String email = providerProfile.getEmail();
if (StringUtils.isEmpty(email)) {
throw new IllegalStateException("No email included in provider profile");
}
String username = providerProfile.getUsername();
if (StringUtils.isEmpty(username)) {
username = email;
}
String firstName = providerProfile.getFirstName();
String lastName = providerProfile.getLastName();
String displayName;
if (StringUtils.isNotEmpty(connection.getDisplayName())) {
displayName = connection.getDisplayName();
} else {
displayName = firstName + " " + lastName;
}
profile.setUsername(username);
profile.setEmail(email);
profile.setAttribute(FIRST_NAME_ATTRIBUTE_NAME, firstName);
profile.setAttribute(LAST_NAME_ATTRIBUTE_NAME, lastName);
profile.setAttribute(DISPLAY_NAME_ATTRIBUTE_NAME, displayName);
if (StringUtils.isNotEmpty(connection.getImageUrl())) {
profile.setAttribute(AVATAR_LINK_ATTRIBUTE_NAME, connection.getImageUrl());
}
return profile;
}
Aggregations