This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from patientsknowbest/feature/PHR-7125_move_co…
…mmon_resources_to_pkb_common PHR-7125 Move common resources to pkb-common
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
config/src/main/java/com/pkb/common/config/LetterInvitationSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.pkb.common.config; | ||
|
||
import java.io.Serializable; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class LetterInvitationSettings implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public static final int DEFAULT_TOKEN_SIZE = 10; | ||
|
||
public static final int DEFAULT_ACCESS_CODE_SIZE = 10; | ||
|
||
public static final int DEFAULT_EXPIRY_IN_SECONDS = (int) TimeUnit.DAYS.toSeconds(70L); | ||
|
||
private int tokenSize; | ||
|
||
private int tokenExpiryInSeconds; | ||
|
||
private int accessCodeSize; | ||
|
||
public LetterInvitationSettings() { | ||
this(DEFAULT_TOKEN_SIZE, DEFAULT_EXPIRY_IN_SECONDS, DEFAULT_ACCESS_CODE_SIZE); | ||
} | ||
|
||
public LetterInvitationSettings(int tokenSize, int tokenExpiryInSeconds, int accessCodeSize) { | ||
if (tokenSize < DEFAULT_TOKEN_SIZE) { | ||
throw new IllegalArgumentException("Token size must be greater than " + DEFAULT_TOKEN_SIZE); | ||
} | ||
if (accessCodeSize < DEFAULT_ACCESS_CODE_SIZE) { | ||
throw new IllegalArgumentException("Access code size must be greater than " + DEFAULT_ACCESS_CODE_SIZE); | ||
} | ||
if (tokenExpiryInSeconds < 1) { | ||
throw new IllegalArgumentException("Token expiry must be greater than 0"); | ||
} | ||
|
||
this.tokenSize = tokenSize; | ||
this.tokenExpiryInSeconds = tokenExpiryInSeconds; | ||
this.accessCodeSize = accessCodeSize; | ||
} | ||
|
||
public int getTokenSize() { | ||
return tokenSize; | ||
} | ||
|
||
public int getTokenExpiryInSeconds() { | ||
return tokenExpiryInSeconds; | ||
} | ||
|
||
public int getAccessCodeSize() { | ||
return accessCodeSize; | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
error/src/main/java/com/pkb/common/error/SSOException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.pkb.common.error; | ||
|
||
/** | ||
* These would be helpful to document the error codes in user guide so that | ||
* end-user could try and recover in few exception condition | ||
* | ||
* E.g if NO_VALID_SSO_AUTH it means that either user hasn't generated SSO credentials | ||
* or hasn't configured the external system with newly generated credentials | ||
* | ||
* @author pravina | ||
* | ||
*/ | ||
public class SSOException extends RuntimeException { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = 5188967730485194183L; | ||
|
||
public enum ErrorCode { | ||
|
||
BAD_SSO_KEY(0, "SSO key supplied by external system is invalid"), | ||
NO_VALID_SSO_AUTH(1, "No valid SSO auth record found "), | ||
PRIVATE_KEY_DECRYPTION_ERROR(2, "Private key decryption error; SSO credentials requires reset"), | ||
SSO_AUTH_ENCRYPTION_ERROR(3, "Private key encryption error; SSO credentials requires reset"), | ||
NO_SSO_ID_LINK(4, "No valid SSO Id Link object found for sso username"); | ||
|
||
private final int code; | ||
private final String description; | ||
|
||
ErrorCode(int code, String description) { | ||
this.code = code; | ||
this.description = description; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return code + ": " + description; | ||
} | ||
|
||
} | ||
|
||
private ErrorCode errorCode; | ||
|
||
public SSOException(ErrorCode errorCode, String message) { | ||
super(message); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public SSOException(ErrorCode errorCode, String message, Throwable cause) { | ||
super(message, cause); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public ErrorCode getErrorCode() { | ||
return errorCode; | ||
} | ||
|
||
} |