User: starksm 
  Date: 02/03/22 19:09:29

  Added:       src/main/org/jboss/test/security/service
                        PropertiesVerifierStore.java
                        PropertiesVerifierStoreMBean.java
                        SecurityConfig.java SecurityConfigMBean.java
  Log:
  Services used in the security-srp.sar
  
  Revision  Changes    Path
  1.1                  
jbosstest/src/main/org/jboss/test/security/service/PropertiesVerifierStore.java
  
  Index: PropertiesVerifierStore.java
  ===================================================================
  package org.jboss.test.security.service;
  
  import java.io.FileNotFoundException;
  import java.io.InputStream;
  import java.io.IOException;
  import java.math.BigInteger;
  import java.net.URL;
  import java.security.KeyException;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Properties;
  import javax.naming.InitialContext;
  import javax.naming.Name;
  
  import org.jboss.naming.NonSerializableFactory;
  import org.jboss.security.Util;
  import org.jboss.security.srp.SRPConf;
  import org.jboss.security.srp.SRPVerifierStore;
  import org.jboss.security.srp.SRPVerifierStore.VerifierInfo;
  import org.jboss.system.ServiceMBeanSupport;
  
  /** The PropertiesVerifierStore service is a SRPVerifierStore implementation
   that obtains the username and password info from a properties file and then
   creates an in memory SRPVerifierStore.
  
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public class PropertiesVerifierStore extends ServiceMBeanSupport
     implements PropertiesVerifierStoreMBean, SRPVerifierStore
  {
     private String jndiName = "srp/DefaultVerifierSource";
     private HashMap storeMap = new HashMap();
     private Thread addUserThread;
  
     /** Creates a new instance of PropertiesVerifierStore */
     public PropertiesVerifierStore()
     {
     }
  
     /** Get the jndi name for the SRPVerifierSource implementation binding.
     */
     public String getJndiName()
     {
       return jndiName;
     }
     /** set the jndi name for the SRPVerifierSource implementation binding.
     */
     public void setJndiName(String jndiName)
     {
        this.jndiName = jndiName;
     }
  
     protected void startService() throws Exception
     {
        // Make sure the security utility class is initialized
        Util.init();
  
        // Find the users.properties file
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        URL users = loader.getResource("users.properties");
        if( users == null )
           throw new FileNotFoundException("Failed to find users.properties resource");
        InputStream is = users.openStream();
        final Properties userPasswords = new Properties();
        userPasswords.load(is);
        addUserThread = new Thread("AddUsers")
        {
           public void run()
           {
              Iterator keys = userPasswords.keySet().iterator();
              while( keys.hasNext() )
              {
                 String username = (String) keys.next();
                 char[] password = userPasswords.getProperty(username).toCharArray();
                 addUser(username, password);
              }
           }
        };
        addUserThread.start();
  
        // Bind a reference to the SRPVerifierStore using NonSerializableFactory
        InitialContext ctx = new InitialContext();
        Name name = ctx.getNameParser("").parse(jndiName);
        NonSerializableFactory.rebind(name, this, true);
        log.debug("Bound SRPVerifierStore at "+jndiName);
     }
     protected void stopService() throws Exception
     {
        InitialContext ctx = new InitialContext();
        NonSerializableFactory.unbind(jndiName);
        ctx.unbind(jndiName);
        log.debug("Unbound SRPVerifierStore at "+jndiName);
     }
  
     public VerifierInfo getUserVerifier(String username) throws KeyException, 
