Skip to content

Commit

Permalink
feat: JWT Authorizor
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Nov 5, 2024
1 parent 8fc2218 commit 94b7020
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ app/.classpath
app/.project
app/.settings

java/.gradle
java/app/build
java/gradle
3 changes: 3 additions & 0 deletions java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ FROM tomcat:jre17
# Copy WAR file
COPY app/build/libs/vss-1.0.war /usr/local/tomcat/webapps/vss.war

# All the below are defaults.
# Pass real values as env variables.
ENV vss.jdbc.url="jdbc:postgresql://postgres:5432/postgres"
ENV vss.jdbc.username=postgres
ENV vss.jdbc.password=YOU_MUST_CHANGE_THIS_PASSWORD
ENV vss.jwt.pubkey="-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq3t7q3HXhyTWS0nWnY+YIYqEwh/Z/Jtwk0DgkqxF455gdzVlSyLyz5NQfXua1jW437/SMEcbHLWcwjxcowj1jvh9blGpvx+xPNH72J5ruDzrh5fhoq2XC7zNt1UVcjkMIlddP4pwK4fV5FrxOWvmxst3Ngp6ShNg5H0yiMTDBF+QqFhRlVqnO4IrIKczxd/VxCXSKJvKjM357n0PVD1KYFT3FJ5fN+d7Fdko16NbfQDDPsfQchfLAF2Tn/r4KZFzCovCQAt7cKDLHl87TvoHVZ4QBGHDIk/w1cig/gERtTqHECVg+wVctWfx6lb+9YG/4/9UgTQpDxAWVaFVd49CwQIDAQAB-----END PUBLIC KEY-----"

EXPOSE 8080
CMD ["catalina.sh", "run"]
4 changes: 4 additions & 0 deletions java/app/src/main/java/org/vss/auth/JwtAuthorizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public JwtAuthorizer(String pemFormatRSAPublicKey) throws Exception {
this.verifier = JWT.require(algorithm).build();
}

public JwtAuthorizer() throws Exception {
this(System.getenv("vss.jwt.pubkey"));
}

@Override
public AuthResponse verify(HttpHeaders headers) throws AuthException {

Expand Down
5 changes: 3 additions & 2 deletions java/app/src/main/java/org/vss/guice/BaseModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.vss.auth.Authorizer;
import org.vss.auth.NoopAuthorizer;
import org.vss.impl.postgres.PostgresBackendImpl;
import org.vss.auth.JwtAuthorizer;

public class BaseModule extends AbstractModule {

Expand All @@ -24,8 +25,8 @@ protected void configure() {
// Provide PostgresBackend as default implementation for KVStore.
bind(KVStore.class).to(PostgresBackendImpl.class).in(Singleton.class);

// Default to Noop Authorizer.
bind(Authorizer.class).to(NoopAuthorizer.class).in(Singleton.class);
// Use JWT Authorizor.
bind(Authorizer.class).to(JwtAuthorizer.class).in(Singleton.class);
}

@Provides
Expand Down
3 changes: 2 additions & 1 deletion java/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ services:
depends_on:
- postgres
ports:
- "8080:8080"
# prevent conflict with Alby Hub in development
- "8090:8080"
networks:
- app-network

Expand Down

0 comments on commit 94b7020

Please sign in to comment.