/* * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code 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 General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.security.auth; import java.net.URL; import java.util.*; import java.security.CodeSource; import java.security.Principal; import java.security.cert.Certificate; import java.lang.reflect.Constructor; import javax.security.auth.Subject; /** *
This
*
* @param subject the
*
* @param url the
*
* @param certs the signers associated with this
*
*/
SubjectCodeSource(Subject subject,
LinkedList
*
* @return the Principals associated with this
*
*
* @return the
*
*
* @param codesource the
*
* @param subjectList a list of PolicyParser.PrincipalEntry objects
* that correspond to all the Principals in the Subject currently
* on this thread's AccessControlContext.
*
* @param pppe the Principals specified in a grant entry.
*
* @return true if the provided subjectList "contains"
* the
*
* @param obj the object to test for equality with this object.
*
* @return true if the objects are considered equal, false otherwise.
*/
public boolean equals(Object obj) {
if (obj == this)
return true;
if (super.equals(obj) == false)
return false;
if (!(obj instanceof SubjectCodeSource))
return false;
SubjectCodeSource that = (SubjectCodeSource)obj;
// the principal lists must match
try {
if (this.getSubject() != that.getSubject())
return false;
} catch (SecurityException se) {
return false;
}
if ((this.principals == null && that.principals != null) ||
(this.principals != null && that.principals == null))
return false;
if (this.principals != null && that.principals != null) {
if (!this.principals.containsAll(that.principals) ||
!that.principals.containsAll(this.principals))
return false;
}
return true;
}
/**
* Return a hashcode for this
*
* @return a hashcode for this
*
* @return a String representation of this SubjectCodeSource
class contains
* a URL
, signer certificates, and either a Subject
* (that represents the Subject
in the current
* AccessControlContext
),
* or a linked list of Principals/PrincipalComparators
* (that represent a "subject" in a Policy
).
*
*/
class SubjectCodeSource extends CodeSource implements java.io.Serializable {
private static final long serialVersionUID = 6039418085604715275L;
private static final java.util.ResourceBundle rb =
java.security.AccessController.doPrivileged
(new java.security.PrivilegedActionSubjectCodeSource
* with the given Subject
, principals, URL
,
* and signers (Certificates). The Subject
* represents the Subject
associated with the current
* AccessControlContext
.
* The Principals are given as a LinkedList
* of PolicyParser.PrincipalEntry
objects.
* Typically either a Subject
will be provided,
* or a list of principals
will be provided
* (not both).
*
* Subject
associated with this
* SubjectCodeSource
URL
associated with this
* SubjectCodeSource
SubjectCodeSource
SubjectCodeSource
.
* The Principals are retrieved as a LinkedList
* of PolicyParser.PrincipalEntry
objects.
*
* SubjectCodeSource
as a LinkedList
* of PolicyParser.PrincipalEntry
objects.
*/
LinkedListSubject
associated with this
* SubjectCodeSource
. The Subject
* represents the Subject
associated with the
* current AccessControlContext
.
*
* Subject
associated with this
* SubjectCodeSource
.
*/
Subject getSubject() {
return subject;
}
/**
* Returns true if this SubjectCodeSource
object "implies"
* the specified CodeSource
.
* More specifically, this method makes the following checks.
* If any fail, it returns false. If they all succeed, it returns true.
*
*
*
*
* null
.
* SubjectCodeSource
.
*
*
* PrincipalComparator
, then the principal must
* imply the provided codesource's Subject
.
* PrincipalComparator
, then the provided
* codesource's Subject
must have an
* associated Principal
, P, where
* P.getClass().getName equals principal.principalClass,
* and P.getName() equals principal.principalName.
* CodeSource
to compare against.
*
* @return true if this SubjectCodeSource
implies the
* the specified CodeSource
.
*/
public boolean implies(CodeSource codesource) {
LinkedListPrincipal
specified
* in the provided pppe argument.
*
* Note that the provided pppe argument may have
* wildcards (*) for the Principal
class and name,
* which need to be considered.
*
* Principal
specified in the provided
* pppe argument.
*/
private boolean subjectListImpliesPrincipalEntry(
LinkedListSubjectCodeSource
objects are considered equal
* if their locations are of identical value, if the two sets of
* Certificates are of identical values, and if the
* Subjects are equal, and if the PolicyParser.PrincipalEntry values
* are of identical values. It is not required that
* the Certificates or PolicyParser.PrincipalEntry values
* be in the same order.
*
* SubjectCodeSource
.
*
* SubjectCodeSource
.
*/
public int hashCode() {
return super.hashCode();
}
/**
* Return a String representation of this SubjectCodeSource
.
*
* SubjectCodeSource
.
*/
public String toString() {
String returnMe = super.toString();
if (getSubject() != null) {
if (debug != null) {
final Subject finalSubject = getSubject();
returnMe = returnMe + "\n" +
java.security.AccessController.doPrivileged
(new java.security.PrivilegedAction