Search in sources :

Example 1 with StaticContent

use of org.glassfish.appclient.server.core.jws.servedcontent.StaticContent in project Payara by payara.

the class ApplicationSignedJARManager method developerSignedAppContentEntry.

private Map.Entry<URI, StaticContent> developerSignedAppContentEntry(URI absURIToFile) {
    final URI jarURIRelativeToApp = EARDirectoryServerURI.relativize(absURIToFile);
    StaticContent content = relURIToContent.get(absURIToFile);
    if (content == null) {
        content = new FixedContent(new File(absURIToFile));
        relURIToContent.put(jarURIRelativeToApp, content);
    }
    return new AbstractMap.SimpleEntry<URI, StaticContent>(jarURIRelativeToApp, content);
}
Also used : StaticContent(org.glassfish.appclient.server.core.jws.servedcontent.StaticContent) FixedContent(org.glassfish.appclient.server.core.jws.servedcontent.FixedContent) URI(java.net.URI) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 2 with StaticContent

use of org.glassfish.appclient.server.core.jws.servedcontent.StaticContent in project Payara by payara.

the class ApplicationSignedJARManager method processURI.

private void processURI(final Set<URI> processedJARs, final Map<String, Map<URI, StaticContent>> selectedAliases, final URI relURI, final String alias) {
    Map<URI, StaticContent> urisForSelectedAlias = selectedAliases.get(alias);
    if (urisForSelectedAlias == null) {
        urisForSelectedAlias = new HashMap<URI, StaticContent>();
        selectedAliases.put(alias, urisForSelectedAlias);
    }
    /*
         * Add this URI to the URIs to be associated with the specified alias.
         */
    urisForSelectedAlias.put(relURI, relURIToContent.get(relURI));
    /*
         * Record that we've processed this URI so we don't do so again.
         */
    processedJARs.add(relURI);
    /*
         * Now that we know we need to handle this alias, mark all other JARs
         * that are associated with this alias (and perhaps others) to be
         * finally grouped with this alias alone.
         */
    for (URI otherURI : signingAliasToRelURIs.get(alias)) {
        urisForSelectedAlias.put(otherURI, relURIToContent.get(otherURI));
        processedJARs.add(otherURI);
    }
}
Also used : StaticContent(org.glassfish.appclient.server.core.jws.servedcontent.StaticContent) URI(java.net.URI)

Example 3 with StaticContent

use of org.glassfish.appclient.server.core.jws.servedcontent.StaticContent in project Payara by payara.

the class ApplicationSignedJARManager method autoSignedAppContentEntry.

/*
     * Returns information about an auto-signed JAR for a given absolute URI and
     * alias, creating the auto-signed content object and adding it to the
     * data structures if it is not already present.
     */
private synchronized Map.Entry<URI, StaticContent> autoSignedAppContentEntry(final URI jarURIRelativeToApp, final URI absURIToFile) throws FileNotFoundException {
    StaticContent content = relURIToContent.get(jarURIRelativeToApp);
    if (content == null) {
        final File unsignedFile = new File(absURIToFile);
        final File signedFile = signedFileForLib(jarURIRelativeToApp, unsignedFile);
        content = new AutoSignedContent(unsignedFile, signedFile, autoSigningAlias, jarSigner, jarURIRelativeToApp.toASCIIString(), helper.appName());
        relURIToContent.put(jarURIRelativeToApp, content);
    } else {
        if (content instanceof AutoSignedContent) {
            content = AutoSignedContent.class.cast(content);
        } else {
            throw new RuntimeException(content.toString() + " != AutoSignedContent");
        }
    }
    return new AbstractMap.SimpleEntry(jarURIRelativeToApp, content);
}
Also used : StaticContent(org.glassfish.appclient.server.core.jws.servedcontent.StaticContent) JarFile(java.util.jar.JarFile) File(java.io.File) AutoSignedContent(org.glassfish.appclient.server.core.jws.servedcontent.AutoSignedContent)

Example 4 with StaticContent

use of org.glassfish.appclient.server.core.jws.servedcontent.StaticContent in project Payara by payara.

the class ApplicationSignedJARManager method addJAR.

/**
 * Adds a JAR to the manager, returning the URI to the file to be
 * served.  This might be an auto-signed file if the original JAR is
 * unsigned.
 * @param uriWithinAnchor relative URI to the JAR within the anchor directory for the app
 * @param jarURI URI to the JAR file in the app to be served
 * @return URI to the JAR file to serve (either the original file or an auto-signed copy of the original)
 * @throws IOException
 */
