我的 Grails 应用程序进行了一个非常简单的调用来查找登录用户的详细信息。基本上是这样的:
select id, username, password, firstname, lastname from Person where id=3;
有时会得到结果,有时不会。我一直在分析正在发送的sql,这对我来说没有意义。一个请求会找到 Person,而后续请求则不会。下面的日志跟踪线程 ID、会话 ID 和登录用户。我知道让人们查看我的 sql 查询日志并不是一件好事,但我希望我已经设法在下面说明我所看到的。
2701 [INFO] 2012-12-03 02:19:02,136 audit [T-82] [23212190391C07976A2CC568F06A780A] [cb18b110954f4476b80c2@stratus5.com] 3.
Connection.prepareStatement(select person0_.id as id4_0_, person0_.version as version4_0_,
person0_.account_expired as account3_4_0_, person0_.account_locked as account4_4_0_,
person0_.created_date as created5_4_0_, person0_.email_hash as email6_4_0_, person0_.enabled as enabled4_0_, person0_.first_name as first8_4_0_,
person0_.last_name as last9_4_0_, person0_.`password` as password10_4_0_, person0_.password_expired as password11_4_0_, person0_.tmp_password as tmp12_4_0_,
person0_.username as username4_0_ from person person0_ where person0_.id=?)
2702 [INFO] 2012-12-03 02:19:02,137 audit [T-82] [23212190391C07976A2CC568F06A780A]
[cb18b110954f4476b80c2@stratus5.com] 3. PreparedStatement.setLong(1, 1160)
2749 [DEBUG] 2012-12-03 02:19:02,278 SignUpApiController [T-82]
[23212190391C07976A2CC568F06A780A] [cb18b110954f4476b80c2@stratus5.com]
user: com.stratus5.auth.Person : 1160
280 [INFO] 2012-12-03 02:15:32,143 audit [T-160] [23212190391C07976A2CC568F06A780A] [cb18b110954f4476b80c2@stratus5.com] 5. Connection.prepareStatement(select person0_.id as id4_0_, person0_.version as version4_0_,
person0_.account_expired as account3_4_0_,
person0_.account_locked as account4_4_0_,
person0_.created_date as created5_4_0_, person0_.email_hash as email6_4_0_,
person0_.enabled as enabled4_0_, person0_.first_name as first8_4_0_,
person0_.last_name as last9_4_0_, person0_.`password` as password10_4_0_,
person0_.password_expired as password11_4_0_, person0_.tmp_password as tmp12_4_0_,
person0_.username as username4_0_ from person person0_
where person0_.id=?)
281 [INFO] 2012-12-03 02:15:32,143 audit [T-160] [23212190391C07976A2CC568F06A780A]
[cb18b110954f4476b80c2@stratus5.com] 5. PreparedStatement.setLong(1, 1160)
313 [DEBUG] 2012-12-03 02:15:32,939 SignUpApiController [T-160]
[23212190391C07976A2CC568F06A780A] [cb18b110954f4476b80c2@stratus5.com]
Current user: null
以下是一些代码摘录,以防它们有帮助:
def principalId = new Long(springSecurityService.getPrincipal().id)
def p = Person.get(principalId)
log.debug "Current user: $p"
我一直在使用 springSecurityService.currentUser 并且看到了同样的错误。我只是根据问题可能出在 springSecurityService 中的假设来故意调用 Person.get,但现在看起来不太可能。