Fuguo-security-default
来自ling
目录
功能
依赖
配置文件说明
登录成功后跳转控制
- 登录成功后登录上次访问页面,上次访问页面有2种控制方式
- ling2.loginSuccessAlwaysUseDefaultTargetUrl = true
- security_check_?_last_jumping_url=xxxxxxxxx _last_jumping_url由applicationContext-security.xml 中ling2.savedRequestAwareAuthenticationSuccessHandler配置
- 由session中_last_jumping_url值决定,由ForwardRedirectStrategy负责实施,由applicationContext-security.xml 中ling2.savedRequestAwareAuthenticationSuccessHandler配置,_last_jumping_url见CookieUtils中对_last_jumping_url的定义
- session中_last_jumping_url在processErroCode写入
- 优先级如下:session中_last_jumping_url>security_check_?_last_jumping_url=xxxxxxxxx
- session中_last_jumping_url的取消在ForwardRedirectStrategy
- 登录成功后转向默认页面
- ling2.loginSuccessAlwaysUseDefaultTargetUrl = false配合ling2.loginSuccessDefaultTargetUrl = index.html
LING_USERLOGININFO_COOKIE_KEY登录用户加密信息的写入和取消
- LING_USERLOGININFO_COOKIE_KEY在CookieLoginService中由cookieName定义
- LING_USERLOGININFO_COOKIE_KEY相关实现在CookieLoginServiceImpl
- LING_USERLOGININFO_COOKIE_KEY在SecurityInterceptorAdapter,RememberMeLoginFilter,CasLoginAuthenticationFilter,FormLoginAuthenticationProvider中写入
- LING_USERLOGININFO_COOKIE_KEY在DefaultLogoutHandler中取消
- 一般使用如下
contextHolder.initUserDetail(user, holder.getRequest(), holder.getResponse());
cookieLoginTokenService.addCookie(ContextHolder.getRequest(), ContextHolder.getResponse(), authentication);
cookieLoginTokenService.cancelCookie(request, response);
sessionShareProvider.clearSid(request,response);
LING_sid用户sid的写入和更换
- LING_sid相关实现在SessionShareProvider
- LING_sid在SecurityInterceptorAdapter中写入
- LING_sid在DefaultLogoutHandler中更换
其他重要参数
- ling2.formLoginUrl = login.html
- ling2.logoutSuccessURL = /index.html
- ling2.loginFailureTargetUrl = /login.html
- ling2.username = username
- ling2.password = password
cookie/Storage中关于作用域的配置
- ling2.cookieDomain=ling2.cn
- 前端中path.js中需要有相应的配置为
var path = "http://www.ling2.cn:7071/";
var domain = "ling2.cn";
登录成功失败
cookie关键字:ContextUtils.erroKey="LING_erro";每次登录错误后被加入,登录成功后清除
如果用户名不存在,错误在DefaultUserService中抛出
一切异常的处理在ContextFilter中汇总,可以在IExceptionHandler中实现拦截,但现在有问题
其他严重异常在DefaultFrameworkService中抛出,在FormLoginAuthenticationProvider被加入cookie
菜单权限无法控制
- 资源权限判断第一步是分了company_id 见UrlMetadataSource#initUrlMetaData,请确认url表中的companyid正确
for(DefaultRole role:roleService.loadAllRoles()){
String companyId=role.getCompanyId();
Map<String,List<ConfigAttribute>> mapAttribute=metaData.get(companyId);
if(mapAttribute==null){
mapAttribute=new HashMap<String,List<ConfigAttribute>>();
metaData.put(companyId, mapAttribute);
}
}
- 菜单不在角色等控制中,默认显示了不被控制的资源
- 没有在任何角色,或菜单在角色中了,角色没用户,都会导致菜单属于无控制权限状态而被显示出来
- role没有companyid
- base_role_member isgrant=true
ConfigAttribute attribute:attributes){
SecurityConfigAttribute configAttribute=(SecurityConfigAttribute)attribute;
boolean granted=configAttribute.isGranted();
if(!configAttribute.getAttributeType().equals(AttributeType.user)){
continue;
}
关键类说明
不能登录成功
- AbstractAuthenticationProcessingFilter.doFilter user is diable 因为userdetail有isenable接口
- ling2.loginProcessUrl = /security_check_ ling2.username = username ling2.password = password 是否和登录页面匹配
- 用户名密码是否加密
关闭权限验证的主要代码
去掉资源的权限验证,能看到菜单就能访问相应页面,知道地址也能访问相应页面,对客户无影响 主要注释代码为 UrlAccessDecisionManager和ComponentMetadataSource ,UrlMetadataSource