在使用SpringSecurity作登陸受權時,出現了這樣的異常:java.lang.IllegalStateException: This object has not been built
java
/** * 登陸驗證 * * @param username 用戶名 * @param password 密碼 * @param code 驗證碼 * @param uuid 惟一標識 * @return 結果 */ public String login(String username, String password, String code, String uuid) { String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; String captcha = redisCache.getCacheObject(verifyKey); redisCache.deleteObject(verifyKey); if (captcha == null) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); throw new CaptchaExpireException(); } if (!code.equalsIgnoreCase(captcha)) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); throw new CaptchaException(); } // 用戶驗證 Authentication authentication = null; try { // 該方法會去調用UserDetailsServiceImpl.loadUserByUsername /* authentication = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken(username, password)); */ UsernamePasswordAuthenticationToken authenObj = new UsernamePasswordAuthenticationToken(username, password); authentication = authenticationManager .authenticate(authenObj); } catch (Exception e) { if (e instanceof BadCredentialsException) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); throw new UserPasswordNotMatchException(); } else { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); throw new CustomException(e.getMessage()); } } AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); LoginUser loginUser = (LoginUser) authentication.getPrincipal(); // 生成token return tokenService.createToken(loginUser); }
異常調試:
redis
目前該bug還在調試中...ui