开发者社区> 问答> 正文

在配置cas支持客户端自定义页面时报:配置报错

Exception starting filter CAS Filter java.lang.IllegalArgumentException: serverName or service must be set. 

配置时,参考网上的,先是配置web.xml,
如下:<listener> <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class> </listener> <!-- CAS --> <filter> <filter-name>CAS Single Sign Out Filter</filter-name> <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class> </filter> <filter> <filter-name>CAS Filter</filter-name> <filter-class>com.cas.client.validation.RemoteAuthenticationFilter</filter-class> <init-param> <param-name>localLoginUrl</param-name> <param-value>http://localhost:8080/casclient</param-value> </init-param> <init-param> <param-name>casServerLoginUrl</param-name> <param-value>https://localhost:8443/cas-server/remoteLogin</param-value> </init-param> <init-param> <param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name> <param-value>https://localhost:8443/cas-server/serviceValidate</param-value> </init-param> <init-param>                <param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name>               <param-value>http://localhost:8080</param-value>     </init-param>   </filter>

<filter-mapping> <filter-name>CAS Single Sign Out Filter</filter-name> <url-pattern>/</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Filter</filter-name> <url-pattern>/</url-pattern> </filter-mapping>
而后,编写com.cas.client.validation.RemoteAuthenticationFilter,其如下:
package com.cas.client.validation;

import java.io.IOException; import java.net.URL; import java.net.URLEncoder;

import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;

import org.jasig.cas.client.util.AbstractCasFilter; import org.jasig.cas.client.util.CommonUtils; import org.jasig.cas.client.validation.Assertion;

public class RemoteAuthenticationFilter extends AbstractCasFilter {          public static final String CONST_CAS_GATEWAY = "const_cas_gateway";

    /**      * 本地登陆页面URL.      /     private String localLoginUrl;          /**       The URL to the CAS Server login.      */     private String casServerLoginUrl;

    /**      * Whether to send the renew request or not.      */     private boolean renew = false;

    /**      * Whether to send the gateway request or not.      */     private boolean gateway = false;

    protected void initInternal(final FilterConfig filterConfig) throws ServletException {         super.initInternal(filterConfig);         setCasServerLoginUrl(getPropertyFromInitParams(filterConfig, "casServerLoginUrl", null));         log.trace("Loaded CasServerLoginUrl parameter: " + this.casServerLoginUrl);         setLocalLoginUrl(getPropertyFromInitParams(filterConfig, "localLoginUrl", null));         log.trace("Loaded LocalLoginUrl parameter: " + this.localLoginUrl);         setRenew(Boolean.parseBoolean(getPropertyFromInitParams(filterConfig, "renew", "false")));         log.trace("Loaded renew parameter: " + this.renew);         setGateway(Boolean.parseBoolean(getPropertyFromInitParams(filterConfig, "gateway", "false")));         log.trace("Loaded gateway parameter: " + this.gateway);     }

    public void init() {         super.init();         CommonUtils.assertNotNull(this.localLoginUrl, "localLoginUrl cannot be null.");         CommonUtils.assertNotNull(this.casServerLoginUrl, "casServerLoginUrl cannot be null.");     }

