KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > security > AuthenticationModule


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.security;
25
26 import java.security.Principal JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Properties JavaDoc;
29
30 import javax.servlet.FilterChain JavaDoc;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33
34 import org.apache.log4j.Logger;
35 import org.infoglue.cms.controllers.kernel.impl.simple.UserControllerProxy;
36 import org.infoglue.cms.exception.SystemException;
37
38 /**
39  * This interface defines what a authenticationmodule has to fulfill.
40  *
41  * @author Mattias Bogeblad
42  */

43
44 public abstract class AuthenticationModule
45 {
46     private final static Logger logger = Logger.getLogger(AuthenticationModule.class.getName());
47
48     public static AuthenticationModule getAuthenticationModule(Object JavaDoc transactionObject, String JavaDoc successLoginUrl) throws SystemException
49     {
50         AuthenticationModule authenticationModule = null;
51         
52         try
53         {
54             String JavaDoc authenticatorClass = InfoGlueAuthenticationFilter.authenticatorClass;
55             String JavaDoc authorizerClass = InfoGlueAuthenticationFilter.authorizerClass;
56             String JavaDoc invalidLoginUrl = InfoGlueAuthenticationFilter.invalidLoginUrl;
57             String JavaDoc loginUrl = InfoGlueAuthenticationFilter.loginUrl;
58             String JavaDoc logoutUrl = InfoGlueAuthenticationFilter.logoutUrl;
59             String JavaDoc serverName = InfoGlueAuthenticationFilter.serverName;
60             Properties JavaDoc extraProperties = InfoGlueAuthenticationFilter.extraProperties;
61             String JavaDoc casRenew = InfoGlueAuthenticationFilter.casRenew;
62             String JavaDoc casServiceUrl = InfoGlueAuthenticationFilter.casServiceUrl;
63             String JavaDoc casValidateUrl = InfoGlueAuthenticationFilter.casValidateUrl;
64             String JavaDoc casLogoutUrl = InfoGlueAuthenticationFilter.casLogoutUrl;
65
66             /*
67             System.out.println("**********************************************");
68             System.out.println("authenticatorClass:" + authenticatorClass);
69             System.out.println("authorizerClass:" + authorizerClass);
70             System.out.println("loginUrl:" + loginUrl);
71             System.out.println("logoutUrl:" + logoutUrl);
72             System.out.println("**********************************************");
73             */

74             
75             authenticationModule = (AuthenticationModule)Class.forName(authenticatorClass).newInstance();
76             authenticationModule.setAuthenticatorClass(authenticatorClass);
77             authenticationModule.setAuthorizerClass(authorizerClass);
78             authenticationModule.setInvalidLoginUrl(invalidLoginUrl);
79             authenticationModule.setLoginUrl(loginUrl);
80             authenticationModule.setLogoutUrl(logoutUrl);
81             authenticationModule.setServerName(serverName);
82             authenticationModule.setExtraProperties(extraProperties);
83             authenticationModule.setCasRenew(casRenew);
84             
85             if(successLoginUrl != null && successLoginUrl.length() > 0)
86             {
87                 int index = successLoginUrl.indexOf("&ticket=");
88                 if(index > -1)
89                 {
90                     successLoginUrl = successLoginUrl.substring(0, index);
91                 }
92                 logger.info("successLoginUrl:" + successLoginUrl);
93                 authenticationModule.setCasServiceUrl(successLoginUrl);
94                 authenticationModule.setSuccessLoginUrl(successLoginUrl);
95             }
96             else
97                 authenticationModule.setCasServiceUrl(casServiceUrl);
98             
99             authenticationModule.setCasValidateUrl(casValidateUrl);
100             authenticationModule.setCasLogoutUrl(casLogoutUrl);
101             authenticationModule.setTransactionObject(transactionObject);
102         }
103         catch(Exception JavaDoc e)
104         {
105             logger.error("An error occurred when we tried to get an authenticationModule:" + e, e);
106             throw new SystemException("An error occurred when we tried to get an authenticationModule: " + e.getMessage(), e);
107         }
108         
109         return authenticationModule;
110     }
111     
112     public abstract String JavaDoc authenticateUser(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, FilterChain JavaDoc fc) throws Exception JavaDoc;
113
114     public abstract String JavaDoc authenticateUser(Map JavaDoc request) throws Exception JavaDoc;
115
116     public abstract Principal JavaDoc loginUser(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Map JavaDoc status) throws Exception JavaDoc;
117
118     public abstract boolean logoutUser(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc;
119     
120     public abstract String JavaDoc getLoginDialogUrl(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc;
121
122     public abstract String JavaDoc getAuthenticatorClass();
123
124     public abstract void setAuthenticatorClass(String JavaDoc authenticatorClass);
125
126     public abstract String JavaDoc getAuthorizerClass();
127
128     public abstract void setAuthorizerClass(String JavaDoc authorizerClass);
129
130     public abstract String JavaDoc getInvalidLoginUrl();
131
132     public abstract void setInvalidLoginUrl(String JavaDoc invalidLoginUrl);
133
134     public abstract String JavaDoc getLoginUrl();
135
136     public abstract void setLoginUrl(String JavaDoc loginUrl);
137
138     public abstract String JavaDoc getSuccessLoginUrl();
139     
140     public abstract void setSuccessLoginUrl(String JavaDoc successLoginUrl);
141
142     public abstract String JavaDoc getLogoutUrl();
143
144     public abstract void setLogoutUrl(String JavaDoc logoutUrl);
145
146     public abstract String JavaDoc getServerName();
147
148     public abstract void setServerName(String JavaDoc serverName);
149
150     public abstract Properties JavaDoc getExtraProperties();
151
152     public abstract void setExtraProperties(Properties JavaDoc properties);
153     
154     public abstract String JavaDoc getCasRenew();
155
156     public abstract void setCasRenew(String JavaDoc casRenew);
157
158     public abstract String JavaDoc getCasServiceUrl();
159
160     public abstract void setCasServiceUrl(String JavaDoc casServiceUrl);
161
162     public abstract String JavaDoc getCasValidateUrl();
163
164     public abstract void setCasValidateUrl(String JavaDoc casValidateUrl);
165
166     public abstract String JavaDoc getCasLogoutUrl();
167
168     public abstract void setCasLogoutUrl(String JavaDoc casLogoutUrl);
169
170     public abstract String JavaDoc getCasAuthorizedProxy();
171
172     public abstract void setCasAuthorizedProxy(String JavaDoc casAuthorizedProxy);
173
174     public abstract Object JavaDoc getTransactionObject();
175
176     public abstract void setTransactionObject(Object JavaDoc transactionObject);
177
178 }
Popular Tags