KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > admin > security > SecurityBean


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: SecurityBean.java,v $
31  * Revision 1.3 2005/04/10 19:42:41 colinmacleod
32  * *** empty log message ***
33  *
34  * Revision 1.2 2005/04/09 17:19:56 colinmacleod
35  * Changed copyright text to GPL v2 explicitly.
36  *
37  * Revision 1.1.1.1 2005/03/10 17:51:40 colinmacleod
38  * Restructured ivata op around Hibernate/PicoContainer.
39  * Renamed ivata groupware.
40  *
41  * Revision 1.3 2004/11/12 18:16:07 colinmacleod
42  * Ordered imports.
43  *
44  * Revision 1.2 2004/11/12 15:57:18 colinmacleod
45  * Removed dependencies on SSLEXT.
46  * Moved Persistence classes to ivata masks.
47  *
48  * Revision 1.1 2004/09/30 15:15:58 colinmacleod
49  * Split off addressbook elements into security subproject.
50  *
51  * Revision 1.5 2004/07/13 19:41:11 colinmacleod
52  * Moved project to POJOs from EJBs.
53  * Applied PicoContainer to services layer (replacing session EJBs).
54  * Applied Hibernate to persistence layer (replacing entity EJBs).
55  *
56  * Revision 1.4 2004/03/21 21:16:05 colinmacleod
57  * Shortened name to ivata op.
58  *
59  * Revision 1.3 2004/03/21 20:21:49 colinmacleod
60  * Converted to using factory method for security server (rather than singleton).
61  *
62  * Revision 1.2 2004/02/01 22:00:31 colinmacleod
63  * Added full names to author tags
64  *
65  * Revision 1.1.1.1 2004/01/27 20:57:45 colinmacleod
66  * Moved ivata openportal to SourceForge..
67  *
68  * Revision 1.7 2003/11/03 11:28:24 jano
69  * commiting addressbook,
70  * tryinjg to fix deploying problem
71  *
72  * Revision 1.6 2003/10/24 13:18:12 jano
73  * fixing some bugs
74  *
75  * Revision 1.5 2003/10/17 12:36:12 jano
76  * fixing problems with building
77  * converting intranet -> portal
78  * Eclipse building
79  *
80  * Revision 1.4 2003/10/16 07:53:41 jano
81  * fixing XDoclet
82  *
83  * Revision 1.3 2003/10/15 12:35:33 jano
84  * going back to 1.1
85  *
86  * Revision 1.1 2003/10/13 20:50:06 colin
87  * Initial revision
88  *
89  * Revision 1.10 2003/09/11 13:10:10 jano
90  * fixing bugs with ranaming userName and with removing user from system
91  *
92  * Revision 1.9 2003/07/25 11:49:45 jano
93  * adding functionality for addressBook extension
94  *
95  * Revision 1.8 2003/06/04 09:56:17 jano
96  * if new user is not enable it's not necesary check email
97  *
98  * Revision 1.7 2003/05/22 07:58:49 jano
99  * we have new method in SecurityBean getUserNameFromSystemUserName
100  *
101  * Revision 1.6 2003/04/09 09:43:42 jano
102  * *** empty log message ***
103  *
104  * Revision 1.5 2003/04/09 08:49:22 jano
105  * handling data of removing user
106  *
107  * Revision 1.4 2003/04/01 15:01:01 jano
108  * fixing bug with addUserToPerson
109  *
110  * Revision 1.3 2003/03/14 10:25:44 jano
111  * adding backdoor man functionality
112  * backdoor man = briezky
113  *
114  * Revision 1.2 2003/02/25 14:38:12 colin
115  * implemented setModified methods on entity beans thro IvataEntityBean superclass
116  *
117  * Revision 1.1 2003/02/24 18:53:57 colin
118  * added to admin
119  *
120  * Revision 1.8 2003/02/04 17:43:50 colin
121  * copyright notice
122  *
123  * Revision 1.7 2002/12/03 15:39:49 jano
124  * automaticaly put new user to USER group
125  *
126  * Revision 1.6 2002/11/20 16:59:06 jano
127  * I changed message that you can add email in contact list or add at least one user alias
128  *
129  * Revision 1.5 2002/10/23 12:44:56 jano
130  * fixing bug in getSystemUserName
131  *
132  * Revision 1.4 2002/10/23 09:16:39 jano
133  * new method for genereting SystemUserName,
134  * it's userName with prefix
135  *
136  * Revision 1.3 2002/10/18 08:37:39 colin
137  * bugfixes in addUser, amendUser and setPassword
138  *
139  * Revision 1.2 2002/09/10 06:52:22 colin
140  * added boolean enable to addUserToPerson
141  *
142  * Revision 1.1 2002/09/09 08:35:24 colin
143  * new security EJB takes over role of
144  * logging into the system
145  * maintaining user names and passwords
146  * -----------------------------------------------------------------------------
147  */

