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

8 adapt to reference implementation #9

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
23c74cd
Add .env.example
alexbalakirev Oct 26, 2024
3348023
Make frontend api required for config
alexbalakirev Oct 27, 2024
01707b0
Renamed short-term session to session-token
alexbalakirev Oct 27, 2024
06a0157
Change short-term session naming to session-token naming
alexbalakirev Oct 27, 2024
5a897c4
Renamed getAndValidateUserFromShortSessionValue to validateToken,
alexbalakirev Oct 27, 2024
d95ed11
Apply getAndValidateCurrentUser renaming for tests
alexbalakirev Oct 27, 2024
7892b8a
Bump version for major release
alexbalakirev Oct 27, 2024
2245aa0
Refactor SDK version in code to a constant
alexbalakirev Oct 27, 2024
f406a5b
Add TokenValidationException class
alexbalakirev Oct 27, 2024
eb5e607
Adapt Session Service to reference implementation
alexbalakirev Oct 28, 2024
b59e1c4
Remove example .env from sdk
alexbalakirev Nov 3, 2024
15c36aa
Removed sessionTokenCookieName, reorder Mandatory fields in config
alexbalakirev Nov 3, 2024
afad0f7
Rename error codes for ValidationErrorType
alexbalakirev Nov 3, 2024
cda0742
Change CORBADO_FRONTEND_API from variable to secret in CI/CD
alexbalakirev Nov 3, 2024
0d357f5
Fix alignment of secrets in ci.yml
alexbalakirev Nov 12, 2024
5c27138
Update generated OpenAPI code
alexbalakirev Dec 15, 2024
33fc47a
Fix RSA key name for session service test
alexbalakirev Dec 15, 2024
9a1694c
Change CORBADO_FRONTEND_API from secret to variable in ci workflow
alexbalakirev Dec 15, 2024
d0a077c
Adjust ci workflow to ignore certain files and commit types
alexbalakirev Dec 15, 2024
207559b
Fix alignment in ci.yml
alexbalakirev Dec 15, 2024
137f65f
style: format IdentifierService
alexbalakirev Dec 15, 2024
012736a
style: fix import ordering and other minor checkstyle issues
alexbalakirev Dec 15, 2024
4ec2a1d
Bump SDK version to 2.0.0b (beta version)
alexbalakirev Dec 15, 2024
d56a2a0
Update ci.yml
alexbalakirev Dec 15, 2024
0c9e57d
Update cache action to v4
alexbalakirev Dec 15, 2024
1f2a270
Remove unused code
alexbalakirev Feb 8, 2025
97993ab
Update GitHub CI artifacts
alexbalakirev Feb 8, 2025
e1af680
Update OpenApi client
alexbalakirev Feb 8, 2025
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
25 changes: 16 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
- development
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
paths-ignore:
- '**/*.md' # Ignore markdown files
- '**/LICENSE'
- 'scripts/**'
pull_request:
branches:
- main
Expand All @@ -23,6 +27,7 @@ on:

jobs:
build:
if: "!startsWith(github.event.head_commit.message, 'style:') && !startsWith(github.event.head_commit.message, 'docs:')" #do not run workflow on style or documentation changes
name: Build
runs-on: ubuntu-latest

Expand All @@ -38,7 +43,7 @@ jobs:
architecture: x64

- name: Cache Maven dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ hashFiles('**/src/**') }}
Expand All @@ -57,12 +62,13 @@ jobs:

- name: Save Maven build artifacts
if: success()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: maven-artifacts
path: target/

test:
if: "!startsWith(github.event.head_commit.message, 'style:') && !startsWith(github.event.head_commit.message, 'docs:')" #do not run workflow on style or documentation changes
name: Test
runs-on: ubuntu-latest
needs: build # Ensure build job runs before this one
Expand All @@ -77,7 +83,7 @@ jobs:
uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: maven-artifacts

Expand All @@ -89,7 +95,7 @@ jobs:
architecture: x64

- name: Cache Maven dependencies for tests
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ matrix.java-version }}-${{ hashFiles('**/pom.xml') }}-${{ hashFiles('**/src/**') }}
Expand All @@ -98,9 +104,10 @@ jobs:

- name: Run test suite
env:
CORBADO_API_SECRET: ${{ secrets.CORBADO_API_SECRET }}
CORBADO_PROJECT_ID: ${{ secrets.CORBADO_PROJECT_ID }}
CORBADO_BACKEND_API: ${{ vars.CORBADO_BACKEND_API }}
CORBADO_PROJECT_ID: ${{ secrets.CORBADO_PROJECT_ID }}
CORBADO_API_SECRET: ${{ secrets.CORBADO_API_SECRET }}
CORBADO_FRONTEND_API: ${{ vars.CORBADO_FRONTEND_API }}
CORBADO_BACKEND_API: ${{ vars.CORBADO_BACKEND_API }}
run: mvn --batch-mode --update-snapshots verify -DskipInstall

deploy:
Expand All @@ -114,7 +121,7 @@ jobs:
uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: maven-artifacts

Expand All @@ -128,7 +135,7 @@ jobs:
server-id: central

