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

Merged
merged 3 commits into from
Dec 10, 2024
Merged
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
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
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