@Override public Set<String> findUserIdsConnectedTo(String providerId, Set<String> providerUserIds) { String providerUserIdsStr = StringUtils.join(providerUserIds, ", "); String query = String.format(FIND_PROFILES_BY_PROVIDER_ID_AND_USER_ID_QUERY, providerId, providerUserIdsStr); List<Profile> profiles = findProfilesByQuery(query); if (CollectionUtils.isNotEmpty(profiles)) { Set<String> ids = new LinkedHashSet<>(profiles.size()); for (Profile profile : profiles) { ids.add(profile.getId().toString()); } return ids; } else { return Collections.emptySet(); } }
@Override public Set<String> findUserIdsConnectedTo(String providerId, Set<String> providerUserIds) { String providerUserIdsStr = StringUtils.join(providerUserIds, ", "); String query = String.format(FIND_PROFILES_BY_PROVIDER_ID_AND_USER_ID_QUERY, providerId, providerUserIdsStr); List<Profile> profiles = findProfilesByQuery(query); if (CollectionUtils.isNotEmpty(profiles)) { Set<String> ids = new LinkedHashSet<>(profiles.size()); for (Profile profile : profiles) { ids.add(profile.getId().toString()); } return ids; } else { return Collections.emptySet(); } }
@Override public List<String> findUserIdsWithConnection(Connection<?> connection) { String providerId = connection.getKey().getProviderId(); String providerUserId = connection.getKey().getProviderUserId(); String query = String.format(FIND_PROFILES_BY_PROVIDER_ID_AND_USER_ID_QUERY, providerId, providerUserId); List<Profile> profiles = findProfilesByQuery(query); if (CollectionUtils.isNotEmpty(profiles)) { List<String> ids = new ArrayList<>(profiles.size()); for (Profile profile : profiles) { ids.add(profile.getId().toString()); } return ids; } else { return Collections.emptyList(); } }
@Override public List<String> findUserIdsWithConnection(Connection<?> connection) { String providerId = connection.getKey().getProviderId(); String providerUserId = connection.getKey().getProviderUserId(); String query = String.format(FIND_PROFILES_BY_PROVIDER_ID_AND_USER_ID_QUERY, providerId, providerUserId); List<Profile> profiles = findProfilesByQuery(query); if (CollectionUtils.isNotEmpty(profiles)) { List<String> ids = new ArrayList<>(profiles.size()); for (Profile profile : profiles) { ids.add(profile.getId().toString()); } return ids; } else { return Collections.emptyList(); } }
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); } }
@Override public void enableRememberMe(Authentication authentication, RequestContext context) throws RememberMeException { String profileId = authentication.getProfile().getId().toString(); PersistentLogin login; try { login = authenticationService.createPersistentLogin(profileId); } catch (ProfileException e) { throw new RememberMeException("Error creating persistent login for profile '" + profileId + "'", e); } logger.debug("Persistent login created: {}", login); addRememberMeCookie(serializeLogin(login), context.getResponse()); }
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); } }
@Override public Authentication authenticateUser(Profile profile, boolean remembered) throws AuthenticationException { try { Ticket ticket = authenticationService.createTicket(profile.getId().toString()); String ticketId = ticket.getId(); DefaultAuthentication auth = new DefaultAuthentication(ticketId, profile, remembered); authenticationCache.putAuthentication(auth); logger.debug("Authentication successful for user '{}' (ticket ID = '{}')", ticket.getProfileId(), ticketId); return auth; } catch (ProfileRestServiceException e) { if (e.getErrorCode() == ErrorCode.DISABLED_PROFILE) { throw new DisabledUserException("User is disabled", e); } else { throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e); } } catch (ProfileException e) { throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e); } }