public class

CodeSource

extends Object
implements Serializable
java.lang.Object
   ↳ java.security.CodeSource

Class Overview

CodeSource encapsulates the location from where code is loaded and the certificates that were used to verify that code. This information is used by SecureClassLoader to define protection domains for loaded classes.

Summary

Public Constructors
CodeSource(URL location, Certificate[] certs)
Constructs a new instance of CodeSource with the specified URL and the Certificates.
CodeSource(URL location, CodeSigner[] signers)
Constructs a new instance of CodeSource with the specified URL and the CodeSigners.
Public Methods
boolean equals(Object obj)
Compares the specified object with this CodeSource for equality.
final Certificate[] getCertificates()
Returns the certificates of this CodeSource.
final CodeSigner[] getCodeSigners()
Returns the CodeSigners of this CodeSource.
final URL getLocation()
Returns the location of this CodeSource.
int hashCode()
Returns the hash code value for this CodeSource.
boolean implies(CodeSource cs)
Indicates whether the specified code source is implied by this CodeSource.
String toString()
Returns a string containing a concise, human-readable description of the this CodeSource including its location, its certificates and its signers.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public CodeSource (URL location, Certificate[] certs)

Since: API Level 1

Constructs a new instance of CodeSource with the specified URL and the Certificates.

Parameters
location the URL representing the location from where code is loaded, maybe null.
certs the Certificate used to verify the code, loaded from the specified location, maybe null.

public CodeSource (URL location, CodeSigner[] signers)

Since: API Level 1

Constructs a new instance of CodeSource with the specified URL and the CodeSigners.

Parameters
location the URL representing the location from where code is loaded, maybe null.
signers the CodeSigners of the code, loaded from the specified location. Maybe null.

Public Methods

public boolean equals (Object obj)

Since: API Level 1

Compares the specified object with this CodeSource for equality. Returns true if the specified object is also an instance of CodeSource, points to the same URL location and the two code sources encapsulate the same Certificates. The order of the Certificates is ignored by this method.

Parameters
obj object to be compared for equality with this CodeSource.
Returns
  • true if the specified object is equal to this CodeSource, otherwise false.

public final Certificate[] getCertificates ()

Since: API Level 1

Returns the certificates of this CodeSource. If the CodeSource(URL, CodeSigner[]) constructor was used to create this instance, the certificates are obtained from the supplied signers.

External modifications of the returned Certificate[] has no impact on this CodeSource.

Returns
  • the certificates of this CodeSource or null if there is none.

public final CodeSigner[] getCodeSigners ()

Since: API Level 1

Returns the CodeSigners of this CodeSource. If the CodeSource(URL, Certificate[]) constructor was used to create this instance, the signers are obtained from the supplied certificates. Only X.509 certificates are analyzed.

Returns
  • the signers of this CodeSource, or null if there is none.

public final URL getLocation ()

Since: API Level 1

Returns the location of this CodeSource.

Returns
  • the location of this CodeSource, maybe null.

public int hashCode ()

Since: API Level 1

Returns the hash code value for this CodeSource. Returns the same hash code for CodeSources that are equal to each other as required by the general contract of hashCode().

Returns
  • the hash code value for this CodeSource.

public boolean implies (CodeSource cs)

Since: API Level 1

Indicates whether the specified code source is implied by this CodeSource. Returns true if all of the following conditions are true, otherwise false:

  • cs is not null
  • if this CodeSource has associated certificates, all certificates are present in cs. The certificates are extracted from the signers if signers are present.
  • if this CodeSource's location is not null, the following conditions are checked
    • this CodeSource's location is not null
    • this CodeSource's location protocol is equal to cs's location protocol
    • if this CodeSource's location host is not null, the following conditions are checked
      • cs's host is not null
      • the SocketPermission of this CodeSource's location host implies the SocketPermission of cs's location host
    • if this CodeSource's location port != -1 the port of cs's location is equal to this CodeSource's location port
    • this CodeSource's location file matches cs's file whereas special wildcard matching applies as described below
    • this CodeSource's location reference is equal to to cs's location reference

Note: If this CodeSource has a null location and not any certificates, this method returns true.

Matching rules for the CodeSource's location file:

  • if this CodeSource's location file ends with "/-", then cs's file must start with CodeSource's location file (exclusive the trailing '-')
  • if this CodeSource's location file ends with "/*", then cs's file must start with CodeSource's location file (exclusive the trailing '*') and must not have any further '/'
  • if this CodeSource's location file ends with "/", then cs's file must start with CodeSource's location file
  • if this CodeSource's location file does not end with "/", then cs's file must start with CodeSource's location file with the '/' appended to it.
Examples for locations that imply the location "http://harmony.apache.org/milestones/M9/apache-harmony.jar":
 http:
 http://*/milestones/M9/*
 http://*.apache.org/milestones/M9/*
 http://harmony.apache.org/milestones/-
 http://harmony.apache.org/milestones/M9/apache-harmony.jar
 

Parameters
cs the code source to check.
Returns
  • true if the argument code source is implied by this CodeSource, otherwise false.

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of the this CodeSource including its location, its certificates and its signers.

Returns
  • a printable representation for this CodeSource.