KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > mbean > config > ManagedSecurityService


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.admin.server.core.mbean.config;
25
26 //JMX imports
27
import javax.management.*;
28
29 //Config imports
30
import com.sun.enterprise.config.ConfigException;
31 import com.sun.enterprise.config.serverbeans.ServerTags;
32 import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
33 import com.sun.enterprise.config.serverbeans.SecurityService;
34 import com.sun.enterprise.config.serverbeans.AuthRealm;
35
36 //Admin imports
37
import com.sun.enterprise.admin.common.exception.MBeanConfigException;
38 import com.sun.enterprise.admin.common.constant.ConfigAttributeName;
39 import com.sun.enterprise.admin.common.exception.AFOtherException;
40 import com.sun.enterprise.admin.common.ObjectNames;
41
42 //i18n import
43
import com.sun.enterprise.util.i18n.StringManager;
44
45 /**
46     This Config MBean represents a SecurityService.
47     It extends ConfigMBeanBase class which provides get/set attribute(s) and getMBeanInfo services according to text descriptions.
48     ObjectName of this MBean is:
49         ias: type=security-service, instance-name=<instance-name>
50 */

51 public class ManagedSecurityService extends ConfigMBeanBase implements ConfigAttributeName.SecurityService
52 {
53     /**
54      * MAPLIST array defines mapping between "external" name and its location in XML relatively base node
55      */

56     private static final String JavaDoc[][] MAPLIST =
57     {
58         {kDefaultRealm , ATTRIBUTE + ServerTags.DEFAULT_REALM},
59         {kDefaultPrincipal , ATTRIBUTE + ServerTags.DEFAULT_PRINCIPAL},
60         {kDefaultPrincipalPassword , ATTRIBUTE + ServerTags.DEFAULT_PRINCIPAL_PASSWORD},
61         {kAnonymousRole , ATTRIBUTE + ServerTags.ANONYMOUS_ROLE},
62         {kAuditEnabled , ATTRIBUTE + ServerTags.AUDIT_ENABLED},
63         // {kLogLevel , ATTRIBUTE + ServerTags.LOG_LEVEL},
64
};
65     /**
66      * ATTRIBUTES array specifies attributes descriptions in format defined for MBeanEasyConfig
67      */

68     private static final String JavaDoc[] ATTRIBUTES =
69     {
70         kDefaultRealm + ", String, RW" ,
71         kDefaultPrincipal + ", String, RW" ,
72         kDefaultPrincipalPassword + ", String, RW" ,
73         kAnonymousRole + ", String, RW" ,
74         kAuditEnabled + ", boolean, RW" ,
75         // kLogLevel + ", String, RW" ,
76
};
77     /**
78      * OPERATIONS array specifies operations descriptions in format defined for MBeanEasyConfig
79      */

80     private static final String JavaDoc[] OPERATIONS =
81     {
82         "createAuthRealm(String name, String classname), ACTION",
83         "deleteAuthRealm(String id), ACTION",
84         "listAuthRealms(), INFO",
85     };
86     
87    
88     // i18n StringManager
89
private static StringManager localStrings =
90         StringManager.getManager( ManagedSecurityService.class );
91     
92     /**
93         Default constructor sets MBean description tables
94     */

95     public ManagedSecurityService() throws MBeanConfigException
96     {
97         this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS);
98     }
99
100     /**
101         Constructs Config MBean for Security Service Component.
102         @param instanceName The server instance name.
103     */

104     public ManagedSecurityService(String JavaDoc instanceName) throws MBeanConfigException
105     {
106         this(); //set description tables
107
initialize(ObjectNames.kSecurityServiceType, new String JavaDoc[]{instanceName});
108     }
109     
110     /**
111     This operation creates AuthRealm according to attributes and adds(links) it to current SecurityService;
112     If attribute is 'null' then default value will be set.
113      */

114     public void createAuthRealm(String JavaDoc name, String JavaDoc classname) throws ConfigException
115     {
116         AuthRealm authRealm = new AuthRealm();
117         if(name!=null)
118             authRealm.setName(name);
119         if(classname!=null)
120             authRealm.setClassname(classname);
121         SecurityService securityService = (SecurityService)getConfigBeanByXPath( ServerXPathHelper.getSecurityServiceXpath() );
122         securityService.addAuthRealm(authRealm);
123         
124         getConfigContext().flush();
125     }
126     
127     /**
128     This operation deletes AuthRealm according to id if it connected to current SecurityService.
129     @throws ConfigException in case of failure.
130      */

131     public void deleteAuthRealm(String JavaDoc id) throws ConfigException, MBeanException, AttributeNotFoundException
132     {
133         SecurityService securityService = (SecurityService)getConfigBeanByXPath( ServerXPathHelper.getSecurityServiceXpath() );
134         AuthRealm authRealm = securityService.getAuthRealmByName(id);
135         if(((String JavaDoc) getAttribute(kDefaultRealm)).equals(id)){
136             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.default_realm_cannot_delete", id );
137           throw new ConfigException( msg );
138         }
139   
140         if(authRealm!=null)
141             securityService.removeAuthRealm(authRealm);
142         getConfigContext().flush();
143     }
144
145     /**
146     This operation returns list of AuthRealm's ids connected to current SecurityService.
147      */

148     public String JavaDoc[] listAuthRealms() throws ConfigException
149     {
150         SecurityService securityService = (SecurityService)getConfigBeanByXPath( ServerXPathHelper.getSecurityServiceXpath() );
151         AuthRealm[] authRealms = securityService.getAuthRealm();
152         String JavaDoc[] res = new String JavaDoc[authRealms.length];
153         for(int i=0; i<authRealms.length; i++)
154         {
155             res[i] = authRealms[i].getName();
156         }
157         return res;
158     }
159 }
160
161
162
163
164
165
166
Popular Tags