added right-management to the rights of the first user.
This commit is contained in:
parent
c57c2ff19d
commit
47aab96dfa
2 changed files with 25 additions and 8 deletions
|
|
@ -7,6 +7,7 @@ import org.springframework.security.oauth2.core.oidc.OidcIdToken;
|
||||||
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
|
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
|
||||||
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
|
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -26,13 +27,27 @@ public class LccOidcUser extends DefaultOidcUser {
|
||||||
public static User createDatabaseUser(String email, String firstName, String lastName, String workdayId, boolean isFirstUser) {
|
public static User createDatabaseUser(String email, String firstName, String lastName, String workdayId, boolean isFirstUser) {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
|
||||||
Group group = new Group();
|
var groups = new ArrayList<Group>();
|
||||||
group.setName(isFirstUser ? "service" : "none");
|
|
||||||
|
if(isFirstUser) {
|
||||||
|
var g = new Group();
|
||||||
|
g.setName("service");
|
||||||
|
groups.add(g);
|
||||||
|
|
||||||
|
g = new Group();
|
||||||
|
g.setName("right-management");
|
||||||
|
groups.add(g);
|
||||||
|
} else {
|
||||||
|
var g = new Group();
|
||||||
|
g.setName("none");
|
||||||
|
groups.add(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
user.setEmail(email);
|
user.setEmail(email);
|
||||||
user.setFirstName(firstName == null ? "" : firstName);
|
user.setFirstName(firstName == null ? "" : firstName);
|
||||||
user.setLastName(lastName == null ? "" : lastName);
|
user.setLastName(lastName == null ? "" : lastName);
|
||||||
user.setGroups(List.of(group));
|
user.setGroups(groups);
|
||||||
user.setWorkdayId(workdayId == null ? "" : workdayId);
|
user.setWorkdayId(workdayId == null ? "" : workdayId);
|
||||||
user.setActive(false);
|
user.setActive(false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -292,21 +292,23 @@ public class SecurityConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
user.getGroups().forEach(g -> log.debug("Local group: {}", g.getName()));
|
|
||||||
user.getGroups().forEach(group -> mappedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + group.getName().toUpperCase())));
|
|
||||||
userId = user.getId();
|
userId = user.getId();
|
||||||
} else {
|
} else {
|
||||||
if (email != null && firstName != null && lastName != null && (ignoreWorkdayClaim || workdayId != null)) {
|
if (email != null && firstName != null && lastName != null && (ignoreWorkdayClaim || workdayId != null)) {
|
||||||
var isFirstUser = userRepository.count() == 0;
|
var isFirstUser = userRepository.count() == 0;
|
||||||
userId = userRepository.update(LccOidcUser.createDatabaseUser(email, firstName, lastName, ignoreWorkdayClaim ? generateRandomWorkdayId() : workdayId, isFirstUser));
|
user = LccOidcUser.createDatabaseUser(email, firstName, lastName, ignoreWorkdayClaim ? generateRandomWorkdayId() : workdayId, isFirstUser);
|
||||||
mappedAuthorities.add(new SimpleGrantedAuthority(isFirstUser ? "ROLE_SERVICE" : "ROLE_NONE"));
|
userId = userRepository.update(user);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.debug("Unable to create user {} / {}", email, workdayId);
|
log.debug("Unable to create user {} / {}", email, workdayId);
|
||||||
mappedAuthorities.add(new SimpleGrantedAuthority("ROLE_NONE"));
|
mappedAuthorities.add(new SimpleGrantedAuthority("ROLE_NONE"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user != null) {
|
||||||
|
user.getGroups().forEach(g -> log.debug("Local group: {}", g.getName()));
|
||||||
|
user.getGroups().forEach(group -> mappedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + group.getName().toUpperCase())));
|
||||||
|
}
|
||||||
|
|
||||||
return new LccOidcUser(
|
return new LccOidcUser(
|
||||||
mappedAuthorities,
|
mappedAuthorities,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue