java.security
Class CodeSource

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.security.CodeSource
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable

public class CodeSource
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Serializable sample code for java.io.Serializable definition code for java.io.Serializable

This class extends the concept of a codebase to encapsulate not only the location (URL) but also the certificate chains that were used to verify signed code originating from that location.

See Also:
Serialized Form

Constructor Summary
CodeSource sample code for java.security.CodeSource.CodeSource(java.net.URL, java.security.cert.Certificate[]) definition code for java.security.CodeSource.CodeSource(java.net.URL, java.security.cert.Certificate[]) (URL sample code for java.net.URL definition code for java.net.URL  url, Certificate sample code for java.security.cert.Certificate definition code for java.security.cert.Certificate [] certs)
          Constructs a CodeSource and associates it with the specified location and set of certificates.
CodeSource sample code for java.security.CodeSource.CodeSource(java.net.URL, java.security.CodeSigner[]) definition code for java.security.CodeSource.CodeSource(java.net.URL, java.security.CodeSigner[]) (URL sample code for java.net.URL definition code for java.net.URL  url, CodeSigner sample code for java.security.CodeSigner definition code for java.security.CodeSigner [] signers)
          Constructs a CodeSource and associates it with the specified location and set of code signers.
 
Method Summary
 boolean equals sample code for java.security.CodeSource.equals(java.lang.Object) definition code for java.security.CodeSource.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Tests for equality between the specified object and this object.
 Certificate sample code for java.security.cert.Certificate definition code for java.security.cert.Certificate [] getCertificates sample code for java.security.CodeSource.getCertificates() definition code for java.security.CodeSource.getCertificates() ()
          Returns the certificates associated with this CodeSource.
 CodeSigner sample code for java.security.CodeSigner definition code for java.security.CodeSigner [] getCodeSigners sample code for java.security.CodeSource.getCodeSigners() definition code for java.security.CodeSource.getCodeSigners() ()
          Returns the code signers associated with this CodeSource.
 URL sample code for java.net.URL definition code for java.net.URL getLocation sample code for java.security.CodeSource.getLocation() definition code for java.security.CodeSource.getLocation() ()
          Returns the location associated with this CodeSource.
 int hashCode sample code for java.security.CodeSource.hashCode() definition code for java.security.CodeSource.hashCode() ()
          Returns the hash code value for this object.
 boolean implies sample code for java.security.CodeSource.implies(java.security.CodeSource) definition code for java.security.CodeSource.implies(java.security.CodeSource) (CodeSource sample code for java.security.CodeSource definition code for java.security.CodeSource  codesource)
          Returns true if this CodeSource object "implies" the specified CodeSource.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.security.CodeSource.toString() definition code for java.security.CodeSource.toString() ()
          Returns a string describing this CodeSource, telling its URL and certificates.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

CodeSource sample code for java.security.CodeSource(java.net.URL, java.security.cert.Certificate[]) definition code for java.security.CodeSource(java.net.URL, java.security.cert.Certificate[])

public CodeSource(URL sample code for java.net.URL definition code for java.net.URL  url,
                  Certificate sample code for java.security.cert.Certificate definition code for java.security.cert.Certificate [] certs)
Constructs a CodeSource and associates it with the specified location and set of certificates.

Parameters:
url - the location (URL).
certs - the certificate(s). It may be null. The contents of the array are copied to protect against subsequent modification.

CodeSource sample code for java.security.CodeSource(java.net.URL, java.security.CodeSigner[]) definition code for java.security.CodeSource(java.net.URL, java.security.CodeSigner[])

public CodeSource(URL sample code for java.net.URL definition code for java.net.URL  url,
                  CodeSigner sample code for java.security.CodeSigner definition code for java.security.CodeSigner [] signers)
Constructs a CodeSource and associates it with the specified location and set of code signers.

Parameters:
url - the location (URL).
signers - the code signers. It may be null. The contents of the array are copied to protect against subsequent modification.
Since:
1.5
Method Detail

hashCode sample code for java.security.CodeSource.hashCode() definition code for java.security.CodeSource.hashCode()

public int hashCode()
Returns the hash code value for this object.

Overrides:
hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

equals sample code for java.security.CodeSource.equals(java.lang.Object) definition code for java.security.CodeSource.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.Object  obj)
Tests for equality between the specified object and this object. Two CodeSource objects are considered equal if their locations are of identical value and if their signer certificate chains are of identical value. It is not required that the certificate chains be in the same order.

