org.jboss.security.SecurityContext Java Examples

The following examples show how to use org.jboss.security.SecurityContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
static Principal getPrincipal()
{
   return AccessController.doPrivileged(new PrivilegedAction<Principal>()
   {
      public Principal run()
      {
         Principal principal = null;
         SecurityContext sc = getSecurityContext();
         if(sc != null)
         {
            principal = sc.getUtil().getUserPrincipal();
         }
         return principal;
      }
   });
}
 
Example #2
Source File: PicketBoxProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the caller subject
 * @return 
 * @throws PicketBoxProcessingException 
 */
public Subject getCallerSubject() throws PicketBoxProcessingException
{
   Subject subject = new Subject();
   SecurityContext securityContext = null;
   try
   {
      securityContext = SecurityActions.getSecurityContext();
   }
   catch (PrivilegedActionException pae)
   {
      throw new PicketBoxProcessingException(pae.getCause());
   }
   if(securityContext != null)
      subject = securityContext.getUtil().getSubject();
   return subject;
}
 
Example #3
Source File: PicketBoxProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the caller roles
 * @return 
 * @throws PicketBoxProcessingException 
 */
public RoleGroup getCallerRoles() throws PicketBoxProcessingException
{
   RoleGroup roleGroup = null;
   
   SecurityContext securityContext = null;
   try
   {
      securityContext = SecurityActions.getSecurityContext();
   }
   catch (PrivilegedActionException pae)
   {
      throw new PicketBoxProcessingException(pae.getCause());
   }
   if(securityContext != null)
      roleGroup = securityContext.getUtil().getRoles(); 
   return roleGroup;
}
 
Example #4
Source File: PicketBoxProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the authenticated principal
 * @return 
 * @throws PicketBoxProcessingException 
 */
public Principal getCallerPrincipal() throws PicketBoxProcessingException
{
   Principal principal = null;
   
   SecurityContext securityContext = null;
   try
   {
      securityContext = SecurityActions.getSecurityContext();
   }
   catch (PrivilegedActionException pae)
   {
      throw new PicketBoxProcessingException(pae.getCause());
   }
   if(securityContext != null)
      principal = securityContext.getUtil().getUserPrincipal(); 
   return principal;
}
 
Example #5
Source File: JaasSecurityManagerBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** Get the currently authenticated Subject. This is a thread local
 property shared across all JaasSecurityManager instances.
 @return The Subject authenticated in the current thread if one
 exists, null otherwise.
 */
public Subject getActiveSubject()
{
   /* This does not use SubjectActions.getActiveSubject since the caller
      must have the correct permissions to access the
      SecurityAssociation.getSubject method.
   */
   //return SecurityAssociation.getSubject();
   Subject subj = null;
   SecurityContext sc = SecurityContextAssociation.getSecurityContext();
   if(sc != null)
   {
      subj = sc.getUtil().getSubject();
   }
   return subj;
}
 
