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);
}
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);
}
}
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);
}
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();
}
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;
}
}
Aggregations