1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.ui.cas;
17
18 import org.acegisecurity.AuthenticationException;
19 import org.acegisecurity.intercept.web.AuthenticationEntryPoint;
20
21 import org.springframework.beans.factory.InitializingBean;
22 import org.springframework.util.Assert;
23
24 import java.io.IOException;
25
26 import java.net.URLEncoder;
27
28 import javax.servlet.ServletException;
29 import javax.servlet.ServletRequest;
30 import javax.servlet.ServletResponse;
31 import javax.servlet.http.HttpServletResponse;
32
33
34 /***
35 * Used by the <code>SecurityEnforcementFilter</code> to commence
36 * authentication via the Yale Central Authentication Service (CAS).
37 *
38 * <P>
39 * The user's browser will be redirected to the Yale CAS enterprise-wide login
40 * page. This page is specified by the <code>loginUrl</code> property. Once
41 * login is complete, the CAS login page will redirect to the page indicated
42 * by the <code>service</code> property. The <code>service</code> is a HTTP
43 * URL belonging to the current application. The <code>service</code> URL is
44 * monitored by the {@link CasProcessingFilter}, which will validate the CAS
45 * login was successful.
46 * </p>
47 *
48 * @author Ben Alex
49 * @version $Id: CasProcessingFilterEntryPoint.java,v 1.5 2005/11/17 00:55:49 benalex Exp $
50 */
51 public class CasProcessingFilterEntryPoint implements AuthenticationEntryPoint,
52 InitializingBean {
53
54
55 private ServiceProperties serviceProperties;
56 private String loginUrl;
57
58
59
60 public void setLoginUrl(String loginUrl) {
61 this.loginUrl = loginUrl;
62 }
63
64 /***
65 * The enterprise-wide CAS login URL. Usually something like
66 * <code>https://www.mycompany.com/cas/login</code>.
67 *
68 * @return the enterprise-wide CAS login URL
69 */
70 public String getLoginUrl() {
71 return loginUrl;
72 }
73
74 public void setServiceProperties(ServiceProperties serviceProperties) {
75 this.serviceProperties = serviceProperties;
76 }
77
78 public ServiceProperties getServiceProperties() {
79 return serviceProperties;
80 }
81
82 public void afterPropertiesSet() throws Exception {
83 Assert.hasLength(loginUrl, "loginUrl must be specified");
84 Assert.notNull(serviceProperties, "serviceProperties must be specified");
85 }
86
87 public void commence(ServletRequest request, ServletResponse response,
88 AuthenticationException authenticationException)
89 throws IOException, ServletException {
90 String url;
91
92 if (serviceProperties.isSendRenew()) {
93 url = loginUrl + "?renew=true" + "&service="
94 + serviceProperties.getService();
95 } else {
96 url = loginUrl + "?service="
97 + URLEncoder.encode(serviceProperties.getService(), "UTF-8");
98 }
99
100 ((HttpServletResponse) response).sendRedirect(url);
101 }
102 }