有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在使用RememberMeCheck登录之前,如何使用spring security更新grails中用户的详细信息?

我使用的是grails,授权由Spring Security完成。我需要在登录前解锁用户帐户

@Transactional(readOnly=true, noRollbackFor=[IllegalArgumentException, UsernameNotFoundException])

UserDetails loadUserByUsername(字符串用户名)引发UsernameNotFoundException{

  User user = User.findByUsername(username)
  // Check and unlock account if 24 Hrs has been passed
  userService.checkAndUnlockAccountAfter24Hrs(user.id);
  if (!user) throw new NoStackUsernameNotFoundException()

  def roles = user.authorities

  // or if you are using role groups:
  // def roles = user.authorities.collect { it.authorities }.flatten().unique()

  def authorities = roles.collect {
     new SimpleGrantedAuthority(it.authority)
  }

  return new MyUserDetails(user.username, user.password, user.enabled,
        !user.accountExpired, !user.passwordExpired,
        !user.accountLocked, authorities ?: NO_ROLES, user.id,
        user.name)

}

现在,当我使用“记住我”复选框登录时,它会显示错误:

- 

    | Error 2017-04-18 12:24:40,426 [http-bio-8080-exec-3] ERROR
       [/].[default]  - Servlet.service() for servlet [default] in context
       with path [] threw exception
           Message: retrieveUser returned null - a violation of the interface contract
               Line | Method
           ->>   76 | attemptAuthentication in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
           - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
           |     49 | doFilter              in     ''
           |     82 | doFilter . . . . . .  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
           |    100 | doFilter              in com.brandseye.cors.CorsFilter
           |   1145 | runWorker . . . . . . in java.util.concurrent.ThreadPoolExecutor
           |    615 | run                   in java.util.concurrent.ThreadPoolExecutor$Worker
           ^    744 | run . . . . . . . . . in java.lang.Thread

共 (0) 个答案