Overrides:
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) in class Object sample code for java.lang.Object definition code for java.lang.Object
Parameters:
obj - the object to test for equality with this object.
Returns:
true if the objects are considered equal, false otherwise.
See Also:
Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

getLocation sample code for java.security.CodeSource.getLocation() definition code for java.security.CodeSource.getLocation()

public final URL sample code for java.net.URL definition code for java.net.URL  getLocation()
Returns the location associated with this CodeSource.

Returns:
the location (URL).

getCertificates sample code for java.security.CodeSource.getCertificates() definition code for java.security.CodeSource.getCertificates()

public final Certificate sample code for java.security.cert.Certificate definition code for java.security.cert.Certificate [] getCertificates()
Returns the certificates associated with this CodeSource.

If this CodeSource object was created using the CodeSource(URL url, CodeSigner[] signers) sample code for java.security.CodeSource.CodeSource(java.net.URL, java.security.CodeSigner[]) definition code for java.security.CodeSource.CodeSource(java.net.URL, java.security.CodeSigner[]) constructor then its certificate chains are extracted and used to create an array of Certificate objects. Each signer certificate is followed by its supporting certificate chain (which may be empty). Each signer certificate and its supporting certificate chain is ordered bottom-to-top (i.e., with the signer certificate first and the (root) certificate authority last).

Returns:
A copy of the certificates array, or null if there is none.

getCodeSigners sample code for java.security.CodeSource.getCodeSigners() definition code for java.security.CodeSource.getCodeSigners()

public final CodeSigner sample code for java.security.CodeSigner definition code for java.security.CodeSigner [] getCodeSigners()
Returns the code signers associated with this CodeSource.

If this CodeSource object was created using the CodeSource(URL url, Certificate[] certs) sample code for java.security.CodeSource.CodeSource(java.net.URL, java.security.cert.Certificate[]) definition code for java.security.CodeSource.CodeSource(java.net.URL, java.security.cert.Certificate[]) constructor then its certificate chains are extracted and used to create an array of CodeSigner objects. Note that only X.509 certificates are examined - all other certificate types are ignored.

Returns:
A copy of the code signer array, or null if there is none.
Since:
1.5

implies sample code for java.security.CodeSource.implies(java.security.CodeSource) definition code for java.security.CodeSource.implies(java.security.CodeSource)

public boolean implies(CodeSource sample code for java.security.CodeSource definition code for java.security.CodeSource  codesource)
Returns true if this CodeSource object "implies" the specified CodeSource.

More specifically, this method makes the following checks, in order. If any fail, it returns false. If they all succeed, it returns true.

  1. codesource must not be null.
  2. If this object's certificates are not null, then all of this object's certificates must be present in codesource's certificates.
  3. If this object's location (getLocation()) is not null, then the following checks are made against this object's location and codesource's:

    1. codesource's location must not be null.
    2. If this object's location equals codesource's location, then return true.
    3. This object's protocol (getLocation().getProtocol()) must be equal to codesource's protocol.
    4. If this object's host (getLocation().getHost()) is not null, then the SocketPermission constructed with this object's host must imply the SocketPermission constructed with codesource's host.
    5. If this object's port (getLocation().getPort()) is not equal to -1 (that is, if a port is specified), it must equal codesource's port.
    6. If this object's file (getLocation().getFile()) doesn't equal codesource's file, then the following checks are made: If this object's file ends with "/-", then codesource's file must start with this object's file (exclusive the trailing "-"). If this object's file ends with a "/*", then codesource's file must start with this object's file and must not have any further "/" separators. If this object's file doesn't end with a "/", then codesource's file must match this object's file with a '/' appended.
    7. If this object's reference (getLocation().getRef()) is not null, it must equal codesource's reference.

For example, the codesource objects with the following locations and null certificates all imply the codesource with the location "http://java.sun.com/classes/foo.jar" and null certificates:

     http:
     http://*.sun.com/classes/*
     http://java.sun.com/classes/-
     http://java.sun.com/classes/foo.jar
 
Note that if this CodeSource has a null location and a null certificate chain, then it implies every other CodeSource.

Parameters:
codesource - CodeSource to compare against.
Returns:
true if the specified codesource is implied by this codesource, false if not.

toString sample code for java.security.CodeSource.toString() definition code for java.security.CodeSource.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns a string describing this CodeSource, telling its URL and certificates.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
information about this CodeSource.