8022410: Fix Javac Warnings in com.sun.security.auth Package

Reviewed-by: darcy
This commit is contained in:
Dan Xu 2013-08-06 14:33:56 -07:00
parent 6c4cb95171
commit bcf263eb10
2 changed files with 63 additions and 67 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -47,6 +47,10 @@ import javax.security.auth.PrivateCredentialPermission;
import sun.security.util.PropertyExpander; import sun.security.util.PropertyExpander;
import sun.security.provider.PolicyParser.PrincipalEntry;
import sun.security.provider.PolicyParser.GrantEntry;
import sun.security.provider.PolicyParser.PermissionEntry;
/** /**
* This class represents a default implementation for * This class represents a default implementation for
* <code>javax.security.auth.Policy</code>. * <code>javax.security.auth.Policy</code>.
@ -469,7 +473,8 @@ public class PolicyFile extends javax.security.auth.Policy {
* @param policyFile the policy Reader object. * @param policyFile the policy Reader object.
*/ */
private void init(URL policy) { private void init(URL policy) {
PolicyParser pp = new PolicyParser(expandProperties); sun.security.provider.PolicyParser pp =
new sun.security.provider.PolicyParser(expandProperties);
try { try {
InputStreamReader isr InputStreamReader isr
= new InputStreamReader(getInputStream(policy)); = new InputStreamReader(getInputStream(policy));
@ -477,12 +482,12 @@ public class PolicyFile extends javax.security.auth.Policy {
isr.close(); isr.close();
KeyStore keyStore = initKeyStore(policy, pp.getKeyStoreUrl(), KeyStore keyStore = initKeyStore(policy, pp.getKeyStoreUrl(),
pp.getKeyStoreType()); pp.getKeyStoreType());
Enumeration<PolicyParser.GrantEntry> enum_ = pp.grantElements(); Enumeration<GrantEntry> enum_ = pp.grantElements();
while (enum_.hasMoreElements()) { while (enum_.hasMoreElements()) {
PolicyParser.GrantEntry ge = enum_.nextElement(); GrantEntry ge = enum_.nextElement();
addGrantEntry(ge, keyStore); addGrantEntry(ge, keyStore);
} }
} catch (PolicyParser.ParsingException pe) { } catch (sun.security.provider.PolicyParser.ParsingException pe) {
System.err.println(AUTH_POLICY + System.err.println(AUTH_POLICY +
rb.getString(".error.parsing.") + policy); rb.getString(".error.parsing.") + policy);
System.err.println(AUTH_POLICY + System.err.println(AUTH_POLICY +
@ -521,8 +526,8 @@ public class PolicyFile extends javax.security.auth.Policy {
* *
* @return null if signedBy alias is not recognized * @return null if signedBy alias is not recognized
*/ */
CodeSource getCodeSource(PolicyParser.GrantEntry ge, KeyStore keyStore) CodeSource getCodeSource(GrantEntry ge, KeyStore keyStore)
throws java.net.MalformedURLException throws java.net.MalformedURLException
{ {
Certificate[] certs = null; Certificate[] certs = null;
if (ge.signedBy != null) { if (ge.signedBy != null) {
@ -559,20 +564,18 @@ public class PolicyFile extends javax.security.auth.Policy {
/** /**
* Add one policy entry to the vector. * Add one policy entry to the vector.
*/ */
private void addGrantEntry(PolicyParser.GrantEntry ge, private void addGrantEntry(GrantEntry ge, KeyStore keyStore) {
KeyStore keyStore) {
if (debug != null) { if (debug != null) {
debug.println("Adding policy entry: "); debug.println("Adding policy entry: ");
debug.println(" signedBy " + ge.signedBy); debug.println(" signedBy " + ge.signedBy);
debug.println(" codeBase " + ge.codeBase); debug.println(" codeBase " + ge.codeBase);
if (ge.principals != null && ge.principals.size() > 0) { if (ge.principals != null && ge.principals.size() > 0) {
ListIterator<PolicyParser.PrincipalEntry> li = ListIterator<PrincipalEntry> li = ge.principals.listIterator();
ge.principals.listIterator();
while (li.hasNext()) { while (li.hasNext()) {
PolicyParser.PrincipalEntry pppe = li.next(); PrincipalEntry pppe = li.next();
debug.println(" " + pppe.principalClass + debug.println(" " + pppe.getPrincipalClass() +
" " + pppe.principalName); " " + pppe.getPrincipalName());
} }
} }
debug.println(); debug.println();
@ -584,10 +587,9 @@ public class PolicyFile extends javax.security.auth.Policy {
if (codesource == null) return; if (codesource == null) return;
PolicyEntry entry = new PolicyEntry(codesource); PolicyEntry entry = new PolicyEntry(codesource);
Enumeration<PolicyParser.PermissionEntry> enum_ = Enumeration<PermissionEntry> enum_ = ge.permissionElements();
ge.permissionElements();
while (enum_.hasMoreElements()) { while (enum_.hasMoreElements()) {
PolicyParser.PermissionEntry pe = enum_.nextElement(); PermissionEntry pe = enum_.nextElement();
try { try {
// XXX special case PrivateCredentialPermission-SELF // XXX special case PrivateCredentialPermission-SELF
Permission perm; Permission perm;
@ -998,11 +1000,11 @@ public class PolicyFile extends javax.security.auth.Policy {
return true; return true;
} }
ListIterator<PolicyParser.PrincipalEntry> pli = ListIterator<PrincipalEntry> pli =
scs.getPrincipals().listIterator(); scs.getPrincipals().listIterator();
while (pli.hasNext()) { while (pli.hasNext()) {
PolicyParser.PrincipalEntry principal = pli.next(); PrincipalEntry principal = pli.next();
// XXX // XXX
// if the Policy entry's Principal does not contain a // if the Policy entry's Principal does not contain a
@ -1050,30 +1052,29 @@ public class PolicyFile extends javax.security.auth.Policy {
* if (y == 1), it's the principal name. * if (y == 1), it's the principal name.
*/ */
private String[][] getPrincipalInfo private String[][] getPrincipalInfo
(PolicyParser.PrincipalEntry principal, (PrincipalEntry principal, final CodeSource accCs) {
final CodeSource accCs) {
// there are 3 possibilities: // there are 3 possibilities:
// 1) the entry's Principal class and name are not wildcarded // 1) the entry's Principal class and name are not wildcarded
// 2) the entry's Principal name is wildcarded only // 2) the entry's Principal name is wildcarded only
// 3) the entry's Principal class and name are wildcarded // 3) the entry's Principal class and name are wildcarded
if (!principal.principalClass.equals if (!principal.getPrincipalClass().equals
(PolicyParser.PrincipalEntry.WILDCARD_CLASS) && (PrincipalEntry.WILDCARD_CLASS) &&
!principal.principalName.equals !principal.getPrincipalName().equals
(PolicyParser.PrincipalEntry.WILDCARD_NAME)) { (PrincipalEntry.WILDCARD_NAME)) {
// build a PrivateCredentialPermission for the principal // build a PrivateCredentialPermission for the principal
// from the Policy entry // from the Policy entry
String[][] info = new String[1][2]; String[][] info = new String[1][2];
info[0][0] = principal.principalClass; info[0][0] = principal.getPrincipalClass();
info[0][1] = principal.principalName; info[0][1] = principal.getPrincipalName();
return info; return info;
} else if (!principal.principalClass.equals } else if (!principal.getPrincipalClass().equals
(PolicyParser.PrincipalEntry.WILDCARD_CLASS) && (PrincipalEntry.WILDCARD_CLASS) &&
principal.principalName.equals principal.getPrincipalName().equals
(PolicyParser.PrincipalEntry.WILDCARD_NAME)) { (PrincipalEntry.WILDCARD_NAME)) {
// build a PrivateCredentialPermission for all // build a PrivateCredentialPermission for all
// the Subject's principals that are instances of principalClass // the Subject's principals that are instances of principalClass
@ -1088,7 +1089,7 @@ public class PolicyFile extends javax.security.auth.Policy {
// If it doesn't, we should stop here with a ClassCastException. // If it doesn't, we should stop here with a ClassCastException.
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Class<? extends Principal> pClass = (Class<? extends Principal>) Class<? extends Principal> pClass = (Class<? extends Principal>)
Class.forName(principal.principalClass, false, Class.forName(principal.getPrincipalClass(), false,
ClassLoader.getSystemClassLoader()); ClassLoader.getSystemClassLoader());
principalSet = scs.getSubject().getPrincipals(pClass); principalSet = scs.getSubject().getPrincipals(pClass);
} catch (Exception e) { } catch (Exception e) {
@ -1387,6 +1388,7 @@ public class PolicyFile extends javax.security.auth.Policy {
} }
} }
@SuppressWarnings("deprecation")
class PolicyPermissions extends PermissionCollection { class PolicyPermissions extends PermissionCollection {
private static final long serialVersionUID = -1954188373270545523L; private static final long serialVersionUID = -1954188373270545523L;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,6 +33,7 @@ import java.security.cert.Certificate;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import javax.security.auth.Subject; import javax.security.auth.Subject;
import sun.security.provider.PolicyParser.PrincipalEntry;
/** /**
* <p> This <code>SubjectCodeSource</code> class contains * <p> This <code>SubjectCodeSource</code> class contains
@ -57,7 +58,7 @@ class SubjectCodeSource extends CodeSource implements java.io.Serializable {
}); });
private Subject subject; private Subject subject;
private LinkedList<PolicyParser.PrincipalEntry> principals; private LinkedList<PrincipalEntry> principals;
private static final Class[] PARAMS = { String.class }; private static final Class[] PARAMS = { String.class };
private static final sun.security.util.Debug debug = private static final sun.security.util.Debug debug =
sun.security.util.Debug.getInstance("auth", "\t[Auth Access]"); sun.security.util.Debug.getInstance("auth", "\t[Auth Access]");
@ -87,14 +88,14 @@ class SubjectCodeSource extends CodeSource implements java.io.Serializable {
* <code>SubjectCodeSource</code> <p> * <code>SubjectCodeSource</code> <p>
*/ */
SubjectCodeSource(Subject subject, SubjectCodeSource(Subject subject,
LinkedList<PolicyParser.PrincipalEntry> principals, LinkedList<PrincipalEntry> principals,
URL url, Certificate[] certs) { URL url, Certificate[] certs) {
super(url, certs); super(url, certs);
this.subject = subject; this.subject = subject;
this.principals = (principals == null ? this.principals = (principals == null ?
new LinkedList<PolicyParser.PrincipalEntry>() : new LinkedList<PrincipalEntry>() :
new LinkedList<PolicyParser.PrincipalEntry>(principals)); new LinkedList<PrincipalEntry>(principals));
sysClassLoader = java.security.AccessController.doPrivileged sysClassLoader = java.security.AccessController.doPrivileged
(new java.security.PrivilegedAction<ClassLoader>() { (new java.security.PrivilegedAction<ClassLoader>() {
public ClassLoader run() { public ClassLoader run() {
@ -114,7 +115,7 @@ class SubjectCodeSource extends CodeSource implements java.io.Serializable {
* <code>SubjectCodeSource</code> as a <code>LinkedList</code> * <code>SubjectCodeSource</code> as a <code>LinkedList</code>
* of <code>PolicyParser.PrincipalEntry</code> objects. * of <code>PolicyParser.PrincipalEntry</code> objects.
*/ */
LinkedList<PolicyParser.PrincipalEntry> getPrincipals() { LinkedList<PrincipalEntry> getPrincipals() {
return principals; return principals;
} }
@ -167,7 +168,7 @@ class SubjectCodeSource extends CodeSource implements java.io.Serializable {
*/ */
public boolean implies(CodeSource codesource) { public boolean implies(CodeSource codesource) {
LinkedList<PolicyParser.PrincipalEntry> subjectList = null; LinkedList<PrincipalEntry> subjectList = null;
if (codesource == null || if (codesource == null ||
!(codesource instanceof SubjectCodeSource) || !(codesource instanceof SubjectCodeSource) ||
@ -197,20 +198,19 @@ class SubjectCodeSource extends CodeSource implements java.io.Serializable {
return false; return false;
} }
ListIterator<PolicyParser.PrincipalEntry> li = ListIterator<PrincipalEntry> li = this.principals.listIterator(0);
this.principals.listIterator(0);
while (li.hasNext()) { while (li.hasNext()) {
PolicyParser.PrincipalEntry pppe = li.next(); PrincipalEntry pppe = li.next();
try { try {
// handle PrincipalComparators // handle PrincipalComparators
Class<?> principalComparator = Class.forName( Class<?> principalComparator = Class.forName(
pppe.principalClass, true, sysClassLoader); pppe.getPrincipalClass(), true, sysClassLoader);
Constructor<?> c = principalComparator.getConstructor(PARAMS); Constructor<?> c = principalComparator.getConstructor(PARAMS);
PrincipalComparator pc = PrincipalComparator pc =
(PrincipalComparator)c.newInstance (PrincipalComparator)c.newInstance
(new Object[] { pppe.principalName }); (new Object[] { pppe.getPrincipalName() });
if (!pc.implies(that.getSubject())) { if (!pc.implies(that.getSubject())) {
if (debug != null) if (debug != null)
@ -236,11 +236,10 @@ class SubjectCodeSource extends CodeSource implements java.io.Serializable {
Iterator<Principal> i = Iterator<Principal> i =
that.getSubject().getPrincipals().iterator(); that.getSubject().getPrincipals().iterator();
subjectList = new LinkedList<PolicyParser.PrincipalEntry>(); subjectList = new LinkedList<PrincipalEntry>();
while (i.hasNext()) { while (i.hasNext()) {
Principal p = i.next(); Principal p = i.next();
PolicyParser.PrincipalEntry spppe = PrincipalEntry spppe = new PrincipalEntry
new PolicyParser.PrincipalEntry
(p.getClass().getName(), p.getName()); (p.getClass().getName(), p.getName());
subjectList.add(spppe); subjectList.add(spppe);
} }
@ -281,23 +280,19 @@ class SubjectCodeSource extends CodeSource implements java.io.Serializable {
* <i>pppe</i> argument. * <i>pppe</i> argument.
*/ */
private boolean subjectListImpliesPrincipalEntry( private boolean subjectListImpliesPrincipalEntry(
LinkedList<PolicyParser.PrincipalEntry> subjectList, LinkedList<PrincipalEntry> subjectList, PrincipalEntry pppe) {
PolicyParser.PrincipalEntry pppe) {
ListIterator<PolicyParser.PrincipalEntry> li = ListIterator<PrincipalEntry> li = subjectList.listIterator(0);
subjectList.listIterator(0);
while (li.hasNext()) { while (li.hasNext()) {
PolicyParser.PrincipalEntry listPppe = li.next(); PrincipalEntry listPppe = li.next();
if (pppe.principalClass.equals if (pppe.getPrincipalClass().equals
(PolicyParser.PrincipalEntry.WILDCARD_CLASS) || (PrincipalEntry.WILDCARD_CLASS) ||
pppe.principalClass.equals pppe.getPrincipalClass().equals(listPppe.getPrincipalClass()))
(listPppe.principalClass)) { {
if (pppe.getPrincipalName().equals
if (pppe.principalName.equals (PrincipalEntry.WILDCARD_NAME) ||
(PolicyParser.PrincipalEntry.WILDCARD_NAME) || pppe.getPrincipalName().equals(listPppe.getPrincipalName()))
pppe.principalName.equals
(listPppe.principalName))
return true; return true;
} }
} }
@ -390,13 +385,12 @@ class SubjectCodeSource extends CodeSource implements java.io.Serializable {
} }
} }
if (principals != null) { if (principals != null) {
ListIterator<PolicyParser.PrincipalEntry> li = ListIterator<PrincipalEntry> li = principals.listIterator();
principals.listIterator();
while (li.hasNext()) { while (li.hasNext()) {
PolicyParser.PrincipalEntry pppe = li.next(); PrincipalEntry pppe = li.next();
returnMe = returnMe + rb.getString("NEWLINE") + returnMe = returnMe + rb.getString("NEWLINE") +
pppe.principalClass + " " + pppe.getPrincipalClass() + " " +
pppe.principalName; pppe.getPrincipalName();
} }
} }
return returnMe; return returnMe;