summaryrefslogtreecommitdiffstats
path: root/luni/src/main/java/javax/security
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2011-06-03 23:05:59 -0700
committerElliott Hughes <enh@google.com>2011-06-04 00:25:25 -0700
commite26b27faf689c17b7894c78caee32432176349ec (patch)
tree409c5a4dc6771d60faa21b818917ac7d223cdbb3 /luni/src/main/java/javax/security
parent8f1bbe0b6549136be386d75edf70ed4daf8a25b0 (diff)
downloadlibcore-e26b27faf689c17b7894c78caee32432176349ec.zip
libcore-e26b27faf689c17b7894c78caee32432176349ec.tar.gz
libcore-e26b27faf689c17b7894c78caee32432176349ec.tar.bz2
Remove more dead "security theater" cruft.
There's probably still more stuff lying around that isn't useful, but this was all I had time for on this particular Friday afternoon... Change-Id: I69593f6c9ab5534d581c703cc85a9766ba8e40e5
Diffstat (limited to 'luni/src/main/java/javax/security')
-rw-r--r--luni/src/main/java/javax/security/auth/AuthPermission.java44
-rw-r--r--luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java351
2 files changed, 12 insertions, 383 deletions
diff --git a/luni/src/main/java/javax/security/auth/AuthPermission.java b/luni/src/main/java/javax/security/auth/AuthPermission.java
index 173f679..3bf621a 100644
--- a/luni/src/main/java/javax/security/auth/AuthPermission.java
+++ b/luni/src/main/java/javax/security/auth/AuthPermission.java
@@ -18,49 +18,17 @@
package javax.security.auth;
import java.security.BasicPermission;
+import java.security.Permission;
/**
- * Legacy security code; this class exists for compatibility only.
+ * Legacy security code; do not use.
*/
public final class AuthPermission extends BasicPermission {
+ public AuthPermission(String name) { super(""); }
- private static final long serialVersionUID = 5806031445061587174L;
+ public AuthPermission(String name, String actions) { super("", ""); }
- private static final String CREATE_LOGIN_CONTEXT = "createLoginContext";
+ @Override public String getActions() { return null; }
- private static final String CREATE_LOGIN_CONTEXT_ANY = "createLoginContext.*";
-
- // inits permission name.
- private static String init(String name) {
- if (name == null) {
- throw new NullPointerException("name == null");
- }
-
- if (CREATE_LOGIN_CONTEXT.equals(name)) {
- return CREATE_LOGIN_CONTEXT_ANY;
- }
- return name;
- }
-
- /**
- * Creates an authentication permission with the specified target name.
- *
- * @param name
- * the target name of this authentication permission.
- */
- public AuthPermission(String name) {
- super(init(name));
- }
-
- /**
- * Creates an authentication permission with the specified target name.
- *
- * @param name
- * the target name of this authentication permission.
- * @param actions
- * this parameter is ignored and should be {@code null}.
- */
- public AuthPermission(String name, String actions) {
- super(init(name), actions);
- }
+ @Override public boolean implies(Permission permission) { return true; }
}
diff --git a/luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java b/luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java
index 7a9903d..0b6bebc 100644
--- a/luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java
+++ b/luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java
@@ -26,355 +26,16 @@ import java.security.Principal;
import java.util.Set;
/**
- * Legacy security code; this class exists for compatibility only.
+ * Legacy security code; do not use.
*/
public final class PrivateCredentialPermission extends Permission {
+ public PrivateCredentialPermission(String name, String action) { super(""); }
- private static final long serialVersionUID = 5284372143517237068L;
+ public String[][] getPrincipals() { return null; }
- // allowed action
- private static final String READ = "read";
+ public String getCredentialClass() { return null; }
- private String credentialClass;
+ @Override public String getActions() { return null; }
- // current offset
- private transient int offset;
-
- // owners set
- private transient CredOwner[] set;
-
- /**
- * Creates a new permission for private credentials specified by the target
- * name {@code name} and an {@code action}. The action is always
- * {@code "read"}.
- *
- * @param name
- * the target name of the permission.
- * @param action
- * the action {@code "read"}.
- */
- public PrivateCredentialPermission(String name, String action) {
- super(name);
- if (READ.equalsIgnoreCase(action)) {
- initTargetName(name);
- } else {
- throw new IllegalArgumentException("Action must be \"read\"");
- }
- }
-
- /**
- * Creates a {@code PrivateCredentialPermission} from the {@code Credential}
- * class and set of principals.
- *
- * @param credentialClass
- * the credential class name.
- * @param principals
- * the set of principals.
- */
- PrivateCredentialPermission(String credentialClass, Set<Principal> principals) {
- super(credentialClass);
- this.credentialClass = credentialClass;
-
- set = new CredOwner[principals.size()];
- for (Principal p : principals) {
- CredOwner element = new CredOwner(p.getClass().getName(), p.getName());
- // check for duplicate elements
- boolean found = false;
- for (int ii = 0; ii < offset; ii++) {
- if (set[ii].equals(element)) {
- found = true;
- break;
- }
- }
- if (!found) {
- set[offset++] = element;
- }
- }
- }
-
- /**
- * Initialize a PrivateCredentialPermission object and checks that a target
- * name has a correct format: CredentialClass 1*(PrincipalClass
- * "PrincipalName")
- */
- private void initTargetName(String name) {
-
- if (name == null) {
- throw new NullPointerException("name == null");
- }
-
- // check empty string
- name = name.trim();
- if (name.isEmpty()) {
- throw new IllegalArgumentException("name is empty");
- }
-
- // get CredentialClass
- int beg = name.indexOf(' ');
- if (beg == -1) {
- throw badSyntax();
- }
- credentialClass = name.substring(0, beg);
-
- // get a number of pairs: PrincipalClass "PrincipalName"
- beg++;
- int count = 0;
- int nameLength = name.length();
- for (int i, j = 0; beg < nameLength; beg = j + 2, count++) {
- i = name.indexOf(' ', beg);
- j = name.indexOf('"', i + 2);
-
- if (i == -1 || j == -1 || name.charAt(i + 1) != '"') {
- throw badSyntax();
- }
- }
-
- // name MUST have one pair at least
- if (count < 1) {
- throw badSyntax();
- }
-
- beg = name.indexOf(' ');
- beg++;
-
- // populate principal set with instances of CredOwner class
- String principalClass;
- String principalName;
-
- set = new CredOwner[count];
- for (int index = 0, i, j; index < count; beg = j + 2, index++) {
- i = name.indexOf(' ', beg);
- j = name.indexOf('"', i + 2);
-
- principalClass = name.substring(beg, i);
- principalName = name.substring(i + 2, j);
-
- CredOwner element = new CredOwner(principalClass, principalName);
- // check for duplicate elements
- boolean found = false;
- for (int ii = 0; ii < offset; ii++) {
- if (set[ii].equals(element)) {
- found = true;
- break;
- }
- }
- if (!found) {
- set[offset++] = element;
- }
- }
- }
-
- private IllegalArgumentException badSyntax() {
- throw new IllegalArgumentException("Target name MUST have the following syntax: " +
- "CredentialClass 1*(PrincipalClass \"PrincipalName\")");
- }
-
- private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
- ois.defaultReadObject();
- initTargetName(getName());
- }
-
- /**
- * Returns the principal's classes and names associated with this {@code
- * PrivateCredentialPermission} as a two dimensional array. The first
- * dimension of the array corresponds to the number of principals. The
- * second dimension defines either the name of the {@code PrincipalClass}
- * [x][0] or the value of {@code PrincipalName} [x][1].
- * <p>
- * This corresponds to the the target name's syntax:
- *
- * <pre>
- * targetName = CredentialClass {PrincipalClass &quot;PrincipalName&quot;}*
- * </pre>
- *
- * @return the principal classes and names associated with this {@code
- * PrivateCredentialPermission}.
- */
- public String[][] getPrincipals() {
-
- String[][] s = new String[offset][2];
-
- for (int i = 0; i < s.length; i++) {
- s[i][0] = set[i].principalClass;
- s[i][1] = set[i].principalName;
- }
- return s;
- }
-
- @Override
- public String getActions() {
- return READ;
- }
-
- /**
- * Returns the class name of the credential associated with this permission.
- *
- * @return the class name of the credential associated with this permission.
- */
- public String getCredentialClass() {
- return credentialClass;
- }
-
- @Override
- public int hashCode() {
- int hash = 0;
- for (int i = 0; i < offset; i++) {
- hash = hash + set[i].hashCode();
- }
- return getCredentialClass().hashCode() + hash;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
-
- if (obj == null || this.getClass() != obj.getClass()) {
- return false;
- }
-
- PrivateCredentialPermission that = (PrivateCredentialPermission) obj;
-
- return credentialClass.equals(that.credentialClass) && (offset == that.offset)
- && sameMembers(set, that.set, offset);
- }
-
- @Override
- public boolean implies(Permission permission) {
-
- if (permission == null || this.getClass() != permission.getClass()) {
- return false;
- }
-
- PrivateCredentialPermission that = (PrivateCredentialPermission) permission;
-
- if (!("*".equals(credentialClass) || credentialClass
- .equals(that.getCredentialClass()))) {
- return false;
- }
-
- if (that.offset == 0) {
- return true;
- }
-
- CredOwner[] thisCo = set;
- CredOwner[] thatCo = that.set;
- int thisPrincipalsSize = offset;
- int thatPrincipalsSize = that.offset;
- for (int i = 0, j; i < thisPrincipalsSize; i++) {
- for (j = 0; j < thatPrincipalsSize; j++) {
- if (thisCo[i].implies(thatCo[j])) {
- break;
- }
- }
- if (j == thatCo.length) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public PermissionCollection newPermissionCollection() {
- return null;
- }
-
- /**
- * Returns true if the two arrays have the same length, and every member of
- * one array is contained in another array
- */
- private boolean sameMembers(Object[] ar1, Object[] ar2, int length) {
- if (ar1 == null && ar2 == null) {
- return true;
- }
- if (ar1 == null || ar2 == null) {
- return false;
- }
- boolean found;
- for (int i = 0; i < length; i++) {
- found = false;
- for (int j = 0; j < length; j++) {
- if (ar1[i].equals(ar2[j])) {
- found = true;
- break;
- }
- }
- if (!found) {
- return false;
- }
- }
- return true;
- }
-
- private static final class CredOwner implements Serializable {
-
- private static final long serialVersionUID = -5607449830436408266L;
-
- String principalClass;
-
- String principalName;
-
- // whether class name contains wildcards
- private transient boolean isClassWildcard;
-
- // whether pname contains wildcards
- private transient boolean isPNameWildcard;
-
- // Creates a new CredOwner with the specified Principal Class and Principal Name
- CredOwner(String principalClass, String principalName) {
- if ("*".equals(principalClass)) {
- isClassWildcard = true;
- }
-
- if ("*".equals(principalName)) {
- isPNameWildcard = true;
- }
-
- if (isClassWildcard && !isPNameWildcard) {
- throw badPrincipal();
- }
-
- this.principalClass = principalClass;
- this.principalName = principalName;
- }
-
- private IllegalArgumentException badPrincipal() {
- throw new IllegalArgumentException("invalid syntax: Principal Class can not be a " +
- "wildcard (*) value if Principal Name is not a wildcard (*) value");
- }
-
- // Checks if this CredOwner implies the specified Object.
- boolean implies(Object obj) {
- if (obj == this) {
- return true;
- }
-
- CredOwner co = (CredOwner) obj;
-
- if (isClassWildcard || principalClass.equals(co.principalClass)) {
- if (isPNameWildcard || principalName.equals(co.principalName)) {
- return true;
- }
- }
- return false;
- }
-
- // Checks two CredOwner objects for equality.
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof CredOwner)) {
- return false;
- }
- CredOwner lhs = (CredOwner) o;
- return principalClass.equals(lhs.principalClass) &&
- principalName.equals(lhs.principalName);
- }
-
- // Returns the hash code value for this object.
- @Override
- public int hashCode() {
- return principalClass.hashCode() + principalName.hashCode();
- }
- }
+ @Override public boolean implies(Permission permission) { return true; }
}