public URI addJAR(final URI uriWithinAnchor, final URI absJARURI) throws IOException {
    /*
         * This method accomplishes three things:
         *
         * 1. Adds an entry to the map from relative URIs to the corresponding
         * static content for the JAR, creating an auto-signed content instance
         * if needed for an unsigned JAR.
         *
         * 2. Adds to the map from relative URI to aliases with which the JAR
         * is signed.
         *
         * 3. Adds to the map from alias to relative URIs signed with that alias.
         */
    // relative URI -> StaticContent
    Map.Entry<URI, StaticContent> result;
    final ReadableArchive arch = archiveFactory.openArchive(absJARURI);
    final Manifest archiveMF = arch.getManifest();
    if (archiveMF == null) {
        return null;
    }
    if (!isArchiveSigned(archiveMF)) {
        /*
             * The developer did not sign this JARs, so arrange for it to be
             * auto-signed.
             */
        result = autoSignedAppContentEntry(uriWithinAnchor, absJARURI);
        updateAliasToURIs(result.getKey(), autoSigningAlias);
        updateURIToAliases(result.getKey(), autoSigningAlias);
    } else {
        /*
             * The developer did sign this JAR, possibly with many certs.
             * For each cert add an association between the signing alias and
             * the JAR.
             */
        result = developerSignedAppContentEntry(absJARURI);
        Collection<String> aliasesUsedToSignJAR = new ArrayList<String>();
        for (Enumeration<String> entryNames = arch.entries("META-INF/"); entryNames.hasMoreElements(); ) {
            final String entryName = entryNames.nextElement();
            final String alias = signatureEntryName(entryName);
            updateURIToAliases(result.getKey(), alias);
        }
        addAliasToURIsEntry(result.getKey(), aliasesUsedToSignJAR);
    }
    arch.close();
    return result.getKey();
}
Also used : StaticContent(org.glassfish.appclient.server.core.jws.servedcontent.StaticContent) ArrayList(java.util.ArrayList) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Manifest(java.util.jar.Manifest) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map) URI(java.net.URI)

Example 5 with StaticContent

use of org.glassfish.appclient.server.core.jws.servedcontent.StaticContent in project Payara by payara.

the class RestrictedContentAdapter method serviceContent.

protected boolean serviceContent(Request gReq, Response gResp) throws IOException {
    String relativeURIString = relativizeURIString(contextRoot, gReq.getRequestURI());
    /*
         * "Forbidden" seems like a more helpful response than "not found"
         * if the corresponding app client has been suspended.
         */
    if (state == State.SUSPENDED) {
        finishErrorResponse(gResp, HttpServletResponse.SC_FORBIDDEN);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine(logPrefix() + "is suspended; refused to serve static content requested using " + (relativeURIString == null ? "null" : relativeURIString));
        }
        return true;
    }
    if (relativeURIString == null) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine(logPrefix() + "Could not find static content requested using full request URI = " + gReq.getRequestURI() + " - relativized URI was null");
        }
        respondNotFound(gResp);
        return true;
    }
    /*
         * The Grizzly-managed cache could contain entries for non-existent
         * files that users request.  If the URI indicates it's a request for
         * static content make sure the requested URI is in the predefined staticContent
         * before having Grizzly serve it.
         *
         * Alternatively, if the URI indicates the request is for dynamic content
         * then handle that separately.
         *
         * If the request is for a URI in neither the static nor dynamic
         * content this adapter should serve, then just return a 404.
         */
    final StaticContent sc = content.get(relativeURIString);
    final URI requestURI = Util.getCodebase(gReq);
    if (sc != null && sc.isAvailable(requestURI)) {
        processContent(relativeURIString, gReq, gResp);
        return true;
    } else {
        finishErrorResponse(gResp, contentStateToResponseStatus(sc, requestURI));
        final String scString = (sc == null ? "null" : sc.toString());
        final String scStateString = (sc == null ? "null" : sc.state().toString());
        if (logger.isLoggable(Level.FINE)) {
            logger.fine(logPrefix() + "Found static content for " + gReq.getMethod() + ": " + relativeURIString + " -> " + scString + " but could not serve it; its state is " + scStateString);
        }
        return true;
    }
}
Also used : StaticContent(org.glassfish.appclient.server.core.jws.servedcontent.StaticContent) URI(java.net.URI)

Aggregations

StaticContent (org.glassfish.appclient.server.core.jws.servedcontent.StaticContent)13 URI (java.net.URI)7 File (java.io.File)6 JarFile (java.util.jar.JarFile)5 StreamedAutoSignedStaticContent (org.glassfish.appclient.server.core.jws.servedcontent.StreamedAutoSignedStaticContent)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AutoSignedContent (org.glassfish.appclient.server.core.jws.servedcontent.AutoSignedContent)2 IOException (java.io.IOException)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Manifest (java.util.jar.Manifest)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 FixedContent (org.glassfish.appclient.server.core.jws.servedcontent.FixedContent)1