@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;
}
}