Skip to content
Snippets Groups Projects
Commit 999deb54 authored by Patryk Kazimierowski's avatar Patryk Kazimierowski
Browse files

added new methods

parent f66f29a1
No related branches found
No related tags found
2 merge requests!131Develop,!128Resolve "Add modal to linkink account"
......@@ -9,5 +9,7 @@ public interface OidcUserService {
User checkUser(OidcUser oidcUser);
User register(OidcUser user, Domain globalDomain);
User registerNewUser(OidcUser oidcUser);
boolean externalUserRequiredLinking(OidcUser oidcUser);
User linkUser(String email, String samlToken, String firstName, String lastName);
}
......@@ -71,15 +71,6 @@ public class OidcUserServiceImpl implements OidcUserService {
+ oidcUserPreferredUsername
+ " does not match internal user ");
}
} else if (existUserByEmail) {
if (allowedLinkingUsersByEmail) {
return linkUser(oidcUserEmail, oidcUserSub);
} else {
throw new ExternalUserCanNotBeLinked("External user "
+ oidcUserPreferredUsername
+ " cannot be linked to an internal user ");
}
} else {
return registerNewUser(oidcUser);
}
......@@ -122,10 +113,32 @@ public class OidcUserServiceImpl implements OidcUserService {
return newUser;
}
private User linkUser(String email, String samlToken) {
@Override
public boolean externalUserRequiredLinking(OidcUser oidcUser) {
String oidcUserSub = oidcUser.getAttribute("sub");
String oidcUserEmail = oidcUser.getAttribute("email");
String oidcUserPreferredUsername = oidcUser.getAttribute("preferred_username");
boolean existUserBySamlToken = userService
.existsBySamlToken(oidcUserSub);
boolean existUserByUsernameAsSamlToken = userService
.existsBySamlToken(oidcUserPreferredUsername);
boolean existUserByEmail = userService
.existsByEmail(oidcUserEmail);
if(existUserBySamlToken || existUserByUsernameAsSamlToken) {
return false;
}else return existUserByEmail;
}
@Override
public User linkUser(String email, String samlToken, String firstName, String lastName) {
User user = userService.findByEmail(email);
user.setSamlToken(samlToken);
user.setFirstname(firstName);
user.setLastname(lastName);
userService.update(user);
return user;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment