User: starksm 
  Date: 01/11/09 02:22:34

  Modified:    src/main/org/jboss/security/plugins Tag: Branch_2_4
                        JaasSecurityDomain.java
  Log:
  Allow the keystore attribute to be a url, file or resource path
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +58 -21    
jbosssx/src/main/org/jboss/security/plugins/Attic/JaasSecurityDomain.java
  
  Index: JaasSecurityDomain.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/plugins/Attic/JaasSecurityDomain.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- JaasSecurityDomain.java   2001/09/26 06:36:35     1.1.2.1
  +++ JaasSecurityDomain.java   2001/11/09 10:22:34     1.1.2.2
  @@ -8,8 +8,9 @@
   
   import java.io.IOException;
   import java.io.File;
  -import java.io.FileNotFoundException;
  -import java.io.FileInputStream;
  +import java.io.InputStream;
  +import java.net.MalformedURLException;
  +import java.net.URL;
   import java.security.KeyStore;
   import javax.management.MBeanServer;
   import javax.management.MBeanServerFactory;
  @@ -24,22 +25,23 @@
   import org.jboss.security.SecurityDomain;
   import org.jboss.util.ServiceMBean;
   
  -/** The JaasSecurityDomain is 
  +/** The JaasSecurityDomain is an extension of JaasSecurityManager that addes
  + the notion of a KeyStore, and JSSE KeyManagerFactory and TrustManagerFactory
  + for supporting SSL and other cryptographic use cases.
    
  -
    @author [EMAIL PROTECTED]
  - @version $Revision: 1.1.2.1 $
  + @version $Revision: 1.1.2.2 $
   */
   public class JaasSecurityDomain extends JaasSecurityManager
      implements SecurityDomain, JaasSecurityDomainMBean
   {
      private int state;
  -   /** The KeyStore associated with the 
  +   /** The KeyStore associated with the security domain.
       */
      private KeyStore keyStore;
      private KeyManagerFactory keyMgr;
      private String keyStoreType = "JKS";
  -   private String keyStoreFile;
  +   private URL keyStoreURL;
      private char[] keyStorePassword;
   
      /** Creates a default JaasSecurityDomain for with a securityDomain
  @@ -84,19 +86,22 @@
      {
         if (getState() != STOPPED)
                return;
  -                     
  +
         state = STARTING;
         log.info("Starting");
  -      if( keyStoreFile != null )
  +      if( keyStoreURL != null )
         {
            keyStore = KeyStore.getInstance(keyStoreType);
  -         FileInputStream fis = new FileInputStream(keyStoreFile);
  -         keyStore.load(fis, keyStorePassword);
  +         InputStream is = keyStoreURL.openStream();
  +         keyStore.load(is, keyStorePassword);
            String algorithm = KeyManagerFactory.getDefaultAlgorithm();
            keyMgr = KeyManagerFactory.getInstance(algorithm);
            keyMgr.init(keyStore, keyStorePassword);
         }
  -      // Register with the
  +      /* Register with the JaasSecurityManagerServiceMBean. This allows this
  +       JaasSecurityDomain to function as the security manager for security-domain
  +       elements that declare java:/jaas/xxx for our security domain name.
  +       */
         MBeanServer server = (MBeanServer) 
MBeanServerFactory.findMBeanServer(null).get(0);
         ObjectName jaasMgr = new 
ObjectName(JaasSecurityManagerServiceMBean.OBJECT_NAME);
         Object[] params = {getSecurityDomain(), this};
  @@ -135,16 +140,48 @@
      {
         this.keyStoreType = type;
      }
  -   public String getKeyStoreFile()
  +   public String getKeyStoreURL()
      {
  -      return this.keyStoreFile;
  -   }
  -   public void setKeyStoreFile(String file) throws IOException
  -   {
  -      this.keyStoreFile = file;
  -      File tst = new File(file);
  -      if( tst.exists() == false )
  -         throw new FileNotFoundException("keystore file does not exist: "+file);
  +      String url = null;
  +      if( keyStoreURL != null )
  +         url = keyStoreURL.toExternalForm();
  +      return url;
  +   }
  +   public void setKeyStoreURL(String storeURL) throws IOException
  +   {
  +      keyStoreURL = null;
  +      // First see if this is a URL
  +      try
  +      {
  +         keyStoreURL = new URL(storeURL);
  +      }
  +      catch(MalformedURLException e)
  +      {
  +         // Not a URL or a protocol without a handler
  +      }
  +
  +      // Next try to locate this as file path
  +      if( keyStoreURL == null )
  +      {
  +         File tst = new File(storeURL);
  +         if( tst.exists() == true )
  +            keyStoreURL = tst.toURL();
  +      }
  +
  +      // Last try to locate this as a classpath resource
  +      if( keyStoreURL == null )
  +      {
  +         ClassLoader loader = Thread.currentThread().getContextClassLoader();
  +         keyStoreURL = loader.getResource(storeURL);
  +      }
  +
  +      // Fail if no valid key store was located
  +      if( keyStoreURL == null )
  +      {
  +         String msg = "Failed to find url="+storeURL+" as a URL, file or resource";
  +         throw new MalformedURLException(msg);
  +      }
  +      log.debug("Using KeyStore="+keyStoreURL.toExternalForm());
      }
      public void setKeyStorePass(String password)
      {
  
  
  

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

Reply via email to