    public final void doFilter(final ServletRequest servletRequest,             final ServletResponse servletResponse, final FilterChain filterChain)             throws IOException, ServletException {         final HttpServletRequest request = (HttpServletRequest) servletRequest;         final HttpServletResponse response = (HttpServletResponse) servletResponse;         final HttpSession session = request.getSession(false);         final String ticket = request.getParameter(getArtifactParameterName());         final Assertion assertion = session != null ? (Assertion) session                 .getAttribute(CONST_CAS_ASSERTION) : null;         final boolean wasGatewayed = session != null                 && session.getAttribute(CONST_CAS_GATEWAY) != null;

        // 如果访问路径为localLoginUrl且带有validated参数则跳过         URL url = new URL(localLoginUrl);         final boolean isValidatedLocalLoginUrl = request.getRequestURI().endsWith(url.getPath()) &&             CommonUtils.isNotBlank(request.getParameter("validated"));                  if (!isValidatedLocalLoginUrl && CommonUtils.isBlank(ticket) && assertion == null && !wasGatewayed) {             log.debug("no ticket and no assertion found");             if (this.gateway) {                 log.debug("setting gateway attribute in session");                 request.getSession(true).setAttribute(CONST_CAS_GATEWAY, "yes");             }

            final String serviceUrl = constructServiceUrl(request, response);

            if (log.isDebugEnabled()) {                 log.debug("Constructed service url: " + serviceUrl);             }

            String urlToRedirectTo = CommonUtils.constructRedirectUrl(                     this.casServerLoginUrl, getServiceParameterName(),                     serviceUrl, this.renew, this.gateway);

            // 加入localLoginUrl             urlToRedirectTo += (urlToRedirectTo.contains("?") ? "&" : "?") + "loginUrl=" + URLEncoder.encode(localLoginUrl, "utf-8");

            if (log.isDebugEnabled()) {                 log.debug("redirecting to "" + urlToRedirectTo + """);             }                          response.sendRedirect(urlToRedirectTo);             return;         }

        if (session != null) {             log.debug("removing gateway attribute from session");             session.setAttribute(CONST_CAS_GATEWAY, null);         }

        filterChain.doFilter(request, response);     }

    public final void setRenew(final boolean renew) {         this.renew = renew;     }

    public final void setGateway(final boolean gateway) {         this.gateway = gateway;     }

    public final void setCasServerLoginUrl(final String casServerLoginUrl) {         this.casServerLoginUrl = casServerLoginUrl;     }

    public final void setLocalLoginUrl(String localLoginUrl) {         this.localLoginUrl = localLoginUrl;     }      } 最后编写登录页面,启动tomcat报错信息如下:
严重: Exception starting filter CAS Filter java.lang.IllegalArgumentException: serverName or service must be set. at org.jasig.cas.client.util.CommonUtils.assertTrue(CommonUtils.java:116) at org.jasig.cas.client.util.AbstractCasFilter.init(AbstractCasFilter.java:103) at com.cas.client.validation.RemoteAuthenticationFilter.init(RemoteAuthenticationFilter.java:57) at org.jasig.cas.client.util.AbstractCasFilter.init(AbstractCasFilter.java:84) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) 2014-7-17 11:15:23 org.apache.catalina.core.StandardContext startInternal 严重: Error filterStart 2014-7-17 11:15:23 org.apache.catalina.core.StandardContext startInternal 严重: Context [/casclient] startup failed due to previous errors

展开
收起
kun坤 2020-06-02 17:21:16 960 0
1 条回答
写回答
取消 提交回答
  • 如下面的代码段所示, 加入severname

    <filter>
    	<filter-name>CAS Authentication Filter</filter-name>
    	<filter-class>
    		com.baidu.cas.client.validation.RemoteAuthenticationFilter
    	</filter-class>
    	<init-param>
    		<param-name>localLoginUrl</param-name>
    		<param-value>
    			http://GUOLIN:9080/cas-client-java-custom-login/l ogin.jsp
    		</param-value>
    	</init-param>
    	<init-param>
    		<param-name>casServerLoginUrl</param-name>
    		<param-value>https://GUOLIN/cas-server/remoteLogin</param-value>
    	</init-param>
    	<init-param>
    		<param-name>serverName</param-name>
    		<param-value>http://GUOLIN:9080</param-value>
    	</init-param>
    </filter>

    也可以参考下 http://wenku.baidu.com/view/0bcc0d01e87101f69e319595.html 第17页的配置

    2020-06-02 17:21:23
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Data as a Service - 数据即服务 -- MongoDB⾼级应⽤模式 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载