Developing Custom Management Utilities with JMX
A security realm comprises mechanisms for protecting WebLogic resources. Each security realm consists of a set of configured security providers, which are modular components that handle specific aspects of security. You can create a JMX client that uses the providers in a realm to add or remove security data such as users and groups. You can also create a client that adds or removes providers and makes other changes to the realm configuration.
The following sections describe managing security realms with JMX:
For more information about WebLogic Security, see Understanding WebLogic Security.
Like other subsystems, the WebLogic Server security framework organizes its MBeans in a hierarchy that JMX clients can navigate without constructing JMX object names. However, the set of MBean types that are available in a security realm depends on which security providers you have installed in the realm, and the set of services that each security provider enables depends on how the provider was created.
The root of the security realm hierarchy is the RealmMBean
. It contains all of the providers that have been configured for the realm. For example, its Authorizers
attribute contains all authorization providers that have been configured for the realm. WebLogic Server installs a default set of security providers; therefore, by default the RealmMBean
Authorizers
attribute contains a DefaultAuthorizerMBean
. However, you can uninstall these default providers and replace them with any number of your own providers or third-party providers. For information about the default security providers, see Configuring WebLogic Security Providers and Configuring Authorization Providers in Securing WebLogic Server.
Each security provider must extend a base provider type. For example, DefaultAuthorizerMBean
extends AuthorizerMBean
, and any custom or third-party authorization provider also extends AuthorizerMBean
. If a JMX client gets the value of the RealmMBean
Authorizers
attribute, the MBean server returns all MBeans in the realm that extend AuthorizerMBean
. The JMX client can iterate through the list of providers and select one based on the value of its Name
attribute or other criteria.
Base provider types can be enhanced by extending a set of optional mix-in interfaces. For example, if an authentication provider extends the UserEditorMBean
, then the provider can add users to the realm.
WebLogic Server's Security MBeans configure security providers in a security realm. The following tables describe the MBeans that configure different types of security providers.
For more information about configuring WebLogic security providers, see Configuring WebLogic Security Providers and Configuring Authentication Providers in Securing WebLogic Server. Figure 6-1 illustrates where the MBeans are located in the configuration MBean hierarchy.
The base MBean for all MBean implementations that manage Authentication providers. If your Authentication provider uses the WebLogic Security SSPI to provide login services, then your MBean must extend See |
|
The SSPI MBean that all Authentication providers with login services must extend. This MBean provides a See |
|
The SSPI MBean that all Identity Assertion providers must extend. This MBean enables an Identity Assertion provider to specify the token types for which it is capable of asserting identity. See |
|
The SSPI MBean that all Servlet Authentication Filter providers must extend. This MBean is just a marker interface. It has no methods on it. See |
The SSPI MBean that all Adjudication providers must extend. See |
|
Configuration attributes for the WebLogic Adjudication provider. See |
|
The SSPI MBean that all Auditing providers must extend. See |
|
Configuration attributes for the WebLogic Auditing provider. See |
|
The SSPI MBean that all Authorization providers must extend. See |
|
The SSPI MBean that must be extended by all Authorization providers that can store policies created while deploying a Web application or EJB. See |
|
Configuration attributes for the WebLogic Authorization provider. See |
|
The SSPI MBean that all Credential Mapping providers must extend. See |
|
The SSPI MBean that must be extended by all Credential Mapper providers that can store credential maps created while deploying a component. See |
|
Configuration attributes for the WebLogic Credential Mapping provider, a username/password Credential Mapping provider. See |
|
Configuration attributes for the PKI Credential Mapping provider, a key pair Credential Mapping provider. See |
|
Configuration attributes for the SAML Credential Mapping provider, a Security Assertion Markup Language Credential Mapping provider. See |
|
The base MBean for all certification path providers. See |
|
The SSPI MBean that all certification path providers with CertPathBuilder services must extend. See |
|
The SSPI MBean that all certification path providers with CertPathValidator services must extend. See |
|
Configures and manages the certificate registry. It is both a builder and a validator. It supports building from the end certificate, the end certificate's subject DN, the end certificate's issuer DN and serial number, and the end certificate's subject key identifier. See |
|
The SSPI MBean that all certification path providers with CertPathBuilder services must extend. See |
|
The base MBean for Role Mapping providers. A Role Mapping provider for a non-deployable module must extend this MBean directly. A Role Mapping provider for a deployable module must extend the See |
|
The SSPI MBean that must be extended by Role Mapping providers that can store roles created while deploying a Web application or EJB. See |
|
Configuration attributes for the WebLogic Role Mapping provider. See |
Provides a set of attributes for ContextHandler support. An Auditor provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for creating, editing, and removing groups. An Authentication provider MBean can optionally implement this MBean. See |
|
Provides a method for listing a group's members. An Authentication provider MBean can optionally implement this MBean. See |
|
Provides configuration attributes that are required to support the Group Membership Hierarchy Cache. An Authentication provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for reading data about groups. An Authentication provider MBean can optionally implement this MBean. See |
|
Provides a method for listing the groups that contain a member. An Authentication provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for creating, editing, and removing users. An Authentication provider MBean can optionally implement this MBean. See |
|
Lists and manages lockouts on user accounts. An Authentication provider MBean can optionally implement this MBean. See |
|
Provides two methods for changing a user's password. An Authentication provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for reading data about users. An Authentication provider MBean can optionally implement this MBean. See |
|
Provides a method for removing users. An Authentication provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for creating, editing, and removing roles. A Role Mapping provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for listing data about roles. A Role Mapping provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for reading roles. A Role Mapping provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for creating, editing, and removing policies. An Authorization provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for listing data about policies. An Authorization provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for reading policies. An Authorization provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for creating, editing, and removing a credential map that matches users, resources and credential action to keystore aliases and the corresponding passwords. A PKICredentialMapping provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for reading a credential map that matches users and resources to keystore aliases and their corresponding passwords that can then be used to retrieve key information or public certificate information from the configured keystores. A PKICredentialMapping provider MBean can optionally implement this MBean. See |
|
Provides a set of methods for creating, editing, and removing a credential map that matches WebLogic users to remote usernames and their corresponding passwords. A Credential Mapping provider MBean can optionally extend this MBean. See |
|
Provides a set of methods for reading credentials and credential mappings. Credential mappings match WebLogic users to remote usernames and passwords. A Credential Mapping provider MBean can optionally extend this MBean. See |
|
Provides a set of methods for reading credentials and credential mappings. Credential mappings match WebLogic users to remote usernames and passwords. A Credential Mapping provider MBean can optionally extend this MBean. See |
|
Provides a set of methods for importing provider specific data. An optional mixin interface that any security provider may extend. See |
|
Provides a set of methods for exporting provider specific data. An optional mixin interface that any security provider may extend. See |
|
Provides a general mechanism for returning lists. Derived MBeans extend this interface to add methods that access the data of the current object in the list. An optional mixin interface that any security provider may extend. See |
|
Defines a method used to return lists of names. An optional mixin interface that any security provider may extend. See |
|
Provides methods to get configuration parameters needed for connecting to an external LDAP server. An optional mixin interface that any security provider may extend. See |
|
The SSPI MBean that security providers extend to indicate that the provider supports versionable applications. An optional mixin interface that a RoleMapper, Authorizer, or CredentialMapper provider MBean may extend. See |
When using JMX to manage security realms, you must use two different MBean servers depending on your task:
For example, the value of the MinimumPasswordLength
attribute in DefaultAuthenticatorMBean
is stored in the domain's configuration document. Because all modifications to this document are controlled by WebLogic Server, to change the value of this attribute you must use the Edit MBean Server and acquire a lock on the domain's configuration. The createUser
operation in DefaultAuthenticatorMBean
adds data to an LDAP server, which is not controlled by WebLogic Server. To prevent incompatible changes between the DefaultAuthenticatorMBean
's configuration and the data that it uses in the LDAP server, you cannot invoke the createUser
operation if you or other users are in the process of modifying the MinimumPasswordLength
attribute. In addition, because changing this attribute requires you to restart WebLogic Server, you cannot invoke the createUser
operation until you have restarted the server.
Because security providers can extend optional mix-in interfaces, not all security providers can perform all tasks. This flexibility enables your organization's security architect to design a realm for your security needs. The flexibility also makes the design of your JMX clients dependent upon the design and configuration of each realm.
For example, some realms might contain three types of Authentication providers:
UserEditorMBean
to save administrative users to an LDAP serverUserEditorMBean
to save customers to a database management systemUserEditorMBean
and is used only to authenticate existing usersTo work with the Authentication providers in this realm, your JMX client must be able to determine which one can add users to the appropriate repository.
Table 6-4 discusses techniques for finding a security provider that is appropriate for your task.
Each security provider instance is assigned a short name when an administrator configures it for the realm. Your JMX client can look up all providers of a specific type (such as all Authentication providers) and choose the one that matches a name. For an example of such a JMX client, start the WebLogic Server Examples Server. From the Examples Server home page, click on "Extending a Realm Using JMX." The source for this JMX client is installed as where If you use this technique, consider saving the name of the security provider in a configuration file instead of hard-coding it in your JMX client. The configuration file enables system administrators to change the providers in the realm and update the properties file instead of requiring you to update and recompile the JMX client. |
|
If the system administrator always wants to use the same type of provider for a task, then your JMX client can find the provider MBean that is of the specified type. For example, if the system administrator always wants to use a While this technique requires no user input, it assumes:
|
|
You can create a JMX client that learns about the class hierarchy for each provider MBean instance and chooses an instance that extends the mix-in interface you need for your task. For example, your client can discover which Authentication provider extends Use this technique if you know that your security realm will contain only one MBean that extends the needed mix-in interface, or if it does not matter which one you use. |
To create a JMX client that finds MBeans by type or mix-in interface:
All WebLogic Server instances maintain their own Runtime MBean Server, and you can connect to any server's Runtime MBean Server.
RealmMBean
attribute, get the name of the MBean's class (see Listing 6-1):Each entry in the WebLogic Server MBean Reference lists the fully-qualified interface name of WebLogic Server provider MBeans. If you use a third-party provider, refer to the third-party documentation for this information.
For example, the fully-qualified interface name of the UserEditorMBean
mix-in interface is weblogic.management.security.authentication.UserEditorMBean
. (See UserEditorMBean
in the WebLogic Server MBean Reference.)
Listing 6-1 Example: Determine If a Provider MBean Instance Extends UserEditorMBean Mix-In Interface
ObjectName MBTservice = new ObjectName(
"com.bea:Name=MBeanTypeService,Type=weblogic.management.mbeanservers.
MBeanTypeService");
for (int p = 0; atnProviders != null && p < atnProviders.length; p++) {
ModelMBeanInfo info = (ModelMBeanInfo)
mBeanServerConnection.getMBeanInfo(atnProviders[p]);
Descriptor desc = info.getMBeanDescriptor();
String className = (String)desc.getFieldValue("interfaceClassName");
String[] mba = (String[]) mBeanServerConnection.invoke( MBTservice,
"getSubtypes", new Object[] {
"weblogic.management.security.authentication.UserEditorMBean" },
new String[] { "java.lang.String" });
boolean isEditor = false;
for (int i = 0; i < mba.length; i++) {
if (mba[i].equals(className)){
userEditor = atnProviders[p];
isEditor = true;
break;
}
if (isEditor = true) break;
}
}
The code example in Listing 6-2 adds a user to a security realm and adds the user to the Administrators
group by searching through all of the authentication providers in the realm and using the first one that extends UserEditorMBean
.
Note the following about the code example:
Listing 6-2 Example: Adding Users to a Realm
public ActionForward createNewAdmin(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws ClientException, Exception {
logger.info("Create New Admin");
CreateAdminBean user = (CreateAdminBean) form;
logger.debug(user.toString());
MBeanServerConnection mBeanServerConnection =
this.getDomainMBeanServerConnection(request);
ObjectName service = new
ObjectName("com.bea:Name=DomainRuntimeService,"+
"Type=weblogic.management.mbeanservers.domainruntime.
DomainRuntimeServiceMBean");
ObjectName domainMBean =
(ObjectName) mBeanServerConnection.getAttribute(service,
"DomainConfiguration");
ObjectName securityConfiguration =
(ObjectName) mBeanServerConnection.getAttribute(domainMBean,
"SecurityConfiguration");
ObjectName defaultRealm =
(ObjectName) mBeanServerConnection.
getAttribute(securityConfiguration, "DefaultRealm");
ObjectName[] atnProviders =
(ObjectName[]) mBeanServerConnection.getAttribute(defaultRealm,
"AuthenticationProviders");
ObjectName userEditor = null;
ObjectName MBTservice = new ObjectName(
"com.bea:Name=MBeanTypeService,Type=weblogic.management.mbeanservers.
MBeanTypeService");
for (int p = 0; atnProviders != null && p < atnProviders.length; p++) {
ModelMBeanInfo info = (ModelMBeanInfo)
mBeanServerConnection.getMBeanInfo(atnProviders[p]);
Descriptor desc = info.getMBeanDescriptor();
String className = (String)desc.getFieldValue("interfaceClassName");
String[] mba = (String[]) mBeanServerConnection.invoke( MBTservice,
"getSubtypes", new Object[] {
"weblogic.management.security.authentication.UserEditorMBean" },
new String[] { "java.lang.String" });
boolean isEditor = false;
for (int i = 0; i < mba.length; i++) {
if (mba[i].equals(className)){
userEditor = atnProviders[p];
isEditor = true;
break;
}
if (isEditor = true) break;
}
}
try {
mBeanServerConnection.invoke(
userEditor, "createUser",
new Object[] {user.getUsername(), user.getPassword(),
"MedRec Admininistator"},
new String[] {"java.lang.String", "java.lang.String",
"java.lang.String"}
);
} catch (MBeanException ex) {
Exception e = ex.getTargetException();
if (e instanceof AlreadyExistsException) {
logger.info("User, " + user.getUsername() + ", already exists.");
ActionErrors errors = new ActionErrors();
errors.add("invalidUserName",
new ActionError("invalid.username.already.exists"));
saveErrors(request, errors);
return mapping.findForward("create.new.admin");
} else {
logger.debug(e);
return mapping.findForward("create.new.admin");
}
}
try {
mBeanServerConnection.invoke(
userEditor, "addMemberToGroup",
new Object[] {"Administrators", user.getUsername()},
new String [] {"java.lang.String", "java.lang.String"}
);
mBeanServerConnection.invoke(
userEditor, "addMemberToGroup",
new Object[] {"MedRecAdmins", user.getUsername()},
new String [] {"java.lang.String", "java.lang.String"}
);
} catch (MBeanException ex) {
Exception e = ex.getTargetException();
if (e instanceof NameNotFoundException) {
logger.info("Invalid Group Name.");
ex.printStackTrace();
return mapping.findForward("create.new.admin");
} else {
logger.debug(e);
return mapping.findForward("create.new.admin");
}
}
logger.info("MedRec Administrator successfully created.");
return mapping.findForward("create.new.admin.successful");
}
While security provider MBeans handle specific aspects of security, such as authentication and authorization, two other MBeans handle general, realm-wide and domain-wide aspects of security:
RealmMBean
represents a security realm. JMX clients can use it to add or remove security providers and to specify such behaviors as whether Web and EJB containers call the security framework on every access or only when security is set in the deployment descriptors.SecurityConfigurationMBean
specifies domain-wide security settings such as connection filters and URL-pattern matching behavior for security constraints, servlets, filters, and virtual-hosts in the WebApp container and external security policies.These two MBeans persist their data in WebLogic Server configuration files. Therefore, to modify attribute values in RealmMBean
or SecurityConfigurationMBean
, you must use the Edit MBean Server and ConfigurationManagerMBean
as described in Managing a Domain's Configuration with JMX.