protected Profile findProfile(String profileId) { try { return profileService.getProfile(profileId); } catch (ProfileException e) { throw new SocialMediaIntegrationException("Unable to find profile '" + profileId + "'", e); } }
protected List<Profile> findProfilesByQuery(String tenant, String query) { try { return profileService.getProfilesByQuery(tenant, query, null, null, null, null, ProfileConstants.NO_ATTRIBUTE); } catch (ProfileException e) { throw new SocialMediaIntegrationException("Unable to find profiles of tenant '" + tenant + "' by " + "query " + query, e); } }
protected Profile createProfileWithSsoInfo(String username, Tenant tenant, HttpServletRequest request) throws ProfileException { Map<String, Object> attributes = null; List<AttributeDefinition> attributeDefinitions = tenant.getAttributeDefinitions(); String email = request.getHeader(emailHeaderName); for (AttributeDefinition attributeDefinition : attributeDefinitions) { String attributeName = attributeDefinition.getName(); String attributeValue = request.getHeader(mellonHeaderPrefix + attributeName); if (StringUtils.isNotEmpty(attributeValue)) { if (attributes == null) { attributes = new HashMap<>(); } attributes.put(attributeName, attributeValue); } } logger.info("Creating new profile with SSO info: username={}, email={}, tenant={}, attributes={}", username, email, tenant.getName(), attributes); return profileService.createProfile(tenant.getName(), username, null, email, true, null, attributes, null); }
protected void updateProfile() { try { profile = profileService.updateAttributes(profile.getId().toString(), profile.getAttributes()); } catch (ProfileException e) { throw new SocialMediaIntegrationException("Unable to update profile of user '" + profile.getId() + "'", e); } }
protected Profile getProfile(String tenant, Profile userData) { try { return profileService.getProfileByUsername(tenant, userData.getUsername()); } catch (ProfileException e) { throw new AuthenticationException("Unable to retrieve current profile for user '" + userData.getUsername() + "' of tenant '" + tenant + "'", e); } }
protected Profile loadProfile(String ticketId) throws AuthenticationException { try { Profile profile = profileService.getProfileByTicket(ticketId); if (profile != null) { logger.debug("Profile '{}' retrieved for ticket '{}'", profile.getId(), ticketId); return profile; } else { throw new AuthenticationSystemException("No profile found for ticket '" + ticketId + "'"); } } catch (ProfileRestServiceException e) { if (e.getErrorCode() == ErrorCode.NO_SUCH_TICKET) { logger.debug("Ticket '{}' is invalid", ticketId); return null; } else { throw new AuthenticationSystemException("An unexpected error occurred while attempting to retrieve " + "profile for ticket '" + ticketId + "'", e); } } catch (ProfileException e) { throw new AuthenticationSystemException("An unexpected error occurred while attempting to retrieve " + "profile for ticket '" + ticketId + "'", e); } }
protected void updateProfile() { try { profile = profileService.updateAttributes(profile.getId().toString(), profile.getAttributes()); } catch (ProfileException e) { throw new SocialMediaIntegrationException("Unable to update profile of user '" + profile.getId() + "'", e); } }
@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); }
protected Profile findProfile(String profileId) { try { return profileService.getProfile(profileId); } catch (ProfileException e) { throw new SocialMediaIntegrationException("Unable to find profile '" + profileId + "'", e); } }
protected Profile updateProfileConnectionData(String tenant, Connection<?> connection, Profile profile) { try { ConnectionUtils.addConnectionData(profile, connection.createData(), textEncryptor); return profileService.updateAttributes(profile.getId().toString(), profile.getAttributes()); } catch (CryptoException | ProfileException e) { throw new AuthenticationException("Unable to update connection data of user '" + profile.getUsername() + "' of tenant '" + tenant + "'", e); } }
protected List<Profile> findProfilesByQuery(String tenant, String query) { try { return profileService.getProfilesByQuery(tenant, query, null, null, null, null, ProfileConstants.NO_ATTRIBUTE); } catch (ProfileException e) { throw new SocialMediaIntegrationException("Unable to find profiles of tenant '" + tenant + "' by " + "query " + query, e); } }
protected Profile createProfile(String tenant, Connection<?> connection, Profile userData) { try { ConnectionUtils.addConnectionData(userData, connection.createData(), textEncryptor); return profileService.createProfile(tenant, userData.getUsername(), null, userData.getEmail(), true, userData.getRoles(), userData.getAttributes(), null); } catch (CryptoException | ProfileException e) { throw new AuthenticationException("Unable to create profile of user '" + userData.getUsername() + "' in tenant '" + tenant + "'", e); } }
protected Authentication authenticate(String profileId) throws AuthenticationException { Profile profile; try { profile = profileService.getProfile(profileId); } catch (ProfileException e) { throw new AuthenticationSystemException("Error retrieving profile '" + profileId + "'", e); } if (profile != null) { return authenticationManager.authenticateUser(profile, true); } else { throw new AuthenticationSystemException("No profile found for ID '" + profileId + "'"); } }
@Override public Authentication authenticateUser(String tenant, String username, String password) { try { Ticket ticket = authenticationService.authenticate(tenant, username, password); Profile profile = profileService.getProfile(ticket.getProfileId()); if (profile == null) { throw new AuthenticationSystemException("No profile found for ID '" + ticket.getProfileId() + "'"); } String ticketId = ticket.getId(); DefaultAuthentication auth = new DefaultAuthentication(ticketId, profile); authenticationCache.putAuthentication(auth); logger.debug("Authentication successful for user '{}' (ticket ID = '{}')", ticket.getProfileId(), ticketId); return auth; } catch (ProfileRestServiceException e) { switch (e.getErrorCode()) { case DISABLED_PROFILE: throw new DisabledUserException("User is disabled", e); case BAD_CREDENTIALS: throw new BadCredentialsException("Invalid username and/or password", e); default: throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e); } } catch (ProfileException e) { throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e); } }