IOException
     {
        if( addUserThread != null )
        {
           try
           {
              addUserThread.join();
              addUserThread = null;
           }
           catch(InterruptedException e)
           {
           }
        }
        VerifierInfo info = (VerifierInfo) storeMap.get(username);
        return info;
     }
     public void setUserVerifier(String username, VerifierInfo info) throws IOException
     {
        throw new IOException("PropertiesVerifierStore is read only");
     }
  
     private void addUser(String username, char[] password)
     {
        VerifierInfo info = new VerifierInfo();
        info.username = username;
        // Create a random salt
        long r = Util.nextLong();
        String rs = Long.toHexString(r);
        info.salt = rs.getBytes();
        BigInteger g = SRPConf.getDefaultParams().g();
        BigInteger N = SRPConf.getDefaultParams().N();
  
        info.verifier = Util.calculateVerifier(username, password, info.salt, N, g);
        info.g = g.toByteArray();
        info.N = N.toByteArray();
        storeMap.put(username, info);
     }
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/security/service/PropertiesVerifierStoreMBean.java
  
  Index: PropertiesVerifierStoreMBean.java
  ===================================================================
  package org.jboss.test.security.service;
  
  import org.jboss.system.ServiceMBean;
  
  /** The JMX mbean interface for the SRP password verifier store.
  
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public interface PropertiesVerifierStoreMBean extends ServiceMBean
  {   /** Get the jndi name for the SRPVerifierSource implementation binding.
     */
     public String getJndiName();
     /** set the jndi name for the SRPVerifierSource implementation binding.
     */
     public void setJndiName(String jndiName);
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/security/service/SecurityConfig.java
  
  Index: SecurityConfig.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.test.security.service;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.Hashtable;
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  import javax.security.auth.login.Configuration;
  
  import org.jboss.security.auth.login.XMLLoginConfig;
  import org.jboss.system.ServiceMBeanSupport;
  
  /** A security config mbean that loads an xml login configuration and
   pushes a XMLLoginConfig instance onto the the config stack managed by
   the SecurityConfigName mbean(default=jboss.security:name=SecurityConfig).
   
   @author [EMAIL PROTECTED]
   @version $Revision: 1.1 $
   */
  public class SecurityConfig extends ServiceMBeanSupport
     implements SecurityConfigMBean
  {
     // Constants -----------------------------------------------------
     
     // Attributes ----------------------------------------------------
     private String authConf = "login-config.xml";
     private XMLLoginConfig config = null;
     private ObjectName mainSecurityConfig;
  
     // Static --------------------------------------------------------
  
     // Constructors --------------------------------------------------
     public SecurityConfig()
     {
        setSecurityConfigName("jboss.security:name=SecurityConfig");
     }
  
     public String getName()
     {
        return "JAAS Login Config";
     }
     public String getSecurityConfigName()
     {
        return mainSecurityConfig.toString();
     }
     public void setSecurityConfigName(String objectName)
     {
        try
        {
           mainSecurityConfig = new ObjectName(objectName);
        }
        catch(Exception e)
        {
           log.error("Failed to create ObjectName", e);
        }
     }
  
     /** Get the resource path to the JAAS login configuration file to use.
      */
     public String getAuthConfig()
     {
        return authConf;
     }
  
     /** Set the resource path to the JAAS login configuration file to use.
      The default is "login-config.xml".
      */
     public void setAuthConfig(String authConf)
     {
        this.authConf = authConf;
     }
  
     // Public --------------------------------------------------------
     /** Start the service. This entails 
      */
     protected void startService() throws Exception
     {
        // Look for the authConf as resource
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        URL loginConfig = loader.getResource(authConf);
        if( loginConfig != null )
        {
           log.info("Using JAAS AuthConfig: "+loginConfig.toExternalForm());
           config = new XMLLoginConfig();
           config.setConfig(loginConfig);
           config.start();
           MBeanServer server = super.getServer();
           ObjectName name = super.getServiceName();
           Hashtable props = name.getKeyPropertyList();
           props.put("testConfig", "XMLLoginConfig");
           name = new ObjectName(name.getDomain(), props);
           server.registerMBean(config, name);
           Object[] args = {name.toString()};
           String[] sig = {String.class.getName()};
           server.invoke(mainSecurityConfig, "pushLoginConfig", args, sig);
        }
        else
        {
           log.warn("No AuthConfig resource found");
        }
     }
  
     protected void stopService() throws Exception
     {
        MBeanServer server = super.getServer();
        ObjectName name = super.getServiceName();
        Hashtable props = name.getKeyPropertyList();
        props.put("testConfig", "XMLLoginConfig");
        name = new ObjectName(name.getDomain(), props);
        Object[] args = {};
        String[] sig = {};
        server.invoke(mainSecurityConfig, "popLoginConfig", args, sig);
        server.unregisterMBean(name);
     }
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/security/service/SecurityConfigMBean.java
  
  Index: SecurityConfigMBean.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.test.security.service;
  
  import org.jboss.system.ServiceMBean;
  
  /** An mbean interface for a config service that pushes an xml based
   javax.security.auth.login.Configuration onto the config stack managed by
   the mbean whose name is given by the SecurityConfigName attribute.
  
   @see org.jboss.security.plugins.SecurityConfigMBean
  
   @author [EMAIL PROTECTED]
   @version $Revision: 1.1 $
   */
  public interface SecurityConfigMBean extends ServiceMBean
  {
     /** Get the classpath resource name of the security configuration file */
     public String getAuthConfig();
     /** Set the classpath resource name of the security configuration file */
     public void setAuthConfig(String configURL);
     /** Get the name of the SecurityConfig mbean whose pushLoginConfig and
      popLoginConfig ops will be used to install and remove the xml login config*/
     public String getSecurityConfigName();
     /** Set the name of the SecurityConfig mbean whose pushLoginConfig and
      popLoginConfig ops will be used to install and remove the xml login config*/
     public void setSecurityConfigName(String objectName);
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to