Example #6
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void push(Principal principal, Object credential, Subject subject,
      String securityDomain)
{
   //SecurityAssociation.pushSubjectContext(subject, principal, credential);
   SecurityContext sc = SecurityContextAssociation.getSecurityContext();
   if(sc == null)
   {
      try
      {
         sc = SecurityContextFactory.createSecurityContext(principal, credential,
               subject, securityDomain);
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
   }
   else
   {
      sc.getUtil().createSubjectInfo(principal, credential, subject); 
   }
   SecurityContextAssociation.setSecurityContext(sc); 
}
 
Example #7
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
static LoginException getContextLoginException()
{
   LoginException exp = null;
   SecurityContext sc = getSecurityContext();
   if (sc != null) {
       Map<String, Object> ctxInfo = sc.getData();
       if (ctxInfo != null) {
           for (Object obj: ctxInfo.values()) {
               if (obj != null && obj instanceof LoginException) {
                   return (LoginException)obj;
               }
           }
       }
   }
   return exp;
}
 
Example #8
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
static Object getCredential()
{
   return AccessController.doPrivileged(new PrivilegedAction<Object>()
   {
      public Object run()
      {
         Object credential = null;
         SecurityContext sc = getSecurityContext();
         if(sc != null)
         {
            credential = sc.getUtil().getCredential();
         }
         return credential;
      }
   });
}
 
Example #9
Source File: JBossIdentityTrustManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see IdentityTrustManager#isTrusted(org.jboss.security.SecurityContext)
 */
public TrustDecision isTrusted(SecurityContext securityContext)
{  
   if(securityContext == null)
      throw PicketBoxMessages.MESSAGES.invalidNullArgument("securityContext");
   if(this.identityTrustContext == null)
      this.identityTrustContext = new JBossIdentityTrustContext(securityDomain, securityContext);
   TrustDecision td = TrustDecision.NotApplicable;
   if(this.identityTrustContext == null)
      throw PicketBoxMessages.MESSAGES.invalidNullProperty("identityTrustContext");

   try
   {
      td = this.identityTrustContext.isTrusted();
   }
   catch (IdentityTrustException e)
   {
       PicketBoxLogger.LOGGER.debugIgnoredException(e);
   }
   return td;
}
 
Example #10
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void push(Principal principal, Object credential, Subject subject,
      String securityDomain)
{
   //SecurityAssociation.pushSubjectContext(subject, principal, credential);
   SecurityContext sc = SecurityContextAssociation.getSecurityContext();
   if(sc == null)
   {
      try
      {
         sc = SecurityContextFactory.createSecurityContext(principal, credential,
               subject, securityDomain);
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
   }
   else
   {
      sc.getUtil().createSubjectInfo(principal, credential, subject); 
   }
   SecurityContextAssociation.setSecurityContext(sc); 
}
 
Example #11
Source File: SecurityFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Establish a security context on the thread
 * @param securityDomainName
 */
public static SecurityContext establishSecurityContext(String securityDomainName)
{ 
   SecurityManager sm = System.getSecurityManager();
   if (sm != null) {
      sm.checkPermission(new RuntimePermission(SecurityFactory.class.getName() + ".establishSecurityContext"));
   }
   SecurityContext securityContext = null;
   try
   {
      securityContext = SecurityContextFactory.createSecurityContext(securityDomainName);
   }
   catch (Exception e)
   {
      throw new RuntimeException(e);
   }
   SecurityActions.setSecurityContext(securityContext);
   return securityContext;
}
 
Example #12
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object run()
{
   //Set it on the current security context also
   SecurityContext sc = SecurityContextAssociation.getSecurityContext();
   if(sc != null)
   {
      sc.getData().put(key, value);
   }
   return SecurityContextAssociation.setContextInfo(key, value);
}
 
Example #13
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static void setSecurityContext(final SecurityContext sc)
{ 
   AccessController.doPrivileged(new PrivilegedAction<SecurityContext>(){

      public SecurityContext run()
      { 
         SecurityContextAssociation.setSecurityContext(sc);
         return null;
      }});
}
 
Example #14
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static SecurityContext getSecurityContext()
{ 
   return AccessController.doPrivileged(new PrivilegedAction<SecurityContext>(){

      public SecurityContext run()
      {   
         return SecurityContextAssociation.getSecurityContext();
      }});
}
 
Example #15
Source File: AbstractIdentityTrustModule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see IdentityTrustModule#initialize(SecurityContext, CallbackHandler, Map, Map)
 */
public void initialize(SecurityContext sc, 
      CallbackHandler handler, Map<String,Object> sharedState
      , Map<String,Object> options) 
throws IdentityTrustException
{ 
   this.securityContext = sc;
   this.callbackHandler = handler;
   this.sharedState = sharedState;
   this.options = options;
}
 
Example #16
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void push(final Principal principal, final Object credential,
   final Subject subject, final String securityDomain) 
{
   AccessController.doPrivileged(
      new PrivilegedAction<Object>()
      {
         public Object run()
         {
            //SecurityAssociation.pushSubjectContext(subject, principal, credential);
            SecurityContext sc = SecurityContextAssociation.getSecurityContext();
            if(sc == null)
            {
               try
               {
                  sc = SecurityContextFactory.createSecurityContext(principal, credential,
                        subject, securityDomain);
               }
               catch (Exception e)
               {
                  throw new RuntimeException(e);
               }
            }
            SecurityContextAssociation.setSecurityContext(sc);
            return null;
         }
      }
   );
}
 
Example #17
Source File: JBossSecurityClient.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SecurityContext getSecurityContext() {
   return AccessController.doPrivileged(new PrivilegedAction<SecurityContext>() {
      @Override
      public SecurityContext run() {
         return NON_PRIVILEGED.getSecurityContext();
      }
   });
}
 
Example #18
Source File: JBossAuthorizationManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private RoleGroup getCurrentRoles(Principal principal)
{ 
   //Check that the caller is authenticated to the current thread
   Subject subject = SubjectActions.getActiveSubject();  
   
   //Deal with the security context
   SecurityContext sc = SubjectActions.getSecurityContext(); 
   if(sc == null)
   {
      sc = new JBossSecurityContext(securityDomain); 
      SubjectActions.setSecurityContext(sc);   
   } 
   
   return getCurrentRoles(principal,subject,sc); 
}
 
Example #19
Source File: SecurityActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static RunAs getIncomingRunAs(final SecurityContext sc)
{
   return AccessController.doPrivileged(new PrivilegedAction<RunAs>()
   {
      public RunAs run()
      {
         return sc.getIncomingRunAs();
      }
   });  
}
 
Example #20
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void push(final Principal principal, final Object credential,
   final Subject subject, final String securityDomain) 
{
   AccessController.doPrivileged(
      new PrivilegedAction<Object>()
      {
         public Object run()
         {
            SecurityContext sc = SecurityContextAssociation.getSecurityContext();
            if(sc == null)
            {
               try
               {
                  sc = SecurityContextFactory.createSecurityContext(principal, credential,
                        subject, securityDomain);
               }
               catch (Exception e)
               {
                  throw new RuntimeException(e);
               }
            }
            SecurityContextAssociation.setSecurityContext(sc);
            return null;
         }
      }
   );
}
 
Example #21
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object run()
{
   //Set it on the current security context also
   SecurityContext sc = SecurityContextAssociation.getSecurityContext();
   if(sc != null)
   {
      sc.getData().put(key, value);
   }
   return SecurityContextAssociation.setContextInfo(key, value);
}
 
Example #22
Source File: JBossSecurityClient.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void createSubjectInfo(final SecurityContext securityContext, final Principal principal, final Object credential, final Subject subject) {
   AccessController.doPrivileged(new PrivilegedAction<Void>() {
      @Override
      public Void run() {
         NON_PRIVILEGED.createSubjectInfo(securityContext, principal, credential, subject);
         return null;
      }
   });
}
 
Example #23
Source File: JBossSecurityClient.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setSecurityContext(final SecurityContext securityContext) {
   AccessController.doPrivileged(new PrivilegedAction<Void>() {
      @Override
      public Void run() {
         NON_PRIVILEGED.setSecurityContext(securityContext);
         return null;
      }
   });
}
 
Example #24
Source File: JBossSecurityClient.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SecurityContext createClientSecurityContext() throws Exception {
   try {
      return AccessController.doPrivileged(new PrivilegedExceptionAction<SecurityContext>() {
         @Override
         public SecurityContext run() throws Exception {
            return NON_PRIVILEGED.createClientSecurityContext();
         }
      });
   } catch (PrivilegedActionException pae) {
      throw pae.getException();
   }
}
 
Example #25
Source File: SecurityActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static void setSecurityContext(final SecurityContext sc)
{
   AccessController.doPrivileged(new PrivilegedAction<Object>()
   {
      public Object run()
      {
         SecurityContextAssociation.setSecurityContext(sc);
         return null;
      }
   });
}
 
Example #26
Source File: SecurityActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static SecurityContext getSecurityContext() throws PrivilegedActionException
{
   return AccessController.doPrivileged(new PrivilegedExceptionAction<SecurityContext>()
   {
      public SecurityContext run() throws Exception
      {
         return SecurityContextAssociation.getSecurityContext();
      }
   });
}
 
Example #27
Source File: SecurityActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static SecurityContext createSecurityContext(final String name) throws PrivilegedActionException
{
   return AccessController.doPrivileged(new PrivilegedExceptionAction<SecurityContext>()
   {
      public SecurityContext run() throws Exception
      {
         return SecurityContextFactory.createSecurityContext(name);
      }
   });
}
 
Example #28
Source File: SecurityActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static void setSecurityContext(final SecurityContext sc)
{
   AccessController.doPrivileged(new PrivilegedAction<Object>()
   {
      public Object run()
      {
         SecurityContextAssociation.setSecurityContext(sc);
         return null;
      }
   });
}
 
Example #29
Source File: SecurityActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static void register(final SecurityContext sc, final Principal principal, final Object credential, final Subject subject)
{
   AccessController.doPrivileged(new PrivilegedAction<Object>()
   {
      public Object run()
      {
         sc.getUtil().createSubjectInfo(principal, credential, subject); 
         return null;
      }
   });        
}
 
Example #30
Source File: SecurityActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static SecurityContext getCurrentSecurityContext()
 {
    return AccessController.doPrivileged( new PrivilegedAction<SecurityContext>() 
    {

public SecurityContext run() 
{
	return SecurityContextAssociation.getSecurityContext();
}
    });
 }