KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > AuthRealmConfigFactory


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 /*
25  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/config/AuthRealmConfigFactory.java,v 1.9 2006/03/09 20:30:36 llc Exp $
26  * $Revision: 1.9 $
27  * $Date: 2006/03/09 20:30:36 $
28  */

29 package com.sun.enterprise.management.config;
30
31 import java.util.Map JavaDoc;
32 import java.util.Properties JavaDoc;
33
34 import javax.management.ObjectName JavaDoc;
35
36 import javax.management.Attribute JavaDoc;
37 import javax.management.AttributeList JavaDoc;
38
39 import com.sun.appserv.management.config.PropertiesAccess;
40 import com.sun.appserv.management.config.AuthRealmConfig;
41 import static com.sun.appserv.management.config.AuthRealmConfig.*;
42
43 import com.sun.appserv.management.util.misc.StringUtil;
44
45 import com.sun.enterprise.management.support.oldconfig.OldSecurityServiceMBean;
46 import com.sun.enterprise.management.support.oldconfig.OldConfigsMBean;
47
48 import com.sun.enterprise.security.auth.realm.file.FileRealm;
49
50 /**
51  */

52 public final class AuthRealmConfigFactory extends ConfigFactory
53 {
54         public
55     AuthRealmConfigFactory(final ConfigFactoryCallback callbacks)
56     {
57         super( callbacks );
58         
59         assert( FileRealm.JAAS_CONTEXT_PARAM.equals(
60             StringUtil.stripPrefix( JAAS_CONTEXT_PROPERTY_KEY,
61                     PropertiesAccess.PROPERTY_PREFIX ) ) );
62                     
63         assert( FileRealm.PARAM_KEYFILE.equals(
64             StringUtil.stripPrefix( KEY_FILE_PROPERTY_KEY,
65                     PropertiesAccess.PROPERTY_PREFIX ) ) );
66     }
67     
68         private final OldSecurityServiceMBean
69     getOldSecurityServiceMBean( )
70     {
71         final OldSecurityServiceMBean oldSecurityService =
72             getOldConfigProxies().getOldSecurityServiceMBean( getConfigName() );
73         return( oldSecurityService );
74     }
75     
76         private final OldConfigsMBean
77     getOldConfigsMBean( )
78     {
79         final OldConfigsMBean oldConfigs =
80             getOldConfigProxies().getOldConfigsMBean();
81         return( oldConfigs );
82     }
83     
84     
85     static final String JavaDoc CLASSNAME_KEY = "Classname";
86     
87         private void
88     checkDefaultProps( final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
89     {
90         final String JavaDoc keyFile = optional == null ?
91                             null : (String JavaDoc)optional.get( KEY_FILE_PROPERTY_KEY );
92         if ( keyFile == null )
93         {
94             throw new IllegalArgumentException JavaDoc(
95                 "Must specify a key file using KEY_FILE_PROPERTY_KEY in options Map" );
96         }
97         
98         final String JavaDoc jaasContext = optional == null ?
99                             null : (String JavaDoc)optional.get( JAAS_CONTEXT_PROPERTY_KEY );
100         if ( jaasContext == null )
101         {
102             throw new IllegalArgumentException JavaDoc(
103                 "Must specify a JAAS context file using JAAS_CONTEXT_PROPERTY_KEY in options Map" );
104         }
105     }
106     
107         public ObjectName JavaDoc
108     create(
109         final String JavaDoc name,
110         final String JavaDoc className,
111         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
112     {
113         if ( className.equals( DEFAULT_REALM_CLASSNAME ) )
114         {
115             checkDefaultProps( optional );
116         }
117         
118         final String JavaDoc[] requiredParams = { CLASSNAME_KEY, className, };
119
120         final Map JavaDoc<String JavaDoc,String JavaDoc> params =
121             initParams( name, requiredParams, optional );
122
123         final ObjectName JavaDoc amxName = createNamedChild( name, params );
124
125         return amxName;
126     }
127
128     
129
130         protected final void
131     removeByName( final String JavaDoc authLayer )
132     {
133         getOldSecurityServiceMBean().removeAuthRealmByName( authLayer );
134     }
135
136     /**
137         The caller is responsible for dealing with any Properties.
138      */

139         protected ObjectName JavaDoc
140     createOldChildConfig(
141         final AttributeList JavaDoc translatedAttrs,
142         final Properties JavaDoc props )
143     {
144         final String JavaDoc target = getConfigName();
145         
146         final ObjectName JavaDoc objectName =
147             getOldConfigsMBean().createAuthRealm(
148                 translatedAttrs, props, target);
149         
150         return( objectName );
151     }
152 }
153
154
155
156
157
158
159
160
Popular Tags