diff --git a/box-java-servlet-skeleton-app/Dockerfile b/box-java-servlet-skeleton-app/Dockerfile index 5632bca..389e256 100644 --- a/box-java-servlet-skeleton-app/Dockerfile +++ b/box-java-servlet-skeleton-app/Dockerfile @@ -2,6 +2,7 @@ FROM tomcat:latest COPY ./UnlimitedJCEPolicyJDK8/* \ /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/ RUN ["rm", "-fr", "/usr/local/tomcat/webapps/ROOT"] +ADD ./config.json /usr/local/tomcat/ ADD ./target/servlet-with-box-and-auth0.war /usr/local/tomcat/webapps/ROOT.war EXPOSE 8080 CMD ["catalina.sh", "run"] \ No newline at end of file diff --git a/box-java-servlet-skeleton-app/README.md b/box-java-servlet-skeleton-app/README.md index dfc0942..047b820 100755 --- a/box-java-servlet-skeleton-app/README.md +++ b/box-java-servlet-skeleton-app/README.md @@ -35,7 +35,7 @@ If you don't install this, you'll get an exception about key length. This is not * *You may need to enter a 2-factor confirmation code.* * Save the JSON config file -- this config file also contains the private key generated for your application. * *Note: Box does not store the generated private key and this config file is the only copy of the private key. You can always delete this keypair from your application and generate a new keypair if you lose this config file.* -4. Be sure to add your configuration file to the `src > main > resource` directory. +4. Be sure to add your configuration file to the root of this project directory. 5. In the "CORS Allowed Origins" section, add `http://localhost:8080`. #### Step 2. Authorize the Application in Your Box Account @@ -49,7 +49,7 @@ If you don't install this, you'll get an exception about key length. This is not * Your application is now authorized to access your Box account. ##### Step 3. Add Configuration File to the Java App -1. Add your generated Box config file to `src > main > resource` and name the file `config.json`. +1. Add your generated Box config file to the root of this project and name the file `config.json`. #### Auth0 Configuration Additionally, since you manage the identity and authorization for your Box App Users within your Java application, you'll need an identity service to fully utilize JWT authentication on behalf of your App Users. diff --git a/box-java-servlet-skeleton-app/src/main/java/com/helpers/BoxHelper.java b/box-java-servlet-skeleton-app/src/main/java/com/helpers/BoxHelper.java index 471688e..a2caf57 100755 --- a/box-java-servlet-skeleton-app/src/main/java/com/helpers/BoxHelper.java +++ b/box-java-servlet-skeleton-app/src/main/java/com/helpers/BoxHelper.java @@ -7,6 +7,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -32,19 +33,14 @@ public class BoxHelper { static BoxConfig boxConfig; static { - Path configPath; - try { - System.out.println("Searching for file.."); - configPath = Paths.get(Thread.currentThread().getContextClassLoader().getResource(BOX_CONFIG).toURI()); - System.out.println(configPath.toString()); - try (BufferedReader reader = Files.newBufferedReader(configPath, Charset.forName("UTF-8"))) { - boxConfig = BoxConfig.readFrom(reader); - accessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES); - } catch (java.io.IOException e1) { - e1.printStackTrace(); - } - } catch (URISyntaxException e) { - e.printStackTrace(); + System.out.println("Searching for file.."); + Path configPath = Paths.get(String.join("", System.getProperty("user.dir"), File.separator, BOX_CONFIG)); + System.out.println(configPath.toString()); + try (BufferedReader reader = Files.newBufferedReader(configPath, Charset.forName("UTF-8"))) { + boxConfig = BoxConfig.readFrom(reader); + accessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES); + } catch (java.io.IOException e1) { + e1.printStackTrace(); } }