Methods Summary |
---|
private void | EmitUserMgmtEvent(int action, java.lang.String user, java.lang.String[] groups)
try
{
AdminContext adminContext = MBeanRegistryFactory.getAdminContext();
String instanceName = adminContext.getServerName();
String name = (String)getAttribute(ServerTags.NAME);
UserMgmtEvent event = new UserMgmtEvent(instanceName, name, action, user, groups);
event.setTargetDestination(getParentConfigName());
EventContext.addEvent(event);
}
catch (Exception e)
{
throw new MBeanConfigException(e.getMessage());
}
|
public void | addUser(java.lang.String userName, java.lang.String password, java.lang.String[] groupList)Adds new user to file realm. User cannot exist already.
checkFileTypeRealm();
FileRealm realm = getRealmKeyFile();
try
{
realm.addUser(userName, password, groupList);
saveInstanceRealmKeyFile(realm);
}
catch(BadRealmException bre)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
throw new MBeanConfigException(bre.getMessage());
}
catch(IASSecurityException ise)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.security_exception", mInstanceName, userName, bre.getMessage());
throw new MBeanConfigException(ise.getMessage());
}
EmitUserMgmtEvent(UserMgmtEvent.ACTION_USERADD, userName, groupList);
|
private void | checkFileTypeRealm()
String className = null;
try
{
className = (String)getAttribute(ServerTags.CLASSNAME);
}
catch (Exception e)
{}
if( className==null ||
!className.equals("com.sun.enterprise.security.auth.realm.file.FileRealm"))
{
String msg = localStrings.getString("authRealmMBean.unsupported_type");
throw new MBeanConfigException(msg);
}
|
private java.lang.String[] | convertEnumerationToStringArray(java.util.Enumeration ee)
ArrayList list = new ArrayList();
while(ee.hasMoreElements())
list.add(ee.nextElement());
return (String[])list.toArray(new String[list.size()]);
|
public java.lang.String[] | getGroupNames()Returns names of all the groups from the instance realm keyfile
checkFileTypeRealm();
FileRealm realm = getRealmKeyFile();
try
{
return convertEnumerationToStringArray(realm.getGroupNames());
}
catch(BadRealmException bre)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
throw new MBeanConfigException(bre.getMessage());
}
|
private java.lang.String | getName()
return (String)getAttribute(ServerTags.NAME);
|
private java.lang.String | getParentConfigName()
return MBeanHelper.getLocation((ModelMBeanInfo)this.getMBeanInfo())[1];
|
private java.lang.String | getProperty(java.lang.String name)
try
{
String unresolved = (String)invoke("getPropertyValue", new Object[]{name}, new String[]{"java.lang.String"});
//This needs to be changed for SE/EE. The instanceName cant
//be assumed to be the das server instance name.
final String instanceName = MBeanRegistryFactory.getAdminContext().
getServerName();
final String resolved = new PropertyResolver(getConfigContext(),
instanceName).resolve(unresolved);
return resolved;
}
catch (Exception e)
{
return null;
}
|
private com.sun.enterprise.security.auth.realm.file.FileRealm | getRealmKeyFile()
try
{
/*
String name = (String)getAttribute(ServerTags.NAME);
Realm realm = Realm.getInstance(name);
if(realm==null)
{
String msg = localStrings.getString("authRealmMBean.realm_not_registered", name);
throw new MBeanConfigException(msg);
}
if(!(realm instanceof FileRealm))
{
String msg = localStrings.getString("authRealmMBean.unsupported_type");
throw new MBeanConfigException(msg);
}
return (FileRealm)realm;
*/
return new FileRealm(getRealmKeyFileName());
}
// catch(MBeanConfigException mce)
// {
// throw mce;
// }
catch(Exception e)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
throw new MBeanConfigException(e.getMessage());
}
/* catch(BadRealmException bre)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
throw new MBeanConfigException(bre.getMessage());
}
catch(NoSuchRealmException nsr)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_realm", mInstanceName);
throw new MBeanConfigException(nsr.getMessage());
}
*/
|
private java.lang.String | getRealmKeyFileName()
return getProperty(FILE_NAME_PROPERTY);
|
public java.lang.String[] | getUserGroupNames(java.lang.String userName)Returns the name of all the groups that this user belongs to from the instance realm keyfile
if(userName==null)
return getGroupNames();
checkFileTypeRealm();
FileRealm realm = getRealmKeyFile();
try
{
return convertEnumerationToStringArray(realm.getGroupNames(userName));
}
catch(NoSuchUserException nse)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_user", mInstanceName, userName);
throw new MBeanConfigException(nse.getMessage());
}
|
public java.lang.String[] | getUserNames()Returns names of all the users from instance realm keyfile
checkFileTypeRealm();
FileRealm realm = getRealmKeyFile();
try
{
return convertEnumerationToStringArray(realm.getUserNames());
}
catch(BadRealmException bre)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
throw new MBeanConfigException(bre.getMessage());
}
|
private boolean | isAdminRealm()
final String name = (String) getAttribute(ServerTags.NAME);
if (ADMIN_REALM.equals(name))
return ( true ) ;
return ( false );
|
private boolean | isBelogsTo(java.util.Enumeration ee, java.lang.Object objectToCheck)
while(ee.hasMoreElements())
if(ee.nextElement().equals(objectToCheck))
return true;
return false;
|
private boolean | isBelogsTo(java.lang.Object[] arr, java.lang.Object objectToCheck)
for(int i=0; i<arr.length; i++)
if(objectToCheck.equals(arr[i]))
return true;
return false;
|
private boolean | isLastAdminUser(java.lang.String userName)
return (isSystemAdminRealm() &&
isUserLastInGroup(userName,AdminConstants.DOMAIN_ADMIN_GROUP_NAME));
|
private boolean | isOk(java.lang.String s)
return ( s != null && s.length() != 0 );
|
private boolean | isSystemAdminRealm()Check if this is the last admin user in DAS admin-auth
try {
Server das = ServerHelper.getDAS(getConfigContext());
String dasConfigName = das.getConfigRef();
if(!getParentConfigName().equals(dasConfigName))
return false; //from another config
JmxConnector jmxc = ServerHelper.getServerSystemConnector(
getConfigContext(),
das.getName());
return jmxc.getAuthRealmName().equals(getName());
} catch (Exception e) {
throw new MBeanConfigException(e.getMessage());
}
|
private boolean | isUserLastInGroup(java.lang.String userName, java.lang.String groupName)
checkFileTypeRealm();
FileRealm realm = getRealmKeyFile();
try
{
if(!isBelogsTo(realm.getGroupNames(userName), groupName))
return false; // user not in the group at all
Enumeration users = realm.getUserNames();
while(users.hasMoreElements())
{
String user = (String)users.nextElement();
if(!userName.equals(user) &&
isBelogsTo(realm.getGroupNames(user), groupName))
return false;
}
}
catch(Exception nse)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_user", mInstanceName, userName);
throw new MBeanConfigException(nse.getMessage());
}
return true;
|
private void | logDetailsIfAdminRealm()
try
{
if (isAdminRealm()) {
//choosing WARNING as the log-level
final ConfigContext cc = super.getConfigContext();
final String nas = NodeAgentHelper.getNodeAgentsAsString(NodeAgentHelper.getNodeAgentsInDomain(cc));
final String sas = ServerHelper.getServersAsString(ServerHelper.getServersInDomainExcludingDAS(cc));
String msg, params[];
if (isOk(nas) && isOk(sas)) {
params = new String[]{ADMIN_REALM, nas, sas};
msg = localStrings.getString("admin.password.change_all_msg", params);
_sLogger.log(Level.WARNING, msg, params);
} else if (isOk(nas) && !isOk(sas)) {
params = new String[]{ADMIN_REALM, nas};
msg = localStrings.getString("admin.password.change_das_na_msg", params);
_sLogger.log(Level.WARNING, msg, params);
} else if (!isOk(nas) && !isOk(sas)) {
params = new String[]{ADMIN_REALM};
msg = localStrings.getString("admin.password.change_das_alone_msg", params);
_sLogger.log(Level.WARNING, msg, params);
}
}
} catch(final Exception e)
{
throw new RuntimeException(e);
}
|
public void | removeUser(java.lang.String userName)Remove user from file realm. User must exist.
checkFileTypeRealm();
if(isLastAdminUser(userName))
{
String msg = localStrings.getString("authRealmMBean.removeLastAdminUser",
AdminConstants.DOMAIN_ADMIN_GROUP_NAME);
throw new MBeanConfigException(msg);
}
FileRealm realm = getRealmKeyFile();
try
{
realm.removeUser(userName);
saveInstanceRealmKeyFile(realm);
}
catch(NoSuchUserException nse)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_user", mInstanceName, userName);
throw new MBeanConfigException(nse.getMessage());
}
EmitUserMgmtEvent(UserMgmtEvent.ACTION_USERREMOVE, userName, null);
|
private void | saveInstanceRealmKeyFile(com.sun.enterprise.security.auth.realm.file.FileRealm realm)
try
{
final String filePath = getRealmKeyFileName();
_sLogger.log(Level.INFO, "filerealm.write", filePath);
realm.writeKeyFile(filePath);
}
catch(IOException ioe)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.realm_io_error", mInstanceName);
_sLogger.log(Level.WARNING, "filerealm.writeerror", ioe);
throw new MBeanConfigException(ioe.getMessage());
}
/* catch(BadRealmException bre)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
throw new MBeanConfigException(bre.getMessage());
}
*/
|
public void | updateUser(java.lang.String userName, java.lang.String password, java.lang.String[] groupList)Update data for an existing user. User must exist. This is equivalent to calling removeUser() followed by addUser().
checkFileTypeRealm();
if(!isBelogsTo(groupList, AdminConstants.DOMAIN_ADMIN_GROUP_NAME) &&
isLastAdminUser(userName))
{
String msg = localStrings.getString("authRealmMBean.removeLastAdminUser",
AdminConstants.DOMAIN_ADMIN_GROUP_NAME);
throw new MBeanConfigException(msg);
}
FileRealm realm = getRealmKeyFile();
try
{
realm.updateUser(userName, userName, password, groupList);
saveInstanceRealmKeyFile(realm);
logDetailsIfAdminRealm();
}
catch(BadRealmException bre)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
throw new MBeanConfigException(bre.getMessage());
}
catch(NoSuchUserException nse)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_user", mInstanceName, userName);
throw new MBeanConfigException(nse.getMessage());
}
catch(IASSecurityException ise)
{
//String msg = localStrings.getString( "admin.server.core.mbean.config.security_exception", mInstanceName, userName, bre.getMessage());
throw new MBeanConfigException(ise.getMessage());
}
EmitUserMgmtEvent(UserMgmtEvent.ACTION_USERUPDATE, userName, groupList);
|