[jboss-cvs] JBossAS SVN: r110524 - projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 3 16:09:07 EST 2011
Author: jesper.pedersen
Date: 2011-02-03 16:09:07 -0500 (Thu, 03 Feb 2011)
New Revision: 110524
Added:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SecurityActions.java
Removed:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectActions.java
Modified:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectCriKey.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectKey.java
Log:
Clean up security action implementations
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SecurityActions.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SecurityActions.java 2011-02-03 21:09:07 UTC (rev 110524)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jca.core.connectionmanager.pool.strategy;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.security.auth.Subject;
+
+/**
+ * Privileged Blocks
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+class SecurityActions
+{
+ /**
+ * Constructor
+ */
+ private SecurityActions()
+ {
+ }
+
+ /**
+ * Get the hash code for a Subject
+ * @param subject The Subject
+ * @return The hash code
+ */
+ static int hashCode(final Subject subject)
+ {
+ if (System.getSecurityManager() == null)
+ return subject.hashCode();
+
+ Integer hashCode = AccessController.doPrivileged(new PrivilegedAction<Integer>()
+ {
+ public Integer run()
+ {
+ return subject.hashCode();
+ }
+ });
+
+ return hashCode.intValue();
+ }
+
+ /**
+ * Verify if two Subject's are equal
+ * @param s1 The first Subject
+ * @param s2 The second Subject
+ * @return True if equal; otherwise false
+ */
+ static boolean equals(final Subject s1, final Subject s2)
+ {
+ if (System.getSecurityManager() == null)
+ return s1 != null ? s1.equals(s2) : s2 == null;
+
+ Boolean equals = AccessController.doPrivileged(new PrivilegedAction<Boolean>()
+ {
+ public Boolean run()
+ {
+ return s1 != null ? s1.equals(s2) : s2 == null;
+ }
+ });
+
+ return equals.booleanValue();
+ }
+}
Deleted: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectActions.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectActions.java 2011-02-03 17:07:46 UTC (rev 110523)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectActions.java 2011-02-03 21:09:07 UTC (rev 110524)
@@ -1,96 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.jca.core.connectionmanager.pool.strategy;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-import javax.security.auth.Subject;
-
-/**
- * SubjectActions.
- * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
- * @version $Rev$ $Date$
- *
- */
-class SubjectActions implements PrivilegedAction<Object>
-{
- /**First subject instance*/
- private Subject subject;
-
- /**Other subject instance*/
- private Subject other;
-
- /**
- * Creates a new subject action.
- * @param subject first instance
- * @param other othe instance
- */
- SubjectActions(Subject subject, Subject other)
- {
- this.subject = subject;
- this.other = other;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object run()
- {
- Object value = null;
-
- if (other == null)
- {
- value = Integer.valueOf(subject.hashCode());
- }
- else
- {
- value = Boolean.valueOf(subject.equals(other));
- }
-
- return value;
- }
-
- /**
- * HashCode.
- * @param subject subject instance
- * @return hash code
- */
- public static int hashCode(Subject subject)
- {
- SubjectActions action = new SubjectActions(subject, null);
- return ((Integer) AccessController.doPrivileged(action)).intValue();
- }
-
- /**
- * Equals.
- * @param subject subject instance
- * @param other other instance
- * @return equality
- */
- public static boolean equals(Subject subject, Subject other)
- {
- SubjectActions action = new SubjectActions(subject, other);
- return ((Boolean) AccessController.doPrivileged(action)).booleanValue();
- }
-}
-
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectCriKey.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectCriKey.java 2011-02-03 17:07:46 UTC (rev 110523)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectCriKey.java 2011-02-03 21:09:07 UTC (rev 110524)
@@ -76,7 +76,7 @@
{
if (hashCode == Integer.MAX_VALUE)
{
- hashCode = SubjectActions.hashCode(subject) ^ cri.hashCode();
+ hashCode = SecurityActions.hashCode(subject) ^ cri.hashCode();
}
return hashCode;
@@ -100,7 +100,7 @@
SubjectCriKey other = (SubjectCriKey) obj;
- return SubjectActions.equals(subject, other.subject)
+ return SecurityActions.equals(subject, other.subject)
&& cri.equals(other.cri)
&& separateNoTx == other.separateNoTx;
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectKey.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectKey.java 2011-02-03 17:07:46 UTC (rev 110523)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectKey.java 2011-02-03 21:09:07 UTC (rev 110524)
@@ -62,7 +62,8 @@
public int hashCode()
{
if (hashCode == Integer.MAX_VALUE)
- hashCode = SubjectActions.hashCode(subject);
+ hashCode = SecurityActions.hashCode(subject);
+
return hashCode;
}
@@ -82,7 +83,7 @@
}
SubjectKey other = (SubjectKey) obj;
- return SubjectActions.equals(subject, other.subject)
+ return SecurityActions.equals(subject, other.subject)
&& separateNoTx == other.separateNoTx;
}
More information about the jboss-cvs-commits
mailing list