Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » security » plugins » [javadoc | source]
    1   /*
    2    * JBoss, the OpenSource J2EE webOS
    3    *
    4    * Distributable under LGPL license.
    5    * See terms of license at gnu.org.
    6    */
    7   package org.jboss.security.plugins;
    8   
    9   import java.io.Serializable;
   10   import java.util.HashSet;
   11   import java.util.Set;
   12   import java.security.Principal;
   13   import javax.security.auth.Subject;
   14   
   15   import org.jboss.security.AnybodyPrincipal;
   16   import org.jboss.security.RealmMapping;
   17   import org.jboss.security.SubjectSecurityManager;
   18   
   19   
   20   /** An implementation of SubjectSecurityManager, RealmMapping that authenticates
   21   everyone and for which Principals have any role requested. It can be used
   22   as a pass-through security manager when you want noop security.
   23   
   24   @see #isValid(Principal, Object)
   25   @see #Principal getPrincipal(Principal)
   26   @see #doesUserHaveRole(Principal, Set)
   27   
   28   @author <a href="mailto:Scott_Stark@displayscape.com">Scott Stark</a>.
   29   @version $Revision: 1.4.4.1 $
   30   */
   31   public class NullSecurityManager
   32       implements SubjectSecurityManager, RealmMapping, Serializable
   33   {
   34       private String securityDomain;
   35   
   36       /** Creates a default JaasSecurityManager for with the
   37           given securityDomain name.
   38       */
   39       public NullSecurityManager(String securityDomain)
   40       {
   41           this.securityDomain = securityDomain;
   42       }
   43   
   44       /** Get the name of the security domain associated with this security mgr.
   45           @return Name of the security manager security domain.
   46        */
   47       public String getSecurityDomain()
   48       {
   49           return securityDomain;
   50       }
   51       /** Get the currently authenticated Subject.
   52           @return Always returns null.
   53        */
   54       public Subject getActiveSubject()
   55       {
   56           return null;
   57       }
   58   
   59       /** Validate that the given credential is correct for principal.
   60       @return always returns true.
   61        */
   62       public boolean isValid(Principal principal, Object credential)
   63       {
   64           return true;
   65       }
   66       /** Validate that the given credential is correct for principal. This does
   67        not populate the activeSubject with any state since no authentication
   68        is performed.
   69       @return always returns true.
   70        */
   71       public boolean isValid(Principal principal, Object credential,
   72         Subject activeSubject)
   73       {
   74          return true;
   75       }
   76   
   77       /** Always returns the argument principal.
   78       @return The argument principal
   79        */
   80       public Principal getPrincipal(Principal principal)
   81       {
   82           Principal result = principal;
   83           return result;
   84       }
   85   
   86       /** Does the current Subject have a role(a Principal) that equates to one
   87           of the role names. This method always returns true.
   88       @param principal, ignored.
   89       @param roleNames, ignored.
   90       @return Always returns true.
   91       */
   92       public boolean doesUserHaveRole(Principal principal, Set roleNames)
   93       {
   94           boolean hasRole = true;
   95           return hasRole;
   96       }
   97   
   98       /** Return the set of domain roles the principal has been assigned.
   99       @return The Set<Principal> with the AnybodyPrincipal as the sole role.
  100        */
  101       public Set getUserRoles(Principal principal)
  102       {
  103           HashSet roles = new HashSet();
  104           roles.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
  105           return roles;
  106       }
  107   
  108       /** Authenticate principal against credential
  109        * @param principal, the user id to authenticate
  110        * @param credential, an opaque credential.
  111        * @return Always returns true.
  112        */
  113       private boolean authenticate(Principal principal, Object credential)
  114       {
  115           boolean authenticated = true;
  116           return authenticated;
  117       }
  118   }

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