KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > auth > realm > UserMgmtEventListenerImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.security.auth.realm;
25
26 import com.sun.enterprise.admin.event.AdminEventListenerException;
27 import com.sun.enterprise.admin.event.UserMgmtEvent;
28 import com.sun.enterprise.admin.event.UserMgmtEventListener;
29 import com.sun.enterprise.security.SecurityUtil;
30 import com.sun.enterprise.security.auth.realm.file.FileRealm;
31 import com.sun.enterprise.server.pluggable.SecuritySupport;
32
33
34 /**
35  * Implements interface UserMgmtEventListener.
36  * So that users can be dynamically created/updated/deleted.
37  * @author Shing Wai Chan
38  */

39 public class UserMgmtEventListenerImpl implements UserMgmtEventListener {
40
41     /**
42      * user added.
43      * It is called whenever a UserMgmtEvent with action of
44      * UserMgmtEvent.ACTION_USERADD is received.
45      * @throws AdminEventListenerException when the listener is unable to
46      * process the event.
47      */

48     public void userAdded(UserMgmtEvent event)
49              throws AdminEventListenerException {
50         reloadRealm(event);
51     }
52
53     /**
54      * user deleted.
55      * It is called whenever a UserMgmtEvent with action of
56      * UserMgmtEvent.ACTION_USERREMOVE is received.
57      * @throws AdminEventListenerException when the listener is unable to
58      * process the event.
59      */

60     public void userRemoved(UserMgmtEvent event)
61              throws AdminEventListenerException {
62         reloadRealm(event);
63     }
64
65     /**
66      * user updated (attributes change).
67      * It is called whenever a UserMgmtEvent with action of
68      * UserMgmtEvent.ACTION_USERUPDATE is received.
69      * @throws AdminEventListenerException when the listener is unable to
70      * process the event.
71      */

72     public void userUpdated(UserMgmtEvent event)
73              throws AdminEventListenerException {
74         reloadRealm(event);
75     }
76
77     /**
78      * In this moment, user management is supported only in FileRealm.
79      * The FileRealm will be refreshed in this case.
80      * Other realms will throw Exception.
81      * Administrative API may be factored out during JSR 196 implementation.
82      * @param event the UserMgmtEvent
83      * @exception AdminEventListenerException
84      */

85     private void reloadRealm(UserMgmtEvent event)
86             throws AdminEventListenerException {
87         try {
88             String JavaDoc realmName = event.getAuthRealmName();
89             Realm realm = Realm.getInstance(realmName);
90
91             // should always true in this moment
92
if (realm instanceof FileRealm) {
93                 SecuritySupport secSupp = SecurityUtil.getSecuritySupport();
94                 secSupp.synchronizeKeyFile(event.getConfigContext(), realmName);
95             }
96
97             realm.refresh();
98         } catch(Exception JavaDoc ex) {
99             throw new AdminEventListenerException(ex);
100         }
101     }
102 }
103
Popular Tags