Skip to content

Commit

Permalink
Implemented Config.java
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbalakirev committed Jun 28, 2024
1 parent 748a7c2 commit 887301e
Showing 1 changed file with 170 additions and 7 deletions.
177 changes: 170 additions & 7 deletions src/main/java/com/corbado/sdk/Config.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,179 @@
package com.corbado.sdk;

/** Configuration class. */
import java.net.MalformedURLException;
import java.net.URL;

/**
* Configuration class for setting up project parameters.
*
* <p>This class encapsulates project configuration details including project ID, API secret,
* backend API URL, and other parameters. It provides validation for these fields and computes
* derived properties like frontend API URL and issuer.
*/
public class Config {

/** The i. */
private int i;
// Fields

/** The project id. */
private String projectId;

/** The api secret. */
private String apiSecret;

/** The backend api. */
private String backendApi = "https://backendapi.corbado.io";

/** The short session cookie name. */
private String shortSessionCookieName = "cbo_short_session";

/** The issuer. */
private String issuer;

/** The frontend api. */
private String frontendApi;

/**
* Instantiates a new config.
*
* @param projectId the project id
* @param apiSecret the api secret
*/
// Constructors
public Config(String projectId, String apiSecret) {
this.projectId = projectId;
this.apiSecret = apiSecret;

// default values
this.frontendApi = "https://" + projectId + ".frontendapi.corbado.io";
this.issuer = this.frontendApi;
}

/**
* Gets the api secret.
*
* @return the api secret
*/
public String getApiSecret() {
return this.apiSecret;
}

/**
* Gets the backend api.
*
* @return the backend api
*/
public String getBackendApi() {
return this.backendApi;
}

/**
* Gets the frontend api.
*
* @return the frontend api
*/
public String getFrontendApi() {
return this.frontendApi;
}

/**
* Gets the issuer.
*
* @return the issuer
*/
public String getIssuer() {
return this.issuer;
}

// Getters and Setters
/**
* Gets the project id.
*
* @return the project id
*/
public String getProjectId() {
return this.projectId;
}

/**
* Gets the short session cookie name.
*
* @return the short session cookie name
*/
public String getShortSessionCookieName() {
return this.shortSessionCookieName;
}

/**
* Sets the api secret.
*
* @param apiSecret the new api secret
* @throws IllegalArgumentException If the API secret does not start with "corbado1_".
*/
public void setApiSecret(String apiSecret) {
if (!apiSecret.startsWith("corbado1_")) {
throw new IllegalArgumentException("Invalid API Secret, must start with 'corbado1_'");
}
this.apiSecret = apiSecret;
}

/**
* Sets the backend api.
*
* @param backendApi the new backend api
* @throws IllegalArgumentException If the URL is invalid.
*/
public void setBackendApi(String backendApi) {
try {
new URL(backendApi); // Validate URL syntax
} catch (final MalformedURLException e) {
throw new IllegalArgumentException("Invalid backend API URL: " + e.getMessage());
}
this.backendApi = backendApi;
}

/**
* Sets the frontend api.
*
* @param frontendApi the new frontend api
* @throws IllegalArgumentException If the URL is invalid.
*/
public void setFrontendApi(String frontendApi) {
try {
new URL(frontendApi); // Validate URL syntax
} catch (final MalformedURLException e) {
throw new IllegalArgumentException("Invalid frontend API URL: " + e.getMessage());
}
this.frontendApi = frontendApi;
}

/**
* Sets the issuer.
*
* @param issuer the new issuer
*/
public void setIssuer(String issuer) {
this.issuer = issuer;
}

public int getI() {
return this.i;
/**
* Sets the project id.
*
* @param projectId the new project id
* @throws IllegalArgumentException If the project Id does not start with "pro-".
*/
public void setProjectId(String projectId) {
if (!projectId.startsWith("pro-")) {
throw new IllegalArgumentException("Invalid project ID, must start with 'pro-'");
}
this.projectId = projectId;
}

public void setI(int i) {
this.i = i;
/**
* Sets the short session cookie name.
*
* @param shortSessionCookieName the new short session cookie name
*/
public void setShortSessionCookieName(String shortSessionCookieName) {
this.shortSessionCookieName = shortSessionCookieName;
}
}

0 comments on commit 887301e

Please sign in to comment.