单点登录cas与权限管理框架shiro集成------普通web项目方式 (二)

2014-11-24 07:17:23 · 作者: · 浏览: 8
"username");
String uid = attributes.get("uid");
//对获取到的信息进行再处理
}
}
chain.doFilter(request, response);
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {

PrincipalCollection principalCollection = SecurityUtils.getSubject()
.getPrincipals();

if (principalCollection != null) {
List principals = principalCollection.asList();
// 这里获取到的list有两个元素,
//一个是cas返回来的用户名,举例是aaa,
//一个是cas返回的更多属性的map对象,举例是{uid:aaa,username:aaa,email:aaa}
//通过principals.get(1)来获得属性集合的map对象
Map attributes = (Map) principals.get(1);
if (principals != null) {
String email = attributes.get("email");
String username = attributes.get("username");
String uid = attributes.get("uid");
//对获取到的信息进行再处理
}
}
chain.doFilter(request, response);
}
获取到信息就可以把它设置到session或怎样由你定。
摘自laigood12345的专栏