| title | Java API Tutorial | ||||
|---|---|---|---|---|---|
| name | Java API | ||||
| thirdParty | false | ||||
| alias |
|
||||
| languages |
|
||||
| image | //auth0.com/lib/platforms-collection/img/java.png | ||||
| tags |
|
||||
| snippets |
|
<%= include('../_includes/package', { pkgRepo: 'auth0-java', pkgBranch: 'master', pkgPath: 'examples/java-api', pkgFilePath: null, pkgType: 'replace' + account.clientParam }) %>
Then, you just need to specify your Auth0 account configuration as enviroment variables. Check it here
Otherwise, Please follow the steps below to configure your existing Java app to use it with Auth0.
You need to add the java-jwt and commons-codec dependencies.
For that, you can just add them to your pom.xml if you're using maven.
${snippet(meta.snippets.dependencies)}
Dropwizard users: make sure to ignore the requests that contain
OPTIONSas method. You can do that by checking"OPTIONS".equals(request.getMethod())and callingchain.doFilter(request, response); return;inJWTFilter.
Now, you need to validate the JWT. For that, we'll use a Filter.
${snippet(meta.snippets.use)}
Please note that we're setting the URL Pattern to /api/* in this case. That means that we'll check the user is authenticated only if the request is to the API.
Please note that if you're using Servlets 2.5, you won't be able to use the @WebFilter annotation. In that case, add the following to your web.xml:
<filter>
<filter-name>JWTFilter</filter-name>
<filter-class>com.auth0.example.JWTFilter</filter-class>
</filter>
<!-- We are going to restrict /api/* paths -->
<filter-mapping>
<filter-name>JWTFilter</filter-name>
<url-pattern>/api/*</url-pattern>
</filter-mapping>Now you have both your FrontEnd and Backend configured to use Auth0. Congrats, you're awesome!