KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > params > valves > CasAuthValveImpl


1 package org.jahia.params.valves;
2
3 import java.io.IOException JavaDoc;
4 import java.net.MalformedURLException JavaDoc;
5 import java.net.URL JavaDoc;
6
7 import javax.xml.parsers.ParserConfigurationException JavaDoc;
8
9 import org.jahia.exceptions.JahiaInitializationException;
10 import org.jahia.exceptions.JahiaException;
11 import org.jahia.params.ParamBean;
12 import org.jahia.pipelines.valves.SsoValve;
13 import org.jahia.services.sso.CasService;
14 import org.xml.sax.SAXException JavaDoc;
15
16 import edu.yale.its.tp.cas.client.CASAuthenticationException;
17
18 /**
19  * <p>Title: CAS valve</p>
20  * <p>Description: authenticate users with a CAS server.</p>
21  * <p>Copyright: Copyright (c) 2005 - Pascal Aubry</p>
22  * <p>Company: University of Rennes 1</p>
23  * @author Pascal Aubry
24  * @version 1.0
25  */

26
27 public class CasAuthValveImpl extends SsoValve {
28
29     
30     /** constructor. */
31     public CasAuthValveImpl () {
32         // nothing to do here
33
}
34     
35     /**
36      * @see org.jahia.pipelines.valves.Valve#initialize()
37      */

38     public void initialize() {
39         // nothing to do here
40
}
41
42     /**
43      * @throws IOException
44      * @throws SAXException
45      * @throws ParserConfigurationException
46      * @throws CASAuthenticationException
47      * @throws org.jahia.exceptions.JahiaException
48      * @throws java.net.MalformedURLException
49      * @see org.jahia.pipelines.valves.SsoValve#validateCredentials(java.lang.Object, org.jahia.params.ParamBean)
50      */

51     public String JavaDoc validateCredentials(Object JavaDoc credentials, ParamBean paramBean)
52         throws JahiaException {
53         try {
54             return CasService.getInstance().validateTicket((String JavaDoc) credentials, paramBean);
55         } catch (Exception JavaDoc e) {
56             throw new JahiaException("Cannot validate CAS credentials", "Cannot validate CAS credentials", JahiaException.SECURITY_ERROR, JahiaException.WARNING_SEVERITY,e);
57         }
58     }
59
60
61     /**
62      * @see org.jahia.pipelines.valves.SsoValve#retrieveCredentials(org.jahia.params.ParamBean)
63      */

64     public Object JavaDoc retrieveCredentials(ParamBean paramBean) throws Exception JavaDoc {
65         String JavaDoc ticket = paramBean.getRequest().getParameter("ticket");
66         if (ticket == null) {
67             return null;
68         }
69         if (ticket.equals("")) {
70             return null;
71         }
72         return ticket;
73     }
74
75     /**
76      * @throws JahiaInitializationException
77      * @throws MalformedURLException
78      * @see org.jahia.pipelines.valves.SsoValve#getRedirectUrl()
79      */

80     public String JavaDoc getRedirectUrl(ParamBean paramBean) throws JahiaException {
81         try {
82             CasService casService = CasService.getInstance();
83             /* return casService.getServerLoginUrl() + "?service=" + casService.getJahiaServiceUrl(); */
84             int pid;
85             pid = paramBean.getPageID();
86             URL JavaDoc url = new URL JavaDoc(paramBean.getSiteURL());
87             int port = url.getPort();
88             String JavaDoc redirectUrl;
89             if (port == -1) {
90                 redirectUrl = "http://" + url.getHost() ;
91             }
92             else {
93                 redirectUrl = "http://" + url.getHost()+ ":" + port;
94             }
95             return casService.getServerLoginUrl() + "?service=" + redirectUrl + paramBean.composePageUrl(pid,null);
96         } catch (MalformedURLException JavaDoc e) {
97             throw new JahiaException("Cannot generate URL", "Cannot generate URL", JahiaException.PARAMETER_ERROR, JahiaException.ERROR_SEVERITY,e);
98         }
99     }
100 }
101
Popular Tags