[jboss-cvs] JBossAS SVN: r64742 - trunk/security/src/main/org/jboss/security/integration/ejb.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 21 11:56:52 EDT 2007


Author: anil.saldhana at jboss.com
Date: 2007-08-21 11:56:51 -0400 (Tue, 21 Aug 2007)
New Revision: 64742

Added:
   trunk/security/src/main/org/jboss/security/integration/ejb/EJBAuthenticationHelper.java
Log:
JBAS-4423:ejb3 security alignment

Added: trunk/security/src/main/org/jboss/security/integration/ejb/EJBAuthenticationHelper.java
===================================================================
--- trunk/security/src/main/org/jboss/security/integration/ejb/EJBAuthenticationHelper.java	                        (rev 0)
+++ trunk/security/src/main/org/jboss/security/integration/ejb/EJBAuthenticationHelper.java	2007-08-21 15:56:51 UTC (rev 64742)
@@ -0,0 +1,94 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.security.integration.ejb;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+import org.jboss.security.SecurityContext;
+import org.jboss.security.identitytrust.IdentityTrustManager.TrustDecision;
+
+//$Id$
+
+/**
+ *  Helper class for EJB Authentication
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Aug 16, 2007 
+ *  @version $Revision$
+ */
+public class EJBAuthenticationHelper
+{ 
+   private SecurityContext securityContext;
+   
+   /**
+    * In rare situations, the caller needs to be stopped right there
+    */
+   private boolean trustDenied = false;
+   
+   public EJBAuthenticationHelper(SecurityContext sc)
+   {
+      if(sc == null)
+         throw new IllegalArgumentException("security context sc is null");
+      this.securityContext = sc;
+   }
+    
+   public boolean isTrusted()
+   {
+      TrustDecision td = securityContext.getIdentityTrustManager().isTrusted();
+      if(td == TrustDecision.Deny)
+         trustDenied = true;
+      return td == TrustDecision.Permit;
+   }
+   
+   /**
+    * Check if the previous call to isTrusted actually 
+    * set the trustDenied flag.
+    * @return
+    */
+   public boolean isTrustDenied()
+   {
+      return this.trustDenied;
+   }
+   
+   /**
+    * Authenticate the caller
+    * @param p
+    * @param cred
+    * @return
+    */
+   public boolean isValid(Subject subject)
+   {
+      Principal p = securityContext.getUtil().getUserPrincipal();
+      Object cred = securityContext.getUtil().getCredential(); 
+      return securityContext.getAuthenticationManager().isValid(p, cred, subject);
+   }
+   
+   /**
+    * Push the authenticated subject onto the security context
+    * IMPORTANT - this needs to be done after the isValid call
+    */
+   public void pushSubjectContext(Subject subject)
+   { 
+      securityContext.getSubjectInfo().setAuthenticatedSubject(subject); 
+   }
+}




More information about the jboss-cvs-commits mailing list