是的,我见过类似的问题,但没有一个答案真正让我找到了解决方案。我没有在任何地方使用线程,并且相同的代码在另一个 jhipster 应用程序中工作,所以我很难过为什么这个提升+移位会导致休眠问题。
public UserDetailsContextMapper userDetailsContextMapper() {
return new UserDetailsContextMapper() {
@Override
public UserDetails mapUserFromContext(
DirContextOperations ctx, String username,
Collection<? extends GrantedAuthority> authorities) {
log.error("2 " + username + " -> " + ctx.toString());
String lowercaseLogonName = username.toLowerCase();
Optional<User> userFromDatabase = userRepository.findOneByLogin(lowercaseLogonName);
if (!userFromDatabase.isPresent()) {
User ldapUser = new User();
ldapUser.setLogin(lowercaseLogonName);
ldapUser.setPassword(RandomStringUtils.random(60)); // We use LDAP password, but the password need to be set
ldapUser.setActivated(true);
try {
Attribute attribute = ctx.getAttributes().get("mail");
ldapUser.setEmail( attribute != null && attribute.size() > 0 ? (String) attribute.get(0) : "");
attribute = ctx.getAttributes().get("givenname");
ldapUser.setFirstName(attribute != null && attribute.size() > 0 ? (String) attribute.get(0) : "");
attribute = ctx.getAttributes().get("sn");
ldapUser.setLastName(attribute != null && attribute.size() > 0 ? (String) attribute.get(0) : "");
} catch (NamingException e) {
log.warn("Couldn't get LDAP details for user: " + lowercaseLogonName);
}
}
编辑 - 这解决了我的问题:
Optional<Authority> optAuthority = authorityRepository.findById(AuthoritiesConstants.USER);
Authority authority = optAuthority.get();
慕桂英546537
12345678_0001
随时随地看视频慕课网APP
相关分类