[prev in list] [next in list] [prev in thread] [next in thread]
List: jboss-cvs-commits
Subject: [jboss-cvs] jbosscx/src/main/org/jboss/resource/security ...
From: Scott Stark <scott.stark () jboss ! com>
Date: 2005-05-31 23:56:31
Message-ID: E1DdGb1-00057a-E1 () committer01 ! frg ! pub ! inap ! atl ! jboss ! com
[Download RAW message or body]
User: starksm
Date: 05/05/31 19:56:31
Modified: src/main/org/jboss/resource/security
GetPrincipalInfoAction.java
Log:
Add an action for getting the run-as principal
Revision Changes Path
1.5 +128 -41 jbosscx/src/main/org/jboss/resource/security/GetPrincipalInfoAction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: GetPrincipalInfoAction.java
===================================================================
RCS file: /cvsroot/jboss/jbosscx/src/main/org/jboss/resource/security/GetPrincipalInfoAction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- GetPrincipalInfoAction.java 24 Nov 2004 15:29:23 -0000 1.4
+++ GetPrincipalInfoAction.java 31 May 2005 23:56:31 -0000 1.5
@@ -1,3 +1,9 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.resource.security;
import java.security.AccessController;
@@ -6,33 +12,22 @@
import java.io.UnsupportedEncodingException;
import org.jboss.security.SecurityAssociation;
+import org.jboss.security.RunAsIdentity;
/** PrivilegedActions used by this package
*
* @author Scott.Stark@jboss.org
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
class GetPrincipalInfoAction
{
- private static class GetPrincipalAction implements PrivilegedAction
- {
- static PrivilegedAction ACTION = new GetPrincipalAction();
- public Object run()
- {
- Principal principal = SecurityAssociation.getPrincipal();
- return principal;
- }
- }
- private static class GetCredentialAction implements PrivilegedAction
- {
- static PrivilegedAction ACTION = new GetCredentialAction();
- public Object run()
- {
- Object credential = SecurityAssociation.getCredential();
- char[] password = null;
/* Obtain the password credential by trying char[], byte[],
and toString()
*/
+ private static char[] getPassword()
+ {
+ Object credential = SecurityAssociation.getCredential();
+ char[] password = null;
if( credential instanceof char[] )
{
password = (char[]) credential;
@@ -56,18 +51,110 @@
}
return password;
}
+
+ interface PrincipalActions
+ {
+ PrincipalActions PRIVILEGED = new PrincipalActions()
+ {
+ private final PrivilegedAction peekAction = new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return SecurityAssociation.peekRunAsIdentity();
+ }
+ };
+
+ private final PrivilegedAction getPrincipalAction = new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return SecurityAssociation.getPrincipal();
+ }
+ };
+
+ private final PrivilegedAction getCredentialAction = new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return getPassword();
+ }
+ };
+
+ public RunAsIdentity peek()
+ {
+ return (RunAsIdentity)AccessController.doPrivileged(peekAction);
+ }
+
+ public Principal getPrincipal()
+ {
+ return (Principal)AccessController.doPrivileged(getPrincipalAction);
+ }
+
+ public char[] getCredential()
+ {
+ return (char[]) AccessController.doPrivileged(getCredentialAction);
+ }
+ };
+
+ PrincipalActions NON_PRIVILEGED = new PrincipalActions()
+ {
+ public RunAsIdentity peek()
+ {
+ return SecurityAssociation.peekRunAsIdentity();
+ }
+
+ public Principal getPrincipal()
+ {
+ return SecurityAssociation.getPrincipal();
+ }
+
+ public char[] getCredential()
+ {
+ return getPassword();
+ }
+ };
+
+ Principal getPrincipal();
+ char[] getCredential();
+ RunAsIdentity peek();
}
static Principal getPrincipal()
{
- Principal principal = (Principal) AccessController.doPrivileged(GetPrincipalAction.ACTION);
+ Principal principal;
+ if(System.getSecurityManager() == null)
+ {
+ principal = PrincipalActions.NON_PRIVILEGED.getPrincipal();
+ }
+ else
+ {
+ principal = PrincipalActions.PRIVILEGED.getPrincipal();
+ }
return principal;
}
static char[] getCredential()
{
- char[] credential = (char[]) AccessController.doPrivileged(GetCredentialAction.ACTION);
+ char[] credential;
+ if(System.getSecurityManager() == null)
+ {
+ credential = PrincipalActions.NON_PRIVILEGED.getCredential();
+ }
+ else
+ {
+ credential = PrincipalActions.PRIVILEGED.getCredential();
+ }
return credential;
}
+ static RunAsIdentity peekRunAsIdentity()
+ {
+ if(System.getSecurityManager() == null)
+ {
+ return PrincipalActions.NON_PRIVILEGED.peek();
+ }
+ else
+ {
+ return PrincipalActions.PRIVILEGED.peek();
+ }
+ }
}
-
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
jboss-cvs-commits mailing list
jboss-cvs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-cvs-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic