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
如下面的代码段所示, 加入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页的配置
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。