Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: JWT Authorizor #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/build-and-push-java-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build Docker

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
IMAGENAME: ${{ github.event.repository.name }}
TAG: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Docker build
uses: mr-smithers-excellent/docker-build-push@v6
id: build
with:
directory: java
image: ${{ env.IMAGENAME }}
dockerfile: java/Dockerfile
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
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
19 changes: 15 additions & 4 deletions java/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
FROM gradle:jdk17-jammy as builder

WORKDIR /build
COPY . ./
RUN gradle wrapper --gradle-version 8.1.1
RUN ./gradlew build -x test

##########################################################################
# Use official Tomcat base image
FROM tomcat:jre17

# Copy WAR file
COPY app/build/libs/vss-1.0.war /usr/local/tomcat/webapps/vss.war
COPY --from=builder /build/app/build/libs/vss-1.0.war /usr/local/tomcat/webapps/vss.war

ENV vss.jdbc.url="jdbc:postgresql://postgres:5432/postgres"
ENV vss.jdbc.username=postgres
ENV vss.jdbc.password=YOU_MUST_CHANGE_THIS_PASSWORD
# 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
Loading