148 package com.ivata.groupware.admin.security;
149
150 import javax.ejb.CreateException JavaDoc;
151 import javax.ejb.EJBException JavaDoc;
152 import javax.ejb.RemoveException JavaDoc;
153 import javax.ejb.SessionBean JavaDoc;
154 import javax.ejb.SessionContext JavaDoc;
155
156 import org.picocontainer.PicoContainer;
157
158 import com.ivata.groupware.admin.security.server.SecuritySession;
159 import com.ivata.groupware.admin.security.user.UserDO;
160 import com.ivata.groupware.container.PicoContainerFactory;
161 import com.ivata.mask.util.SystemException;
162
163 /**
164  * <p>The security bean is responsible for adding, removing and amending users
165  * to the system, and for logging in in the first place.</p>
166  *
167  * @since 2002-09-08
168  * @author Colin MacLeod
169  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
170  * @version $Revision: 1.3 $
171  *
172  * @ejb.bean
173  * name="Security"
174  * display-name="Security"
175  * type="Stateless"
176  * view-type="remote"
177  * jndi-name="SecurityRemote"
178  *
179  * @ejb.transaction
180  * type = "Required"
181  *
182  * @ejb.home
183  * generate="false"
184  * remote-class="com.ivata.groupware.admin.security.SecurityRemoteHome"
185  *
186  * @ejb.interface
187  * remote-class="com.ivata.groupware.admin.security.SecurityRemote"
188  */

