Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */ 
  package org.jboss.security.plugins;
  
  import static org.jboss.security.SecurityConstants.ROLES_IDENTIFIER;
 
 import java.util.Map;
 
 
 import  org.jboss.logging.Logger;
 import  org.jboss.security.AuthenticationManager;
 import  org.jboss.security.AuthorizationManager;
 import  org.jboss.security.ISecurityManagement;
 import  org.jboss.security.RunAs;
 import  org.jboss.security.SecurityConstants;
 import  org.jboss.security.SecurityContext;
 import  org.jboss.security.SecurityContextFactory;
 import  org.jboss.security.SecurityContextUtil;
 import  org.jboss.security.SecurityManagerLocator;
 import  org.jboss.security.SubjectInfo;
 import  org.jboss.security.audit.AuditManager;
 import  org.jboss.security.identitytrust.IdentityTrustManager;
 import  org.jboss.security.mapping.MappingManager;

Implementation of the Security Context for the JBoss AS

Author(s):
Anil Saldhana
Version:
$Revision$
Since:
Aug 30, 2006
 
 public class JBossSecurityContext implements SecurityContext, SecurityManagerLocator
 {   
    private static final long serialVersionUID = 1L;
    
    //Define Security Permissions
    
    private static final RuntimePermission getDataPermission
      = new RuntimePermission(JBossSecurityContext.class.getName() + ".getData");
    
    private static final RuntimePermission getSubjectInfoPermission
      = new RuntimePermission(JBossSecurityContext.class.getName() + ".getSubjectInfo");
 
    private static final RuntimePermission setRolesPermission
      = new RuntimePermission(JBossSecurityContext.class.getName() + ".setRolesPermission");
    
    private static final RuntimePermission setRunAsPermission
      = new RuntimePermission(JBossSecurityContext.class.getName() + ".setRunAsPermission");
    
    private static final RuntimePermission setSubjectInfoPermission
    = new RuntimePermission(JBossSecurityContext.class.getName() + ".setSubjectInfo");
  
    private static final RuntimePermission getSecurityManagementPermission
      = new RuntimePermission(JBossSecurityContext.class.getName() + ".getSecurityManagement");
    
    private static final RuntimePermission setSecurityManagementPermission
      = new RuntimePermission(JBossSecurityContext.class.getName() + ".setSecurityManagement");
    
    private static final RuntimePermission setSecurityDomainPermission
      = new RuntimePermission(JBossSecurityContext.class.getName() + ".setSecurityDomain");
 
    protected static final Logger log = Logger.getLogger(JBossSecurityContext.class); 
    protected boolean trace = .isTraceEnabled();  
    
    protected Map<String,ObjectcontextData = new HashMap<String,Object>();
    
    protected String securityDomain = SecurityConstants.DEFAULT_APPLICATION_POLICY;
 
    protected SubjectInfo subjectInfo = null;
     
    protected RunAs incomingRunAs = null;
    protected RunAs outgoingRunAs = null;
    
    protected ISecurityManagement iSecurityManagement;
    
    protected transient CallbackHandler callbackHandler = new JBossCallbackHandler(); 
    
    protected transient SecurityContextUtil util = null;
    
    public JBossSecurityContext(String securityDomain)
    {
       this. = securityDomain;
       if(this. == null)
          this. = new JBossCallbackHandler();
       
        = getUtil();
       //Create a null subjectinfo as default
       .createSubjectInfo(nullnullnull);
    }
   

   

Throws:
SecurityException Under a security manager, caller does not have RuntimePermission("org.jboss.security.plugins.JBossSecurityContext.getSecurityManagement")
See also:
SecurityContext.getSecurityManagement()
   public ISecurityManagement getSecurityManagement()
   {
      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
      
      return this.;
   }

   

Throws:
SecurityException Under a security manager, caller does not have RuntimePermission("org.jboss.security.plugins.JBossSecurityContext.setSecurityManagement")
See also:
SecurityContext.setSecurityManagement(ISecurityManagement)
   public void setSecurityManagement(ISecurityManagement ism)
   {
      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
      
      if(ism == null)
         throw new IllegalArgumentException("ism is null");
      this. = ism;  
   }
  
   

Throws:
SecurityException Under a security manager, caller does not have RuntimePermission("org.jboss.security.plugins.JBossSecurityContext.getData")
See also:
SecurityContext.getData()
 
   public Map<String,ObjectgetData()
   { 
      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
         sm.checkPermission();
    
      return ;
   }
 
   
Get the security domain name
   public String getSecurityDomain()
   { 
      return ;
   }
 
   /*
    * (non-Javadoc)
    * @see org.jboss.security.SecurityContext#setSecurityDomain(java.lang.String)
    */
   public void setSecurityDomain(String domain)
   {
      SecurityManager manager = System.getSecurityManager();
      if(manager != null)
      
      if (domain == null)
         throw new IllegalArgumentException("Security domain cannot be null");
      this. = domain;
   }

   

Throws:
SecurityException Under a security manager, caller does not have RuntimePermission("org.jboss.security.plugins.JBossSecurityContext.getSubjectInfo")
See also:
SecurityContext.getSubjectInfo()
   public SubjectInfo getSubjectInfo()
   { 
      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
      
      return ;
   } 
   
   

See also:
SecurityContext.getOutgoingRunAs()
   public RunAs getIncomingRunAs()
   { 
      return this.;
   }

   

Throws:
SecurityException Under a security manager, caller does not have RuntimePermission("org.jboss.security.plugins.JBossSecurityContext.setRunAsPermission")
See also:
SecurityContext.setOutgoingRunAs(RunAs)
   public void setIncomingRunAs(RunAs runAs)
   { 
      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
         sm.checkPermission();
      
      this. = runAs;
   } 

   

See also:
SecurityContext.getOutgoingRunAs()
   public RunAs getOutgoingRunAs()
   { 
      return this.;
   }

   

Throws:
SecurityException Under a security manager, caller does not have RuntimePermission("org.jboss.security.plugins.JBossSecurityContext.setRunAsPermission")
See also:
SecurityContext.setOutgoingRunAs(RunAs)
   public void setOutgoingRunAs(RunAs runAs)
   { 
      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
         sm.checkPermission();
     
      this. = runAs;
   } 
   
   

See also:
SecurityContext.getUtil()
   public SecurityContextUtil getUtil()
   {  
      if( == null)
      {
         try
         {
             = SecurityContextFactory.createUtil(this);
         }
         catch (Exception e)
         {
            throw new IllegalStateException(e);
         } 
      } 
      return ;
   }
   
   public AuditManager getAuditManager()
   {
      return this..getAuditManager(this.);
   }
   public AuthenticationManager getAuthenticationManager()
   {
      return this..getAuthenticationManager(this.);
   }
   public AuthorizationManager getAuthorizationManager()
   {
      return this..getAuthorizationManager(this.);
   }
   public IdentityTrustManager getIdentityTrustManager()
   {
      return this..getIdentityTrustManager(this.);
   }
   public MappingManager getMappingManager()
   {
      return this..getMappingManager(this.);
   }     
   
   
   //Value Added Methods
   

Throws:
SecurityException Under a security manager, caller does not have RuntimePermission("org.jboss.security.plugins.JBossSecurityContext.setSubjectInfo")
   public void setSubjectInfo(SubjectInfo si)
   {
      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
      
      this. = si;
   }
   
   

Parameters:
roles
replace
Throws:
SecurityException Under a security manager, caller does not have RuntimePermission("org.jboss.security.plugins.JBossSecurityContext.setRolesPermission")
   public void setRoles(Group rolesboolean replace)
   {
      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
         sm.checkPermission();
    
      Group mergedRoles = roles;
      if(!replace)
      {
         mergedRoles = mergeGroups( (Group).get(ROLES_IDENTIFIER), roles); 
      } 
      .put(ROLES_IDENTIFIER, mergedRoles);
   }
   
   private Group mergeGroups(Group aGroup b)
   {
      Group newGroup = b;
      if(a != null)
      {
         Enumeration<? extends Principalen = a.members();
         while(en.hasMoreElements())
         {
            newGroup.addMember(en.nextElement());
         } 
      } 
      return newGroup
   } 
   
   
   
Set the CallbackHandler for the Managers in the SecurityContext

Parameters:
callbackHandler
   public void setCallbackHandler(CallbackHandler callbackHandler)
   {
      this. = callbackHandler;
   }
   
   public String toString()
   {
      StringBuilder builder = new StringBuilder();
      builder.append("[").append(getClass().getCanonicalName()).append("()");
      builder.append(this.).append(")]"); 
      return builder.toString();
   }
   @SuppressWarnings("unchecked")
   public Object clone() throws CloneNotSupportedException
   { 
      JBossSecurityContext jsc = (JBossSecurityContextsuper.clone();
      if(jsc != null)
      {
         HashMap<String,Objectcmap = (HashMap<String,Object>);
         jsc.contextData = (Map<StringObject>) (cmap).clone();
      }
      return super.clone();
   }
New to GrepCode? Check out our FAQ X