User: d_jencks
  Date: 01/08/18 21:55:29

  Modified:    src/main/org/jboss/resource/security
                        ManyToOnePrincipalMapping.java
                        PrincipalMapping.java PrincipalMappingSupport.java
  Log:
  Converted logging to log4j and prettied format
  
  Revision  Changes    Path
  1.3       +59 -55    
jbosscx/src/main/org/jboss/resource/security/ManyToOnePrincipalMapping.java
  
  Index: ManyToOnePrincipalMapping.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosscx/src/main/org/jboss/resource/security/ManyToOnePrincipalMapping.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ManyToOnePrincipalMapping.java    2001/07/18 14:36:05     1.2
  +++ ManyToOnePrincipalMapping.java    2001/08/19 04:55:29     1.3
  @@ -8,40 +8,37 @@
   
   import java.security.Principal;
   
  -import javax.security.auth.Subject;
  -
   import javax.resource.spi.security.PasswordCredential;
   
  +import javax.security.auth.Subject;
  +
   /**
  - *   A principal mapping that maps all caller principals to a single
  - *   resource principal. Currently only basic password authentication
  - *   is supported.
  + *  A principal mapping that maps all caller principals to a single resource
  + *  principal. Currently only basic password authentication is supported. <p>
    *
  - *   <p> The properties string is expected to contain (in
  - *   <code>Properties.load</code> format) two properties:
  - *   <code>userName</code> and <code>password</code>. These are used
  - *   to construct the <code>PasswordCredential</code> attached to the
  - *   resource principal.
  + *  The properties string is expected to contain (in <code>Properties.load
  + *  </code>format) two properties: <code>userName</code> and <code>password
  + *  </code>. These are used to construct the <code>PasswordCredential</code>
  + *  attached to the resource principal. <p>
    *
  - *   <p> Additionally, the properties can contain a
  - *   <code>principalName</code> property that specifies the name of
  - *   the resource principal. If this property is not set then the
  - *   <code>userName</code> is used.
  + *  Additionally, the properties can contain a <code>principalName</code>
  + *  property that specifies the name of the resource principal. If this property
  + *  is not set then the <code>userName</code> is used.
    *
  - *   @see org.jboss.resource.ConnectionManagerImpl
  - *   @author Toby Allsopp ([EMAIL PROTECTED])
  - *   @version $Revision: 1.2 $
  + * @author     Toby Allsopp ([EMAIL PROTECTED])
  + * @created    August 19, 2001
  + * @see        org.jboss.resource.ConnectionManagerImpl
  + * @version    $Revision: 1.3 $
    */
   public class ManyToOnePrincipalMapping
  -   extends PrincipalMappingSupport
  -{
  +       extends PrincipalMappingSupport {
      // Constants -----------------------------------------------------
   
      // Attributes ----------------------------------------------------
   
      private Principal resourcePrincipal;
  -   private String userName;
  -   private String password;
  +   private String   userName;
  +   private String   password;
   
      // Static --------------------------------------------------------
   
  @@ -51,46 +48,43 @@
   
      // PrincipalMappingSupport overrides -----------------------------
   
  -   public Subject createSubject(Principal callerPrincipal)
  -   {
  -      if (userName == null)
  -      {
  +   public Subject createSubject( Principal callerPrincipal ) {
  +      if ( userName == null ) {
            return null;
         }
   
         Subject subject = new Subject();
  -      subject.getPrincipals().add(resourcePrincipal);
  +      subject.getPrincipals().add( resourcePrincipal );
   
  -      if (metadata.getAuthMechType().equals("BasicPassword"))
  -      {
  +      if ( metadata.getAuthMechType().equals( "BasicPassword" ) ) {
            // The spec says that we need a new instance of this every
            // time, because it is specific to a managed connection
            // factory instance. We could probably get away with caching
            // one per MCF, but who really cares?
            PasswordCredential cred =
  -            new PasswordCredential(userName, password.toCharArray());
  -         cred.setManagedConnectionFactory(mcf);
  -         subject.getPrivateCredentials().add(cred);
  -      }
  -      else
  -      {
  -         throw new RuntimeException("Unsupported authentication-mechanism-type: '" +
  -                                    metadata.getAuthMechType() + "'");
  +               new PasswordCredential( userName, password.toCharArray() );
  +         cred.setManagedConnectionFactory( mcf );
  +         subject.getPrivateCredentials().add( cred );
  +      } else {
  +         throw new RuntimeException( "Unsupported authentication-mechanism-type: '" 
+
  +               metadata.getAuthMechType() + "'" );
         }
   
         return subject;
      }
   
  -   protected void afterSetProperties()
  -   {
  -      userName = (String) properties.get("userName");
  -      password = (String) properties.get("password");
  -      if (password == null) password = "";
  +   protected void afterSetProperties() {
  +      userName = ( String )properties.get( "userName" );
  +      password = ( String )properties.get( "password" );
  +      if ( password == null ) {
  +         password = "";
  +      }
   
  -      String principalName = (String) properties.get("principalName");
  -      if (principalName == null)
  +      String principalName = ( String )properties.get( "principalName" );
  +      if ( principalName == null ) {
            principalName = userName;
  -      resourcePrincipal = new ResourcePrincipal(principalName);
  +      }
  +      resourcePrincipal = new ResourcePrincipal( principalName );
      }
   
      // Package protected ---------------------------------------------
  @@ -101,26 +95,36 @@
   
      // Inner classes -------------------------------------------------
   
  +   /**
  +    * @created    August 19, 2001
  +    */
      private static class ResourcePrincipal
  -      implements Principal
  -   {
  +          implements Principal {
         private final String name;
   
  -      private ResourcePrincipal(String name) { this.name = name; }
  +      private ResourcePrincipal( String name ) {
  +         this.name = name;
  +      }
   
  -      public String getName() { return name; }
  +      public String getName() {
  +         return name;
  +      }
   
  -      public int hashCode() { return name.hashCode(); }
  +      public int hashCode() {
  +         return name.hashCode();
  +      }
   
  -      public boolean equals(Object other)
  -      {
  -         if (other instanceof ResourcePrincipal)
  -            return ((ResourcePrincipal) other).name.equals(name);
  -         else
  +      public boolean equals( Object other ) {
  +         if ( other instanceof ResourcePrincipal ) {
  +            return ( ( ResourcePrincipal )other ).name.equals( name );
  +         } else {
               return false;
  +         }
         }
   
  -      public String toString() { return name; }
  +      public String toString() {
  +         return name;
  +      }
   
      }
   }
  
  
  
  1.2       +41 -38    
jbosscx/src/main/org/jboss/resource/security/PrincipalMapping.java
  
  Index: PrincipalMapping.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosscx/src/main/org/jboss/resource/security/PrincipalMapping.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PrincipalMapping.java     2001/02/06 06:54:41     1.1
  +++ PrincipalMapping.java     2001/08/19 04:55:29     1.2
  @@ -8,71 +8,74 @@
   
   import java.security.Principal;
   
  -import javax.security.auth.Subject;
  -
   import javax.resource.spi.ManagedConnectionFactory;
   
  +import javax.security.auth.Subject;
  +
   import org.jboss.logging.Log;
   import org.jboss.resource.RARMetaData;
   
   /**
  - *   Interface for classes that implement a mapping from caller
  - *   principal to resource principal.
  + *  Interface for classes that implement a mapping from caller principal to
  + *  resource principal. <p>
    *
  - *   <p> The <code>set...</code> methods <strong>must</strong> be
  - *   called before <code>createSubject</code>.
  + *  The <code>set...</code> methods <strong>must</strong> be called before
  + *  <code>createSubject</code> .
    *
  - *   @see org.jboss.resource.ConnectionManagerImpl
  - *   @author Toby Allsopp ([EMAIL PROTECTED])
  - *   @version $Revision: 1.1 $
  + * @author     Toby Allsopp ([EMAIL PROTECTED])
  + * @author     <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  + * @created    August 19, 2001
  + * @see        org.jboss.resource.ConnectionManagerImpl
  + * @version    $Revision: 1.2 $
    */
  -public interface PrincipalMapping
  -{
  +public interface PrincipalMapping {
      // Constants -----------------------------------------------------
   
      // Public --------------------------------------------------------
   
      /**
  -    * Sets the <code>Log</code> to which to log.
  +    *  Sets the <code>name</code> portion of the category for log4j logging.
  +    *
  +    * @param  name  The new Name value
       */
  -   void setLog(Log log);
  +   void setName( String name );
   
      /**
  -    * Sets the managed connection factory for which principals will be
  -    * mapped.
  +    *  Sets the managed connection factory for which principals will be mapped.
  +    *
  +    * @param  mcf  The new ManagedConnectionFactory value
       */
  -   void setManagedConnectionFactory(ManagedConnectionFactory mcf);
  +   void setManagedConnectionFactory( ManagedConnectionFactory mcf );
   
      /**
  -    * Sets the meta-data that describes the resource adapter for which
  -    * principals will be mapped.
  +    *  Sets the meta-data that describes the resource adapter for which
  +    *  principals will be mapped.
  +    *
  +    * @param  metadata  The new RARMetaData value
       */
  -   void setRARMetaData(RARMetaData metadata);
  +   void setRARMetaData( RARMetaData metadata );
   
      /**
  -    * Sets configuration information for a particular implementation
  -    * of this interface. The format of this information is specific to
  -    * each implementation, but it is intended that a sequence of
  -    * name-value pairs in <code>Properties.load</code> format will be
  -    * used.
  +    *  Sets configuration information for a particular implementation of this
  +    *  interface. The format of this information is specific to each
  +    *  implementation, but it is intended that a sequence of name-value pairs in
  +    *  <code>Properties.load</code> format will be used.
       *
  -    * @see java.util.Properties#load
  +    * @param  properties  The new Properties value
  +    * @see                java.util.Properties#load
       */
  -   void setProperties(String properties);
  +   void setProperties( String properties );
   
      /**
  -    * Creates a <code>Subject</code> that contains the resource
  -    * principal and its credentials obtained from the principal
  -    * mapping implementation.
  -    *
  -    * @param callerPrincipal the identity under which the request for
  -    *                        a connection has been made, i.e. the
  -    *                        principal the requesting component is
  -    *                        running under.
  +    *  Creates a <code>Subject</code> that contains the resource principal and
  +    *  its credentials obtained from the principal mapping implementation.
       *
  -    * @return a new <code>Subject</code> instance containing a single
  -    *         principal, the mapped resource principal, and whatever
  -    *         credentials are required for EIS sign-on
  +    * @param  callerPrincipal  the identity under which the request for a
  +    *      connection has been made, i.e. the principal the requesting component
  +    *      is running under.
  +    * @return                  a new <code>Subject</code> instance containing a
  +    *      single principal, the mapped resource principal, and whatever
  +    *      credentials are required for EIS sign-on
       */
  -   Subject createSubject(Principal callerPrincipal);
  +   Subject createSubject( Principal callerPrincipal );
   }
  
  
  
  1.2       +27 -30    
jbosscx/src/main/org/jboss/resource/security/PrincipalMappingSupport.java
  
  Index: PrincipalMappingSupport.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosscx/src/main/org/jboss/resource/security/PrincipalMappingSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PrincipalMappingSupport.java      2001/02/06 06:54:41     1.1
  +++ PrincipalMappingSupport.java      2001/08/19 04:55:29     1.2
  @@ -12,28 +12,29 @@
   
   import javax.resource.spi.ManagedConnectionFactory;
   
  -import org.jboss.logging.Log;
  +import org.jboss.logging.log4j.JBossCategory;
   import org.jboss.resource.RARMetaData;
   
   /**
  - *   Base class for <code>PrincipalMapping</code> implementations that
  - *   want to share some implementation tedium.
  + *  Base class for <code>PrincipalMapping</code> implementations that want to
  + *  share some implementation tedium. <p>
    *
  - *   <p> The implementation of <code>setProperties</code> assumes that
  - *   the properties string is in <code>Properties.load</code> format
  - *   and takes care of converting to a <code>Properties</code> object.
  + *  The implementation of <code>setProperties</code> assumes that the properties
  + *  string is in <code>Properties.load</code> format and takes care of
  + *  converting to a <code>Properties</code> object.
    *
  - *   @author Toby Allsopp ([EMAIL PROTECTED])
  - *   @version $Revision: 1.1 $
  + * @author     Toby Allsopp ([EMAIL PROTECTED])
  + * @author     <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  + * @created    August 19, 2001
  + * @version    $Revision: 1.2 $
    */
   public abstract class PrincipalMappingSupport
  -   implements PrincipalMapping
  -{
  +       implements PrincipalMapping {
      // Constants -----------------------------------------------------
   
      // Attributes ----------------------------------------------------
   
  -   protected Log log;
  +   protected JBossCategory category;
      protected ManagedConnectionFactory mcf;
      protected RARMetaData metadata;
      protected Properties properties;
  @@ -46,31 +47,26 @@
   
      // PrincipalMapping implementation -------------------------------
   
  -   public void setLog(Log log) { this.log = log; }
  +   public void setName( String name ) {
  +      category = ( JBossCategory )JBossCategory.getInstance( getClass().getName() + 
"." + name );
  +   }
   
  -   public void setManagedConnectionFactory(ManagedConnectionFactory mcf)
  -   {
  +   public void setManagedConnectionFactory( ManagedConnectionFactory mcf ) {
         this.mcf = mcf;
      }
   
  -   public void setRARMetaData(RARMetaData metadata)
  -   {
  +   public void setRARMetaData( RARMetaData metadata ) {
         this.metadata = metadata;
      }
   
  -   public void setProperties(String propStr)
  -   {
  +   public void setProperties( String propStr ) {
         properties = new Properties();
  -      try
  -      {
  +      try {
            properties.load(
  -            new ByteArrayInputStream(propStr.getBytes("ISO-8859-1")));
  -      }
  -      catch (IOException ioe)
  -      {
  -         log.error("Couldn't convert properties string '" + propStr + "' to " +
  -                   "Properties");
  -         log.exception(ioe);
  +               new ByteArrayInputStream( propStr.getBytes( "ISO-8859-1" ) ) );
  +      } catch ( IOException ioe ) {
  +         category.error( "Couldn't convert properties string '" + propStr + "' to " 
+
  +               "Properties", ioe );
         }
         afterSetProperties();
      }
  @@ -80,10 +76,11 @@
      // Protected -----------------------------------------------------
   
      /**
  -    * Called once the <code>properties</code> field has been
  -    * initialised and populated.
  +    *  Called once the <code>properties</code> field has been initialised and
  +    *  populated.
       */
  -   protected void afterSetProperties() {}
  +   protected void afterSetProperties() {
  +   }
   
      // Private -------------------------------------------------------
   
  
  
  

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

Reply via email to