KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > RealmManager


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 package com.sun.enterprise.security;
24
25 import java.util.*;
26 import java.io.*;
27 import java.util.logging.*;
28 import javax.naming.Context JavaDoc;
29 import com.sun.enterprise.util.Utility;
30 import com.sun.enterprise.util.ORBManager;
31 import com.sun.enterprise.Switch;
32 import com.sun.enterprise.security.auth.RemoteObject;
33 import com.sun.enterprise.security.auth.realm.Realm;
34 import com.sun.enterprise.NamingManager;
35 import com.sun.enterprise.naming.NamingManagerImpl;
36 import com.sun.enterprise.security.RealmConfig;
37 import com.sun.logging.*;
38
39
40 /**
41  * This class has methods to startup and access the Realm and register
42  * it within the current Name Service.
43  * @see IRealmManager the remote interface to access the realm
44  * @author Harpreet Singh
45  */

46
47 public class RealmManager extends RemoteObject implements IRealmManager{
48
49     private static Logger _logger=null;
50     static {
51         _logger=LogDomains.getLogger(LogDomains.SECURITY_LOGGER);
52     }
53
54     // Name of the Realm Manager Service in the Name Service.
55
public static String JavaDoc REALM_MANAGER_NAME = "Realm_Manager";
56
57     
58     /**
59      * Creates a new instance of the Realm Manager.
60      * This call expects that an initialized ORB has been set in the
61      * ORBManager
62      * @see com.sun.enterprise.util.ORBManager
63      */

64     public RealmManager() {
65     super();
66     }
67
68     
69     /**
70      * Initializes the Realm Manager Server & binds the name in the
71      * Name Service.
72      * @exception A javax.naming.NamingException is thrown if unable
73      * to register the Authentication Server.
74      */

75     public void init()
76     throws javax.naming.NamingException JavaDoc, java.rmi.RemoteException JavaDoc {
77
78             RealmConfig.createRealms();
79     }
80
81     
82     /**
83      * Starts the Authentication Server & waits forever for invocations.
84      */

85     public void start() throws java.lang.InterruptedException JavaDoc {
86     // wait for object invocation
87
Object JavaDoc sync = new Object JavaDoc();
88     synchronized (sync) {
89         sync.wait();
90     }
91     }
92
93     
94     public void refreshRealms(String JavaDoc realmName)
95     throws java.rmi.RemoteException JavaDoc{
96         try{
97         Realm r = Realm.getInstance(realmName);
98         r.refresh();
99         }catch (Exception JavaDoc e){
100         throw new java.rmi.RemoteException JavaDoc(e.toString());
101         }
102     }
103
104     
105     /**
106      *
107      * Starts up a standalone Realm Manager. It uses the command
108      * line arguments to initialize the ORB.
109      *
110      */

111     public static void main(String JavaDoc[] args) {
112     try {
113         Utility.checkJVMVersion();
114         // Initialize the ORB if not already started.
115
ORBManager.getORB() ;
116
117         Switch theSwitch = Switch.getSwitch();
118         NamingManager nm = new NamingManagerImpl();
119         theSwitch.setNamingManager(nm);
120         
121         RealmManager mgr = new RealmManager();
122         mgr.init(); // Initialize the Authentication Service ...
123
mgr.start(); // Start the Server.
124
} catch (Exception JavaDoc ex) {
125         _logger.log(Level.SEVERE,
126                         "java_security.realm_manager_exception",ex);
127     }
128     }
129
130     
131 }
132
133
134
135
Popular Tags