FileDocCategorySizeDatePackage
SignedStaticContent.javaAPI DocGlassfish v2 API7674Fri May 04 22:34:12 BST 2007com.sun.enterprise.appclient.jws

SignedStaticContent

public class SignedStaticContent extends StaticContent
Represents a jar file that is signed before being served in response to a Java Web Start request. Signing occurs when the jar is first requested.
author
tjquinn

Fields Summary
private final File
unsignedJar
the unsigned jar to be served in signed form
private final File
signedJar
the signed jar
private URI
installRootURI
URI for the app server installation root
private final Logger
logger
private final com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public SignedStaticContent(ContentOrigin origin, String contentKey, String path, File signedJar, File unsignedJar, URI installRootURI, com.sun.enterprise.util.i18n.StringManager localStrings, boolean isMain)
Creates a new instance of SignedStaticContent

param
origin the origin from which the jar to be signed comes
param
contentKey key by which this jar will be retrievable when requested
param
path the relative path within the app server to the jar
param
signedJar specifies what the resulting signed jar file should be
param
unsignedjar the existing unsigned jar to be signed just-in-time
param
installRootURI the app server's installation directory
param
isMain indicates if the jar contains the mail class that Java Web Start should launch

    
    
                                                                                                
    
     
              
              
              
             
              
             
             
                
        super(origin, contentKey, path, signedJar, installRootURI, isMain);
        
        /*
         *Find out as much as we can in order to sign the jar, but do not sign it yet.
         */
        this.installRootURI = installRootURI;
        this.unsignedJar = unsignedJar;
        this.signedJar = signedJar;
        this.localStrings = localStrings;
    
Methods Summary
private booleancheckUserAlias(java.security.KeyStore keystore, java.lang.String candidateAlias)
Returns whether the specified alias is present in the keystore or not. Also logs a warning if the user-specified alias is missing.

param
keystore the keystore to use in checking the user alias
param
candidateAlias the alias to look for
return
true if the alias is present in the keystore; false otherwise
throws
KeyStoreException in case of error accessing the keystore

        boolean result;
        if ( ! (result = keystore.containsAlias(candidateAlias)) ) {
            logger.warning(localStrings.getString("jws.sign.userAliasAbsent", candidateAlias));
        }
        return result;
    
private synchronized voidensureSignedFileUpToDate()
Makes sure that the signed jar exists and is up-to-date compared to the corresponding unsigned jar. If not, create a new signed jar using the alias provided on this object's constructor.

throws
KeyStoreException in case of errors reading the key store
throws
IllegalArgumentException if the unsigned jar does not exists

        /*
         *Check to see if the signed version of this jar is present.
         */
        if ( ! unsignedJar.exists()) {
            throw new IllegalArgumentException(
                    localStrings.getString("jws.sign.noUnsignedJar", unsignedJar.getAbsolutePath()));
        }

        if ( ! signedJar.exists() || (signedJar.lastModified() < unsignedJar.lastModified())) {
            signJar();
        }
    
private java.lang.StringgetKeystorePassword()
Returns the password for the keystore.

return
the keystore password

        return SSLUtils.getKeyStorePass();
    
public java.net.URIgetRelativeURI()
Returns the URI, relative to the app server installation directory, of the signed jar file to be published, signing the unsigned jar if needed to create the signed one to serve.

return
relative URI to the jar

        try {
            ensureSignedFileUpToDate();
            return installRootURI.relativize(signedJar.toURI());
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    
private voidsignJar()
Signs the jar file.

throws
Exception when signing the JAR or obtaining keystore information

        /*
         *In EE environments synchronization does not include empty directories.
         *So the java-web-start/<app-name> directory may not yet exist if this
         *is a non-DAS instance.  So just make sure the required directories
         *are created.
         */
        File signedJarParent = signedJar.getParentFile();
        if ( ! signedJarParent.exists() && ! signedJarParent.mkdirs() ) {
            throw new Exception(localStrings.getString("jws.sign.errorCreatingDir", signedJarParent.getAbsolutePath()));
        }
        
        ASJarSigner.signJar(unsignedJar, signedJar);