KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > offline > AuthRealmSupport


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.management.offline;
24
25 import com.sun.enterprise.admin.config.MBeanConfigException;
26
27 import com.sun.appserv.management.util.misc.StringUtil;
28
29 /**
30     Support for working with our default file realm.
31  */

32 final class AuthRealmSupport
33 {
34     private final AuthRealmMBeanX mAuthRealmMBean;
35     private final AuthRealmConfigBeanHelper mHelper;
36     
37     public final String JavaDoc PREFIX = "${com.sun.aas.instanceRoot}";
38         
39         public
40     AuthRealmSupport( final AuthRealmConfigBeanHelper helper )
41     {
42         mHelper = helper;
43         
44         String JavaDoc file = helper.getFile();
45         
46         if ( file.startsWith( PREFIX ) )
47         {
48             throw new IllegalArgumentException JavaDoc(
49                 "AuthRealm does not yet support ${...} values for the filename" );
50         }
51         
52         mAuthRealmMBean = new AuthRealmMBeanX( file );
53     }
54         protected void
55     sdebug( Object JavaDoc o )
56     {
57         System.out.println( "" + o );
58     }
59     
60         private String JavaDoc
61     getRealmName()
62     {
63         try
64         {
65             return (String JavaDoc)mHelper.getAttribute( "Name" );
66         }
67         catch( Exception JavaDoc e )
68         {
69             return null;
70         }
71     }
72     
73         public String JavaDoc[]
74     getGroupNames()
75     {
76         try
77         {
78             return mAuthRealmMBean.getGroupNames();
79         }
80         catch( MBeanConfigException e )
81         {
82             throw new RuntimeException JavaDoc( "" + e );
83         }
84     }
85     
86         public String JavaDoc[]
87     getUserNames()
88     {
89         //sdebug( "AuthRealmSupport.getUserNames(): " + getRealmName() );
90

91         try
92         {
93             final String JavaDoc[] userNames = mAuthRealmMBean.getUserNames();
94             
95             //sdebug( "AuthRealmSupport.getUserNames(): " +
96
//getRealmName() + ": " + StringUtil.toString( userNames ) );
97
return userNames;
98         }
99         catch( MBeanConfigException e )
100         {
101             //sdebug( e.getMessage() );
102
//e.printStackTrace();
103
throw new RuntimeException JavaDoc( "" + e );
104         }
105     }
106     
107         public String JavaDoc[]
108     getUserGroupNames( final String JavaDoc user )
109     {
110         try
111         {
112             return mAuthRealmMBean.getUserGroupNames( user );
113         }
114         catch( MBeanConfigException e )
115         {
116             throw new RuntimeException JavaDoc( "" + e );
117         }
118     }
119     
120         public void
121     addUser(
122         final String JavaDoc user,
123         final String JavaDoc password,
124         final String JavaDoc[] groupList)
125     {
126         try
127         {
128             mAuthRealmMBean.addUser( user, password, groupList );
129         }
130         catch( MBeanConfigException e )
131         {
132             throw new RuntimeException JavaDoc( "" + e );
133         }
134     }
135     
136         public void
137     updateUser(
138         final String JavaDoc user,
139         final String JavaDoc password,
140         final String JavaDoc[] groupList)
141     {
142         try
143         {
144             mAuthRealmMBean.updateUser( user, password, groupList );
145         }
146         catch( MBeanConfigException e )
147         {
148             throw new RuntimeException JavaDoc( "" + e );
149         }
150     }
151     
152         public void
153     removeUser( final String JavaDoc user)
154     {
155         try
156         {
157             mAuthRealmMBean.removeUser( user );
158         }
159         catch( MBeanConfigException e )
160         {
161             throw new RuntimeException JavaDoc( "" + e );
162         }
163     }
164 }
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
Popular Tags