Skip to content

Commit

Permalink
SHIBUI-1994
Browse files Browse the repository at this point in the history
Fix for new users
  • Loading branch information
chasegawa committed Jul 14, 2021
1 parent 2ef26b2 commit e7f10d1
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;

import java.io.IOException;
import java.util.List;
import java.util.Optional;
Expand All @@ -55,12 +57,18 @@ public AddNewUserFilter(Pac4jConfigurationProperties pac4jConfigurationPropertie
saml2ProfileMapping = this.pac4jConfigurationProperties.getSaml2ProfileMapping();
}

@Transactional
private User buildAndPersistNewUserFromProfile(CommonProfile profile) {
Role noRole = roleRepository.findByName(ROLE_NONE).orElse(new Role(ROLE_NONE));
roleRepository.save(noRole);
Optional<Role> noRole = roleRepository.findByName(ROLE_NONE);
Role newUserRole;
if (noRole.isEmpty()) {
newUserRole = new Role(ROLE_NONE);
newUserRole = roleRepository.save(newUserRole);
}
newUserRole = noRole.get();

User user = new User();
user.getRoles().add(noRole);
user.getRoles().add(newUserRole);
user.setUsername(getAttributeFromProfile(profile, "username"));
user.setPassword(BCrypt.hashpw(RandomStringUtils.randomAlphanumeric(20), BCrypt.gensalt()));
user.setFirstName(getAttributeFromProfile(profile, "firstName"));
Expand Down

0 comments on commit e7f10d1

Please sign in to comment.