- name: Cache Maven dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ hashFiles('**/src/**') }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You can find the latest SDK version at [central repository](https://repo1.maven.
Add this dependency to your project's build file:

```groovy
implementation "com.corbado:corbado-java:1.0.4"
implementation "com.corbado:corbado-java:2.0.0b"
```

#### Maven users
Expand All @@ -38,7 +38,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.corbado</groupId>
<artifactId>corbado-java</artifactId>
<version>1.0.4</version>
<version>2.0.0b</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.4
2.0.0b
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.corbado</groupId>
<artifactId>corbado-java</artifactId>
<packaging>jar</packaging>
<version>1.0.4</version>
<version>2.0.0b</version>
<name>Corbado Java</name>
<description>Corbado Java SDK</description>
<url>https://github.com/corbado/corbado-java</url>
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/com/corbado/entities/SessionValidationResult.java

This file was deleted.

49 changes: 49 additions & 0 deletions src/main/java/com/corbado/enums/exception/ValidationErrorType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.corbado.enums.exception;

import com.corbado.exceptions.TokenValidationException;

/** Enum representing error types for {@link TokenValidationException}. */
public enum ValidationErrorType {

/** The invalid token. */
CODE_INVALID_TOKEN("Invalid token"),

/** The empty session token. */
CODE_EMPTY_SESSION_TOKEN("Session token is empty"),

/** The empty issuer. */
CODE_EMPTY_ISSUER("Issuer is empty"),

CODE_JWT_BEFORE("Token is not valid yet"),

CODE_JWT_EXPIRED("Token is expired"),

CODE_INVALID_PUBLIC_KEY("Public key is invalid"),

CODE_JWT_INVALID_SIGNATURE("Token signature is invalid"),

/** The issuer missmatch. */
CODE_ISSUER_MISSMATCH("Token issuer does not match");

/** The description. */
private final String description;

/**
* Instantiates a new validation error type.
*
* @param description the description
*/
ValidationErrorType(final String description) {
this.description = description;
}

/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
return this.description;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.corbado.exceptions;

import com.corbado.generated.invoker.ApiException;
import com.google.gson.Gson;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import com.corbado.generated.invoker.ApiException;
import com.google.gson.Gson;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/com/corbado/exceptions/TokenValidationException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.corbado.exceptions;

import com.corbado.enums.exception.ValidationErrorType;
import lombok.Getter;

/**
* TokenValidationException is a custom exception used to indicate issues during token validation.
* This exception is typically thrown when the token's issuer, format, or other key attributes do
* not meet the expected validation criteria.
*
* <p>This exception wraps a specific {@link ValidationErrorType} enum value to categorize the type
* of validation error encountered, and it provides a descriptive message detailing the reason for
* the exception. Additionally, it can wrap an underlying exception that caused the validation
* failure, allowing for more detailed error tracing.
*
* <p>Typical usage includes handling invalid token attributes, such as missing or mismatched
* issuers, empty tokens, or other validation failures.
*
* <p>Example usage:
*
* <pre>{@code
* try {
* validateToken(token);
* } catch (SomeOtherException e) {
* throw new TokenValidationException(ValidationErrorType.ISSUER_MISMATCH,
* "Issuer mismatch (configured issuer: 'expected.com', JWT issuer: 'actual.com')", e);
* }
* }</pre>
*
* @see ValidationErrorType
*/
public class TokenValidationException extends RuntimeException {

/** The Constant serialVersionUID. */
@Getter private static final long serialVersionUID = -2978676337061777870L;

/** The error type. */
@Getter private final ValidationErrorType errorType;

/**
* Constructs a new TokenValidationException with a specified error type, a detailed message, and
* an optional original exception that caused this validation failure.
*
* @param errorType the type of validation error encountered, represented by {@link
* ValidationErrorType}
* @param message a descriptive message providing additional context for the validation error
* @param cause the original exception that caused this validation failure, if any
*/
public TokenValidationException(
final ValidationErrorType errorType, final String message, final Throwable cause) {
super(message, cause);
this.errorType = errorType;
}

/**
* Constructs a new TokenValidationException with a specified error type and detailed message,
* without an underlying cause.
*
* @param errorType the type of validation error encountered, represented by {@link
* ValidationErrorType}
* @param message a descriptive message providing additional context for the validation error
*/
public TokenValidationException(final ValidationErrorType errorType, final String message) {
super(message);
this.errorType = errorType;
}
}
12 changes: 8 additions & 4 deletions src/main/java/com/corbado/generated/api/AuthEventsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public void setCustomBaseUrl(String customBaseUrl) {
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table summary="Response Details" border="1">
<table border="1">
<caption>Response Details</caption>
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> Auth event has been created </td><td> - </td></tr>
<tr><td> 0 </td><td> Error </td><td> - </td></tr>
Expand Down Expand Up @@ -158,7 +159,8 @@ private okhttp3.Call authEventCreateValidateBeforeCall(String userID, AuthEventC
* @return AuthEvent
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<table border="1">
<caption>Response Details</caption>
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> Auth event has been created </td><td> - </td></tr>
<tr><td> 0 </td><td> Error </td><td> - </td></tr>
Expand All @@ -177,7 +179,8 @@ public AuthEvent authEventCreate(String userID, AuthEventCreateReq authEventCrea
* @return ApiResponse&lt;AuthEvent&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<table border="1">
<caption>Response Details</caption>
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> Auth event has been created </td><td> - </td></tr>
<tr><td> 0 </td><td> Error </td><td> - </td></tr>
Expand All @@ -198,7 +201,8 @@ public ApiResponse<AuthEvent> authEventCreateWithHttpInfo(String userID, AuthEve
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
* @http.response.details
<table summary="Response Details" border="1">
<table border="1">
<caption>Response Details</caption>
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> Auth event has been created </td><td> - </td></tr>
<tr><td> 0 </td><td> Error </td><td> - </td></tr>
Expand Down
Loading