1 package org.jahia.params.valves; 2 3 import java.io.IOException ; 4 import java.net.MalformedURLException ; 5 import java.net.URL ; 6 7 import javax.xml.parsers.ParserConfigurationException ; 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 ; 15 16 import edu.yale.its.tp.cas.client.CASAuthenticationException; 17 18 26 27 public class CasAuthValveImpl extends SsoValve { 28 29 30 31 public CasAuthValveImpl () { 32 } 34 35 38 public void initialize() { 39 } 41 42 51 public String validateCredentials(Object credentials, ParamBean paramBean) 52 throws JahiaException { 53 try { 54 return CasService.getInstance().validateTicket((String ) credentials, paramBean); 55 } catch (Exception 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 64 public Object retrieveCredentials(ParamBean paramBean) throws Exception { 65 String 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 80 public String getRedirectUrl(ParamBean paramBean) throws JahiaException { 81 try { 82 CasService casService = CasService.getInstance(); 83 84 int pid; 85 pid = paramBean.getPageID(); 86 URL url = new URL (paramBean.getSiteURL()); 87 int port = url.getPort(); 88 String 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 e) { 97 throw new JahiaException("Cannot generate URL", "Cannot generate URL", JahiaException.PARAMETER_ERROR, JahiaException.ERROR_SEVERITY,e); 98 } 99 } 100 } 101 | Popular Tags |