/** * Create a new Group and return the corresponding MBean Name. * * @param groupname Group name of the new group * @param description Description of the new group */ public String createGroup(String groupname, String description) { UserDatabase database = (UserDatabase) this.resource; Group group = database.createGroup(groupname, description); try { MBeanUtils.createMBean(group); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException ("Exception creating group [" + groupname + "] MBean"); iae.initCause(e); throw iae; } return (findGroup(groupname)); }
/** * Create a new Role and return the corresponding MBean Name. * * @param rolename Group name of the new group * @param description Description of the new group */ public String createRole(String rolename, String description) { UserDatabase database = (UserDatabase) this.resource; Role role = database.createRole(rolename, description); try { MBeanUtils.createMBean(role); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException ("Exception creating role [" + rolename + "] MBean"); iae.initCause(e); throw iae; } return (findRole(rolename)); }
/** * Create a new User and return the corresponding MBean Name. * * @param username User name of the new user * @param password Password for the new user * @param fullName Full name for the new user */ public String createUser(String username, String password, String fullName) { UserDatabase database = (UserDatabase) this.resource; User user = database.createUser(username, password, fullName); try { MBeanUtils.createMBean(user); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException ("Exception creating user [" + username + "] MBean"); iae.initCause(e); throw iae; } return (findUser(username)); }
/** * Return the MBean Name for the specified group name (if any); * otherwise return <code>null</code>. * * @param groupname Group name to look up */ public String findGroup(String groupname) { UserDatabase database = (UserDatabase) this.resource; Group group = database.findGroup(groupname); if (group == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedGroup.getDomain(), group); return (oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException ("Cannot create object name for group [" + groupname + "]"); iae.initCause(e); throw iae; } }
/** * Return the MBean Name for the specified role name (if any); * otherwise return <code>null</code>. * * @param rolename Role name to look up */ public String findRole(String rolename) { UserDatabase database = (UserDatabase) this.resource; Role role = database.findRole(rolename); if (role == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedRole.getDomain(), role); return (oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException ("Cannot create object name for role [" + rolename + "]"); iae.initCause(e); throw iae; } }
/** * Return the MBean Name for the specified user name (if any); * otherwise return <code>null</code>. * * @param username User name to look up */ public String findUser(String username) { UserDatabase database = (UserDatabase) this.resource; User user = database.findUser(username); if (user == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user); return (oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException ("Cannot create object name for user [" + username + "]"); iae.initCause(e); throw iae; } }
/** * Remove an existing group and destroy the corresponding MBean. * * @param groupname Group name to remove */ public void removeGroup(String groupname) { UserDatabase database = (UserDatabase) this.resource; Group group = database.findGroup(groupname); if (group == null) { return; } try { MBeanUtils.destroyMBean(group); database.removeGroup(group); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException ("Exception destroying group [" + groupname + "] MBean"); iae.initCause(e); throw iae; } }
/** * Remove an existing role and destroy the corresponding MBean. * * @param rolename Role name to remove */ public void removeRole(String rolename) { UserDatabase database = (UserDatabase) this.resource; Role role = database.findRole(rolename); if (role == null) { return; } try { MBeanUtils.destroyMBean(role); database.removeRole(role); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException ("Exception destroying role [" + rolename + "] MBean"); iae.initCause(e); throw iae; } }
/** * Remove an existing user and destroy the corresponding MBean. * * @param username User name to remove */ public void removeUser(String username) { UserDatabase database = (UserDatabase) this.resource; User user = database.findUser(username); if (user == null) { return; } try { MBeanUtils.destroyMBean(user); database.removeUser(user); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException ("Exception destroying user [" + username + "] MBean"); iae.initCause(e); throw iae; } }
/** * Create, register, and return an MBean for this * <code>UserDatabase</code> object. * * @param userDatabase The UserDatabase to be managed * * @exception Exception if an MBean cannot be created or registered */ static DynamicMBean createMBean(UserDatabase userDatabase) throws Exception { String mname = createManagedName(userDatabase); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); DynamicMBean mbean = managed.createMBean(userDatabase); ObjectName oname = createObjectName(domain, userDatabase); if( mserver.isRegistered( oname )) { mserver.unregisterMBean(oname); } mserver.registerMBean(mbean, oname); return (mbean); }
/** * Deregister the MBean for this * <code>UserDatabase</code> object. * * @param userDatabase The UserDatabase to be managed * * @exception Exception if an MBean cannot be deregistered * @deprecated Unused. Will be removed in Tomcat 8.0.x */ @Deprecated static void destroyMBean(UserDatabase userDatabase) throws Exception { String mname = createManagedName(userDatabase); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, userDatabase); if( mserver.isRegistered(oname) ) mserver.unregisterMBean(oname); }
/** * Prepare for the beginning of active use of the public methods of this * component and implement the requirements of * {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected void startInternal() throws LifecycleException { try { Context context = getServer().getGlobalNamingContext(); database = (UserDatabase) context.lookup(resourceName); } catch (Throwable e) { ExceptionUtils.handleThrowable(e); containerLog.error(sm.getString("userDatabaseRealm.lookup", resourceName), e); database = null; } if (database == null) { throw new LifecycleException (sm.getString("userDatabaseRealm.noDatabase", resourceName)); } super.startInternal(); }
/** * Create a new Group and return the corresponding MBean Name. * * @param groupname Group name of the new group * @param description Description of the new group */ public String createGroup(String groupname, String description) { UserDatabase database = (UserDatabase) this.resource; Group group = database.createGroup(groupname, description); /* if (roles != null) { for (int i = 0; i < roles.length; i++) { Role role = database.findRole(roles[i]); if (role == null) { createRole(roles[i], null); role = database.findRole(roles[i]); } group.addRole(role); } } */ try { MBeanUtils.createMBean(group); } catch (Exception e) { throw new IllegalArgumentException("Exception creating group " + group + " MBean: " + e); } return (findGroup(groupname)); }
/** * Return the MBean Name for the specified group name (if any); * otherwise return <code>null</code>. * * @param groupname Group name to look up */ public String findGroup(String groupname) { UserDatabase database = (UserDatabase) this.resource; Group group = database.findGroup(groupname); if (group == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedGroup.getDomain(), group); return (oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException ("Cannot create object name for group " + group); } }
/** * Return the MBean Name for the specified role name (if any); * otherwise return <code>null</code>. * * @param rolename Role name to look up */ public String findRole(String rolename) { UserDatabase database = (UserDatabase) this.resource; Role role = database.findRole(rolename); if (role == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedRole.getDomain(), role); return (oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException ("Cannot create object name for role " + role); } }
/** * Return the MBean Name for the specified user name (if any); * otherwise return <code>null</code>. * * @param username User name to look up */ public String findUser(String username) { UserDatabase database = (UserDatabase) this.resource; User user = database.findUser(username); if (user == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user); return (oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException ("Cannot create object name for user " + user); } }
/** * Remove an existing group and destroy the corresponding MBean. * * @param groupname Group name to remove */ public void removeGroup(String groupname) { UserDatabase database = (UserDatabase) this.resource; Group group = database.findGroup(groupname); if (group == null) { return; } try { MBeanUtils.destroyMBean(group); database.removeGroup(group); } catch (Exception e) { throw new IllegalArgumentException("Exception destroying group " + group + " MBean: " + e); } }
/** * Remove an existing role and destroy the corresponding MBean. * * @param rolename Role name to remove */ public void removeRole(String rolename) { UserDatabase database = (UserDatabase) this.resource; Role role = database.findRole(rolename); if (role == null) { return; } try { MBeanUtils.destroyMBean(role); database.removeRole(role); } catch (Exception e) { throw new IllegalArgumentException("Exception destroying role " + role + " MBean: " + e); } }
/** * Remove an existing user and destroy the corresponding MBean. * * @param username User name to remove */ public void removeUser(String username) { UserDatabase database = (UserDatabase) this.resource; User user = database.findUser(username); if (user == null) { return; } try { MBeanUtils.destroyMBean(user); database.removeUser(user); } catch (Exception e) { throw new IllegalArgumentException("Exception destroying user " + user + " MBean: " + e); } }
/** * Create, register, and return an MBean for this * <code>UserDatabase</code> object. * * @param userDatabase The UserDatabase to be managed * * @exception Exception if an MBean cannot be created or registered */ public static ModelMBean createMBean(UserDatabase userDatabase) throws Exception { String mname = createManagedName(userDatabase); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ModelMBean mbean = managed.createMBean(userDatabase); ObjectName oname = createObjectName(domain, userDatabase); mserver.registerMBean(mbean, oname); return (mbean); }
/** * Deregister the MBean for this * <code>UserDatabase</code> object. * * @param userDatabase The UserDatabase to be managed * * @exception Exception if an MBean cannot be deregistered */ public static void destroyMBean(UserDatabase userDatabase) throws Exception { String mname = createManagedName(userDatabase); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, userDatabase); mserver.unregisterMBean(oname); }
/** * Prepare for active use of the public methods of this Component. * * @exception LifecycleException if this component detects a fatal error * that prevents it from being started */ public synchronized void start() throws LifecycleException { try { StandardServer server = (StandardServer) ServerFactory.getServer(); Context context = server.getGlobalNamingContext(); database = (UserDatabase) context.lookup(resourceName); } catch (Throwable e) { e.printStackTrace(); log(sm.getString("userDatabaseRealm.lookup", resourceName), e); database = null; } if (database == null) { throw new LifecycleException (sm.getString("userDatabaseRealm.noDatabase", resourceName)); } // Perform normal superclass initialization super.start(); }
/** * Create a new Group and return the corresponding MBean Name. * * @param groupname * Group name of the new group * @param description * Description of the new group */ public String createGroup(String groupname, String description) { UserDatabase database = (UserDatabase) this.resource; Group group = database.createGroup(groupname, description); try { MBeanUtils.createMBean(group); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException( "Exception creating group [" + groupname + "] MBean"); iae.initCause(e); throw iae; } return (findGroup(groupname)); }
/** * Create a new Role and return the corresponding MBean Name. * * @param rolename * Group name of the new group * @param description * Description of the new group */ public String createRole(String rolename, String description) { UserDatabase database = (UserDatabase) this.resource; Role role = database.createRole(rolename, description); try { MBeanUtils.createMBean(role); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException( "Exception creating role [" + rolename + "] MBean"); iae.initCause(e); throw iae; } return (findRole(rolename)); }
/** * Create a new User and return the corresponding MBean Name. * * @param username * User name of the new user * @param password * Password for the new user * @param fullName * Full name for the new user */ public String createUser(String username, String password, String fullName) { UserDatabase database = (UserDatabase) this.resource; User user = database.createUser(username, password, fullName); try { MBeanUtils.createMBean(user); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException( "Exception creating user [" + username + "] MBean"); iae.initCause(e); throw iae; } return (findUser(username)); }
/** * Return the MBean Name for the specified group name (if any); otherwise * return <code>null</code>. * * @param groupname * Group name to look up */ public String findGroup(String groupname) { UserDatabase database = (UserDatabase) this.resource; Group group = database.findGroup(groupname); if (group == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedGroup.getDomain(), group); return (oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException( "Cannot create object name for group [" + groupname + "]"); iae.initCause(e); throw iae; } }
/** * Return the MBean Name for the specified role name (if any); otherwise * return <code>null</code>. * * @param rolename * Role name to look up */ public String findRole(String rolename) { UserDatabase database = (UserDatabase) this.resource; Role role = database.findRole(rolename); if (role == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedRole.getDomain(), role); return (oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException( "Cannot create object name for role [" + rolename + "]"); iae.initCause(e); throw iae; } }
/** * Return the MBean Name for the specified user name (if any); otherwise * return <code>null</code>. * * @param username * User name to look up */ public String findUser(String username) { UserDatabase database = (UserDatabase) this.resource; User user = database.findUser(username); if (user == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user); return (oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException( "Cannot create object name for user [" + username + "]"); iae.initCause(e); throw iae; } }