Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » security » plugins » [javadoc | source]
    1   /*
    2   * JBoss, Home of Professional Open Source
    3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
    4   * by the @authors tag. See the copyright.txt in the distribution for a
    5   * full listing of individual contributors.
    6   *
    7   * This is free software; you can redistribute it and/or modify it
    8   * under the terms of the GNU Lesser General Public License as
    9   * published by the Free Software Foundation; either version 2.1 of
   10   * the License, or (at your option) any later version.
   11   *
   12   * This software is distributed in the hope that it will be useful,
   13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   15   * Lesser General Public License for more details.
   16   *
   17   * You should have received a copy of the GNU Lesser General Public
   18   * License along with this software; if not, write to the Free
   19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   21   */
   22   package org.jboss.security.plugins;
   23   
   24   import javax.naming.InvalidNameException;
   25   import javax.naming.NamingException;
   26   import javax.security.auth.Subject;
   27   
   28   import org.jboss.security.AuthorizationManager;
   29   import org.jboss.security.RealmMapping;
   30   import org.jboss.security.AuthenticationManager;
   31   import org.jboss.security.SubjectSecurityManager;
   32   import org.jboss.security.audit.AuditManager;
   33   import org.jboss.security.identitytrust.IdentityTrustManager;
   34   import org.jboss.security.mapping.MappingManager;
   35   import org.jboss.util.CachePolicy;
   36   
   37   /** An encapsulation of the JNDI security context information
   38    *
   39    * @author  Scott.Stark@jboss.org
   40    * @author  Anil.Saldhana@jboss.org
   41    * @version 
   42    */
   43   public class SecurityDomainContext
   44   {
   45      static final String ACTIVE_SUBJECT = "subject";
   46      static final String AUTHENTICATION_MGR = "authenticationMgr";
   47      static final String SECURITY_MGR = "securityMgr";
   48      static final String REALM_MAPPING = "realmMapping";
   49      static final String AUTHORIZATION_MGR = "authorizationMgr";
   50      static final String AUDIT_MGR = "auditMgr";
   51      static final String MAPPING_MGR = "mappingMgr";
   52      static final String IDENTITY_TRUST_MGR = "identityTrustMgr";
   53      static final String AUTH_CACHE = "authenticationCache";
   54      static final String DOMAIN_CONTEXT = "domainContext";
   55   
   56      AuthenticationManager securityMgr;
   57      AuthorizationManager authorizationMgr;
   58      CachePolicy authenticationCache;
   59      AuditManager auditMgr;
   60      MappingManager mappingMgr;
   61      IdentityTrustManager identityTrustMgr;
   62   
   63      /** Creates new SecurityDomainContextHandler */
   64      public SecurityDomainContext(AuthenticationManager securityMgr, 
   65            CachePolicy authenticationCache)
   66      {
   67         this.securityMgr = securityMgr;
   68         this.authenticationCache = authenticationCache; 
   69      }
   70   
   71      public Object lookup(String name) throws NamingException
   72      {
   73         Object binding = null;
   74         if( name == null || name.length() == 0 )
   75            throw new InvalidNameException("name cannot be null or empty");
   76   
   77         if( name.equals(ACTIVE_SUBJECT) )
   78            binding = getSubject();
   79         else if( name.equals(AUTHENTICATION_MGR) || name.equals(SECURITY_MGR))
   80            binding = securityMgr;
   81         else if( name.equals(REALM_MAPPING) )
   82            binding = getRealmMapping();
   83         else if( name.equals(AUTHORIZATION_MGR) )
   84            binding = getAuthorizationManager();
   85         else if( name.equals(AUDIT_MGR) )
   86            binding = this.getAuditMgr();
   87         else if( name.equals(MAPPING_MGR) )
   88            binding = this.getMappingMgr();
   89         else if( name.equals(IDENTITY_TRUST_MGR) )
   90            binding = this.getIdentityTrustMgr();
   91         else if( name.equals(AUTH_CACHE) )
   92            binding = authenticationCache;
   93         else if( name.equals(DOMAIN_CONTEXT) )
   94            binding = this;
   95            
   96         return binding;
   97      }
   98      public Subject getSubject()
   99      {
  100         Subject subject = null;
  101         if( securityMgr instanceof SubjectSecurityManager )
  102         {
  103            subject = ((SubjectSecurityManager)securityMgr).getActiveSubject();
  104         }
  105         return subject;
  106      }
  107      public AuthenticationManager getSecurityManager()
  108      {
  109         return securityMgr;
  110      }
  111      public RealmMapping getRealmMapping()
  112      {
  113         RealmMapping realmMapping = null;
  114         if(authorizationMgr != null && authorizationMgr instanceof RealmMapping)
  115         {
  116            realmMapping = (RealmMapping)authorizationMgr;
  117         }
  118         else
  119         if( securityMgr instanceof RealmMapping )
  120         {
  121            realmMapping = (RealmMapping)securityMgr;
  122         }
  123         return realmMapping;
  124      }
  125      
  126      public void setAuthenticationManager(AuthenticationManager aum)
  127      {
  128         this.securityMgr = aum;
  129      }
  130      
  131      public void setAuthorizationManager(AuthorizationManager am)
  132      {
  133         this.authorizationMgr = am;
  134      }
  135      
  136      public AuthorizationManager getAuthorizationManager()
  137      {
  138         return authorizationMgr;
  139      }
  140      
  141      public void setAuthenticationCache(CachePolicy cp)
  142      {
  143         this.authenticationCache = cp;
  144      }
  145       
  146      public CachePolicy getAuthenticationCache()
  147      {
  148         return authenticationCache;
  149      }
  150   
  151      public AuditManager getAuditMgr()
  152      {
  153         return auditMgr;
  154      }
  155   
  156      public void setAuditMgr(AuditManager auditMgr)
  157      {
  158         this.auditMgr = auditMgr;
  159      }
  160   
  161      public MappingManager getMappingMgr()
  162      {
  163         return mappingMgr;
  164      }
  165   
  166      public void setMappingMgr(MappingManager mappingMgr)
  167      {
  168         this.mappingMgr = mappingMgr;
  169      }
  170   
  171      public IdentityTrustManager getIdentityTrustMgr()
  172      {
  173         return identityTrustMgr;
  174      }
  175   
  176      public void setIdentityTrustMgr(IdentityTrustManager identityTrustMgr)
  177      {
  178         this.identityTrustMgr = identityTrustMgr;
  179      } 
  180   }

Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » security » plugins » [javadoc | source]