cas认证不拦截指定的URL

最近在搞CAS总是在不断的改进,每当往前迈进一步都会发现新问题。文采有限直接进入正题。

重写AuthenticationFilter类

 

/**过滤不拦截URL如果是多个用;隔开**/

public class AuthenticationFilter extends AbstractCasFilter {
     .............
     /**过滤不拦截URL如果是多个用;隔开**/
     private String excludes = null;
     private final String exclude_splitter = ";";
     ............
     
     protected void initInternal(final FilterConfig filterConfig) throws ServletException {
         .........
         setExcludes(getPropertyFromInitParams(filterConfig,"excludes",null));
         ..........
     }
     
     public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,final FilterChain filterChain) throws IOException, ServletException {
         //增加过滤
         if(exclude(request)){
             filterChain.doFilter(request, response);
             return;
        }
     }
     
     
    private boolean exclude(final HttpServletRequest request){
    	String serviceUrl = request.getRequestURI();
    	if(excludes == null || serviceUrl == null) return false;
    	if(excludes.contains(exclude_splitter)) {
    		return excludeCore(serviceUrl);
    	} else {
    		return serviceUrl.contains(excludes);
    	}
    }
    
    private boolean excludeCore(String serviceUrl){
    	String all_excludes[] = excludes.split(exclude_splitter);
    	for(String exclude : all_excludes){
    		if(serviceUrl.contains(exclude)){
    			return true;
    		}
    	}
    	return false;
    }
     
     ...........
     public String getExcludes() {
	return excludes;
     }

     public void setExcludes(String excludes) {
	this.excludes = excludes;
    }     
}

上面是代码中实现,下面在web.xml中增加需要过来的文件即可。

 <init-param>
      <param-name>excludes</param-name>
      param-value>/tools/;/VerificationCodeServlet</param-value>
 </init-param>

如果多URL用“;”隔开。这样就可以实现url不通过cas认证。

客户端3.3.3完全不通过上面实现,只需要在web.xml文件直接配置即可。配置如下:

 <init-param>
      <param-name>ignorePattern</param-name>
      <param-value>/tools/|/VerificationCodeServlet</param-value>
 </init-param>

如果多个URL用“|”隔开。

感兴趣可以加QQ群:10043620一起学习一起进步

转载于:https://my.oschina.net/95408719/blog/664396

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值