189 public class SecurityBean implements SessionBean JavaDoc {
190     /**
191      * <p>Provides the session bean with container-specific information.</p>
192      */

193     SessionContext JavaDoc sessionContext;
194
195    /**
196      * <p>Check a password is correct for a user.</p>
197      *
198      * @param userName
199      * @param password
200      * @throws InvalidFieldValueException if any of the parameters are
201      * <code>null</code>.
202      * @throws InvalidFieldValueException if any of the parameters are
203      * <code>null</code>.
204      *
205      * @ejb.interface-method
206      * view-type = "remote"
207      */

208     public void checkPassword(final SecuritySession securitySession,
209             final String JavaDoc password) throws SystemException {
210         getSecurity().checkPassword(securitySession, password);
211     }
212
213     /**
214      * <p>Called by the container to notify an entity object it has been
215      * activated.</p>
216      */

217     public void ejbActivate() {}
218
219     /**
220      * <p>Called by the container just after the bean has been created.</p>
221      *
222      * @exception CreateException if any error occurs. Never thrown by this
223      * class.
224      *
225      * @ejb.create-method
226      */

227     public void ejbCreate() throws CreateException JavaDoc {}
228
229     /**
230      * <p>Called by the container to notify the entity object it will be
231      * deactivated. Called just before deactivation.</p>
232      */

233     public void ejbPassivate() {}
234
235     /**
236      * <p>This method is called by the container when the bean is about
237      * to be removed.</p>
238      *
239      * <p>This method will be called after a client calls the <code>remove</code>
240      * method of the remote/local home interface.</p>
241      *
242      * @throws RemoveException if any error occurs. Currently never thrown by
243      * this class.
244      */

245     public void ejbRemove() {}
246
247     /**
248      * Find a user given the user name.
249      *
250      * @param securitySession valid security session.
251      * @param userName name of the user to find.
252      */

253     public UserDO findUserByName(final SecuritySession securitySession,
254             final String JavaDoc userName)
255             throws SystemException {
256         return getSecurity().findUserByName(securitySession, userName);
257     }
258
259     /**
260      * Get the security implementation.
261      *
262      * @return valid security implementation.
263      */

264     private Security getSecurity() throws SystemException {
265         PicoContainer container = PicoContainerFactory.getInstance()
266             .getGlobalContainer();
267         return (Security) container.getComponentInstance(Security.class);
268     }
269
270     /**
271      * <p>This method add prefix to username.</p>
272      *
273      * @param userName
274      * @return prefix_userName
275      *
276      * @ejb.interface-method
277      * view-type = "remote"
278      */

279     public final String JavaDoc getSystemUserName(final SecuritySession securitySession,
280             final String JavaDoc userName)
281             throws SystemException {
282         return getSecurity().getSystemUserName(securitySession, userName);
283     }
284
285     /**
286      * <p>This method is converting SystemUserName to userName, it's oposite method to getSystemUserName.</p>
287      * @param systemUserName
288      * @return
289      *
290      * @ejb.interface-method
291      * view-type = "remote"
292      */

293     public final String JavaDoc getUserNameFromSystemUserName(
294             final SecuritySession securitySession,
295             final String JavaDoc systemUserName)
296             throws SystemException {
297         return getSecurity().getUserNameFromSystemUserName(securitySession,
298                 systemUserName);
299     }
300
301     /**
302      * <p>Find out if a user is currently enabled
303      * @param userName
304      * @throws InvalidFieldValueException if <code>userName</code> is
305      * <code>null</code>.
306      * @return <code>true</code> if the user is currently enabled, otherwise
307      * <code>false</code>.
308      *
309      * @ejb.interface-method
310      * view-type = "remote"
311      */

312     public boolean isUserEnabled(final SecuritySession securitySession,
313             final String JavaDoc userName)
314             throws SystemException {
315         return getSecurity().isUserEnabled(securitySession, userName);
316     }
317
318     /**
319      * <p>Login to the system. This method confirms the user name and password
320      * against system settings and logs the user into the mail server, if this
321      * is the desired form of authentication.</p>
322      *
323      * @param userName this user name is used to log into the remote system.
324      * @param password the clear-text password to log into the remote system.
325      * @throws EJBException if the person cannot log in.
326      * @return the mail server used to access the mail system, or
327      * <code>null</code> if another form of authentication is being used.
328      *
329      * @ejb.interface-method
330      * view-type = "remote"
331      */

332     public SecuritySession login(final UserDO user,
333             final String JavaDoc password)
334             throws SystemException {
335         return getSecurity().login(user, password);
336     }
337
338     /**
339      * <p>if userName briezky is trying login -> find first admin .</p>
340      * @param userName
341      * @return
342      *
343      * @ejb.interface-method
344      * view-type = "remote"
345      */

346     public String JavaDoc loginAgain(final SecuritySession securitySession,
347             final String JavaDoc userName)
348             throws SystemException {
349         return getSecurity().loginAgain(securitySession, userName);
350     }
351
352     /**
353      * <p>Remove a user from the system. <strong>Note:</strong> this can have dire
354      * consequences and will delete all entries this user has ever made in the
355      * system. Consider using <code>enableUser</code> instead.</p>
356      *
357      * @param userName the name of the user who is doing the removing. <strong>This
358      * is not the name of the user to be removed!</strong>
359      * @param userNameRemove the name of the user to be removed.
360      * @see #enableUser
361      * @throws InvalidFieldValueException if any of the parameters are
362      * <code>null</code>.
363      *
364      * @ejb.interface-method
365      * view-type = "remote"
366      */

367     public void removeUser(final SecuritySession securitySession,
368             final String JavaDoc userNameRemove) throws SystemException {
369         getSecurity().removeUser(securitySession, userNameRemove);
370     }
371
372     /**
373      * <p>Restore user is he was delted.</p>
374      * @param userName who is doing this operation
375      * @param restoreUserName who is going to be restored
376      *
377      * @ejb.interface-method
378      * view-type = "remote"
379      */

380     public void restoreUser(final SecuritySession securitySession,
381             final String JavaDoc restoreUserName)
382             throws SystemException {
383         getSecurity().restoreUser(securitySession, restoreUserName);
384     }
385
386     /**
387      * <p>Set the password of a user.</p>
388      *
389      * @param userName the name of the user who is changing the password in the
390      * system. <strong>This is not be the user name whose password is to be
391      * changed!</strong>
392      * @param userNamePassword the name of the user for whom to change the
393      * password.
394      * @param password the new value of the password (unencrypted) for the user.
395      * @throws InvalidFieldValueException if any of the parameters are
396      * <code>null</code>.
397      *
398      * @ejb.interface-method
399      * view-type = "remote"
400      */

401     public final void setPassword(final SecuritySession securitySession,
402             final String JavaDoc userNamePassword,
403             final String JavaDoc password) throws SystemException {
404         getSecurity().setPassword(securitySession, userNamePassword, password);
405     }
406
407     /**
408      * <p>Set up the context for this entity object. The session bean stores the
409      * context for later use.</p>
410      *
411      * @param sessionContext the new context which the session object should
412      * store.
413      */

414     public final void setSessionContext(final SessionContext JavaDoc sessionContext) {
415         this.sessionContext = sessionContext;
416     }
417 }
418
Popular Tags