浏览 8536 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-01-18
public TUser getUser() { //取得登录用户 SecurityContext ctx = SecurityContextHolder.getContext(); Authentication auth = ctx.getAuthentication(); if(auth.getPrincipal() instanceof UserDetails) { user = (TUser)auth.getPrincipal(); //log.debug("\nauth.getPrincipal()==============\n"+user.getUserid()); } return user; } java.lang.NullPointerException com.firedragon.struts.base.action.BaseDispatchAction.getUser(BaseDispatchAction.java:125) 可是从DEBUG的信息来看 [2007-01-17 23:51:32]DEBUG org.springframework.web.context.support.XmlWebApplicationContext(line:215) -Publishing event in context [Root WebApplicationContext]: org.acegisecurity.event.authentication.AuthenticationSuccessEvent[source=org.acegisecurity.providers.UsernamePasswordAuthenticationToken@aaf3d2: Username: com.firedragon.hibernate.model.TUser@ba2b6b[用户名:=admin, enabled:=true, accountExpired:=true, credentialsExpired:=true, accountLocked:=true,受权角色: ,ROLE_11]; Password: [PROTECTED]; Authenticated: true; Details: org.acegisecurity.ui.WebAuthenticationDetails@16d8a64: RemoteIpAddress: 127.0.0.1; SessionId: 8AECD601C138A1E87458F770333028E8; Granted Authorities: ROLE_11] [2007-01-17 23:51:32]WARN org.acegisecurity.event.authentication.LoggerListener(line:60) -Authentication event AuthenticationSuccessEvent: admin; details: org.acegisecurity.ui.WebAuthenticationDetails@16d8a64: RemoteIpAddress: 127.0.0.1; SessionId: 8AECD601C138A1E87458F770333028E8 [2007-01-17 23:51:32]DEBUG org.acegisecurity.ui.AbstractProcessingFilter(line:392) -Authentication success: org.acegisecurity.providers.UsernamePasswordAuthenticationToken@aaf3d2: Username: com.firedragon.hibernate.model.TUser@ba2b6b[用户名:=admin, enabled:=true, accountExpired:=true, credentialsExpired:=true, accountLocked:=true,受权角色: ,ROLE_11]; Password: [PROTECTED]; Authenticated: true; Details: org.acegisecurity.ui.WebAuthenticationDetails@16d8a64: RemoteIpAddress: 127.0.0.1; SessionId: 8AECD601C138A1E87458F770333028E8; Granted Authorities: ROLE_11 [2007-01-17 23:51:32]DEBUG org.acegisecurity.ui.AbstractProcessingFilter(line:398) -Updated SecurityContextHolder to contain the following Authentication: 'org.acegisecurity.providers.UsernamePasswordAuthenticationToken@aaf3d2: Username: com.firedragon.hibernate.model.TUser@ba2b6b[用户名:=admin, enabled:=true, accountExpired:=true, credentialsExpired:=true, accountLocked:=true,受权角色: ,ROLE_11]; Password: [PROTECTED]; Authenticated: true; Details: org.acegisecurity.ui.WebAuthenticationDetails@16d8a64: RemoteIpAddress: 127.0.0.1; SessionId: 8AECD601C138A1E87458F770333028E8; Granted Authorities: ROLE_11' [2007-01-17 23:51:32]DEBUG org.acegisecurity.ui.AbstractProcessingFilter(line:416) -Redirecting to target URL from HTTP Session (or default): /News/main.html [2007-01-17 23:51:32]DEBUG org.springframework.web.context.support.XmlWebApplicationContext(line:215) -Publishing event in context [Root WebApplicationContext]: org.acegisecurity.event.authentication.InteractiveAuthenticationSuccessEvent[source=org.acegisecurity.providers.UsernamePasswordAuthenticationToken@aaf3d2: Username: com.firedragon.hibernate.model.TUser@ba2b6b[用户名:=admin, enabled:=true, accountExpired:=true, credentialsExpired:=true, accountLocked:=true,受权角色: ,ROLE_11]; Password: [PROTECTED]; Authenticated: true; Details: org.acegisecurity.ui.WebAuthenticationDetails@16d8a64: RemoteIpAddress: 127.0.0.1; SessionId: 8AECD601C138A1E87458F770333028E8; Granted Authorities: ROLE_11] [2007-01-17 23:51:32]WARN org.acegisecurity.event.authentication.LoggerListener(line:60) -Authentication event InteractiveAuthenticationSuccessEvent: admin; details: org.acegisecurity.ui.WebAuthenticationDetails@16d8a64: RemoteIpAddress: 127.0.0.1; SessionId: 8AECD601C138A1E87458F770333028E8 [2007-01-17 23:51:32]DEBUG org.acegisecurity.context.HttpSessionContextIntegrationFilter(line:276)[color=red]--------SecurityContext stored to HttpSession------[/color]: 'org.acegisecurity.context.SecurityContextImpl@aaf3d2: Authentication: org.acegisecurity.providers.UsernamePasswordAuthenticationToken@aaf3d2: Username: com.firedragon.hibernate.model.TUser@ba2b6b[用户名:=admin, enabled:=true, accountExpired:=true, credentialsExpired:=true, accountLocked:=true,受权角色: ,ROLE_11]; Password: [PROTECTED]; Authenticated: true; Details: org.acegisecurity.ui.WebAuthenticationDetails@16d8a64: RemoteIpAddress: 127.0.0.1; SessionId: 8AECD601C138A1E87458F770333028E8; Granted Authorities: ROLE_11' [2007-01-17 23:51:32]DEBUG org.acegisecurity.context.HttpSessionContextIntegrationFilter(line:285) [color=red]-------SecurityContextHolder set to new context-----[/color], as request processing completed -------SecurityContext stored to HttpSession------ ------SecurityContextHolder set to new context---- 上面这里应该把用户信息放到session里去了,请教什么地方出来问题可能导致取不到值? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-01-20
问题的解决办法
|
|
返回顶楼 | |
发表时间:2007-01-28
(User) ctx.getAuthentication().getPrincipal();
|
|
返回顶楼 | |
发表时间:2007-01-29
我不是很了解,能把配置文件贴出来?然后把你的认证的代码也贴出来
|
|
返回顶楼 | |
发表时间:2007-04-03
大哥这个问题也困扰了我一天,不过今天解决啦
大家都挺难的 http://wiki.springside.org.cn/display/springside/Chapter+2.+Technical+Overview 你现看看这个文章 HttpSessionContextIntegrationFilter在HTTP之间存储SecurityContext 加上HttpSessionContextIntegrationFilter这个就行啦,在Filter链条上 |
|
返回顶楼 | |