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: Updated project URL and add new endpoints for QTOTP #21

Merged
merged 7 commits into from
Nov 26, 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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

* Java 1.5 or above.

* Read API documentation (https://latch.telefonica.com/www/developers/doc_api).
* Read API documentation (https://latch.tu.com/www/developers/doc_api).

* To get the "Application ID" and "Secret", (fundamental values for integrating Latch in any application), it’s necessary to register a developer account in Latch's website: https://latch.telefonica.com. On the upper right side, click on "Developer area".
* To get the "Application ID" and "Secret", (fundamental values for integrating Latch in any application), it’s necessary to register a developer account in Latch's website: https://latch.tu.com. On the upper right side, click on "Developer area".


#### CREATING THE JAR DEPENDENCY ####
Expand Down Expand Up @@ -62,11 +62,11 @@ You need this additional parameters:
- WEB3SIGNATURE: A proof-of-ownership signature of a constant, in order to verify that the user owns the private key of the wallet. You can use https://etherscan.io/verifiedSignatures# to sign the following message:
- MESSAGE TO SIGN : **"Latch-Web3"**

Example of using it [java example](src/test/java/TestExampleWeb3.java)
Example of using it [java example](src/test/java/ExampleWeb3.java)


#### TROUBLESHOOTING ####

*A javax.net.ssl.SSLHandshakeException with a nested sun.security.validator.ValidatorException is thrown when invoking an API call.*

This exception is normally thrown when the JDK doesn't trust the CA that signs the digital certificate used in Latch's website (https://latch.telefonica.com). You may need to install the CA (http://www.startssl.com/certs/ca.pem) as a trusted certificate in your JDK's truststore (normally in jre/lib/security/cacerts) using the keytool utility.
This exception is normally thrown when the JDK doesn't trust the CA that signs the digital certificate used in Latch's website (https://latch.tu.com). You may need to install the CA (http://www.startssl.com/certs/ca.pem) as a trusted certificate in your JDK's truststore (normally in jre/lib/security/cacerts) using the keytool utility.
2 changes: 1 addition & 1 deletion src/main/java/com/elevenpaths/latch/Error.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*Latch Java SDK - Set of reusable classes to allow developers integrate Latch on their applications.
Copyright (C) 2023 Telefonica Digital
Copyright (C) 2024 Telefonica Innovación Digital

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/elevenpaths/latch/Latch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*Latch Java SDK - Set of reusable classes to allow developers integrate Latch on their applications.
Copyright (C) 2023 Telefonica Digital
Copyright (C) 2024 Telefonica Innovación Digital

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
175 changes: 174 additions & 1 deletion src/main/java/com/elevenpaths/latch/LatchApp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*Latch Java SDK - Set of reusable classes to allow developers integrate Latch on their applications.
Copyright (C) 2023 Telefonica Digital
Copyright (C) 2024 Telefonica Innovación Digital

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -157,6 +157,15 @@ public LatchResponse status(String accountId, boolean silent, String otpToken, S
return status(accountId, null, null, silent, otpToken, otpMessage);
}

/**
* Return operation status for a given accountId and operation while sending some custom data (Like OTP token or a message)
* @param accountId The accountId which status is going to be retrieved
* @param operationId The operationId which status is going to be retrieved
* @param silent True for not sending lock/unlock push notifications to the mobile devices, false otherwise.
* @param otpToken This will be the OTP sent to the user instead of generating a new one
* @param otpMessage To attach a custom message with the OTP to the user
* @return LatchResponse containing the status
*/
public LatchResponse status(String accountId, String operationId, boolean silent, String otpToken, String otpMessage) {
return status(accountId, operationId, null, silent, otpToken, otpMessage);
}
Expand All @@ -165,6 +174,7 @@ public LatchResponse status(String accountId, String operationId, boolean silent
* Return operation status for a given accountId and operation while sending some custom data (Like OTP token or a message)
* @param accountId The accountId which status is going to be retrieved
* @param operationId The operationId which status is going to be retrieved
* @param instanceId The instance identifier
* @param silent True for not sending lock/unlock push notifications to the mobile devices, false otherwise.
* @param otpToken This will be the OTP sent to the user instead of generating a new one
* @param otpMessage To attach a custom message with the OTP to the user
Expand All @@ -191,6 +201,13 @@ public LatchResponse status(String accountId, String operationId, String instanc
return HTTP_POST_proxy(url.toString(), data);
}

/**
* Create an instance
* @param accountId The user identified
* @param operationId The operation identifier
* @param instanceName The name for the instance
* @return LatchResponse containing the status
*/
public LatchResponse addInstance(String accountId, String operationId, String instanceName) {
StringBuilder url = new StringBuilder(API_INSTANCE_URL).append("/").append(accountId);
if (operationId != null && !operationId.isEmpty()) {
Expand All @@ -203,6 +220,13 @@ public LatchResponse addInstance(String accountId, String operationId, String in
return HTTP_PUT_proxy(url.toString(), data);
}

/**
* Remove the instance
* @param accountId The user identified
* @param operationId The operation identifier
* @param instanceId The instance identifier
* @return LatchResponse containing the status
*/
public LatchResponse removeInstance(String accountId, String operationId, String instanceId) {
StringBuilder url = new StringBuilder(API_INSTANCE_URL).append("/").append(accountId);
if (operationId != null && !operationId.isEmpty()) {
Expand All @@ -213,28 +237,65 @@ public LatchResponse removeInstance(String accountId, String operationId, String
}


/**
* Return operation status for a given accountId
* @param accountId The user identified
* @param operationId The operation identifier
* @return LatchResponse containing the status
*/
@Deprecated
public LatchResponse operationStatus(String accountId, String operationId) {
return status(accountId, operationId, null, false, false);
}

/**
* Return operation status for a given accountId
* @param accountId The user identified
* @param operationId The operation identifier
* @param silent True for not sending lock/unlock push notifications to the mobile devices, false otherwise
* @param noOtp True for not generating an OTP if needed
* @return LatchResponse containing the status
*/
@Deprecated
public LatchResponse operationStatus(String accountId, String operationId, boolean silent, boolean noOtp) {
return status(accountId, operationId, null, silent, noOtp);
}

/**
* Unpairs the origin provider with a user account.
* @param id The account identified
* @return LatchResponse containing the status
*/
public LatchResponse unpair(String id) {
return HTTP_GET_proxy(new StringBuilder(API_UNPAIR_URL).append("/").append(id).toString());
}

/**
* Locks the operation
* @param accountId The user identified
* @return LatchResponse containing the status
*/
public LatchResponse lock(String accountId) {
return lock(accountId, null);
}

/**
* Locks the operation
* @param accountId The user identified
* @param operationId The operation identifier
* @return LatchResponse containing the status
*/
public LatchResponse lock(String accountId, String operationId) {
return lock(accountId, operationId, null);
}

/**
* Locks the operation
* @param accountId The user identified
* @param operationId The operation identifier
* @param instanceId The instance identifier
* @return LatchResponse containing the status
*/
public LatchResponse lock(String accountId, String operationId, String instanceId) {
StringBuilder sb = new StringBuilder(API_LOCK_URL).append("/").append(accountId);
if (operationId != null && !operationId.isEmpty()) {
Expand All @@ -246,14 +307,32 @@ public LatchResponse lock(String accountId, String operationId, String instanceI
return HTTP_POST_proxy(sb.toString());
}

/**
* Unlocks the operation
* @param accountId The user identified
* @return LatchResponse containing the status
*/
public LatchResponse unlock(String accountId) {
return unlock(accountId, null);
}

/**
* Unlocks the operation
* @param accountId The user identified
* @param operationId The operation identifier
* @return LatchResponse containing the status
*/
public LatchResponse unlock(String accountId, String operationId) {
return unlock(accountId, operationId, null);
}

/**
* Unlocks the operation
* @param accountId The user identified
* @param operationId The operation identifier
* @param instanceId The instance identifier
* @return LatchResponse containing the status
*/
public LatchResponse unlock(String accountId, String operationId, String instanceId) {
StringBuilder sb = new StringBuilder(API_UNLOCK_URL).append("/").append(accountId);
if (operationId != null && !operationId.isEmpty()) {
Expand All @@ -265,16 +344,36 @@ public LatchResponse unlock(String accountId, String operationId, String instanc
return HTTP_POST_proxy(sb.toString());
}

/**
* Get history status
* @param accountId The user identified
* @return LatchResponse containing the status
*/
public LatchResponse history(String accountId) {
return HTTP_GET_proxy(new StringBuilder(API_HISTORY_URL).append("/").append(accountId).toString());
}

/**
* Get history status
* @param accountId The user identified
* @param from From in epoch format
* @param to To in epoch format
* @return LatchResponse containing the status
*/
public LatchResponse history(String accountId, Long from, Long to) {
return HTTP_GET_proxy(new StringBuilder(API_HISTORY_URL).append("/").append(accountId)
.append("/").append(from != null ? String.valueOf(from) :"0")
.append("/").append(to != null ? String.valueOf(to) : String.valueOf(new Date().getTime())).toString());
}

/**
* Add a new operation
* @param parentId identifies the parent of the operation to be created
* @param name The name of the operation
* @param twoFactor Specifies if the Two Factor protection is enabled for this operation
* @param lockOnRequest Specifies if the 'Lock latches on status request' feature is disabled, opt-in or mandatory for this operation
* @return LatchResponse containing the status
*/
public LatchResponse createOperation(String parentId, String name, String twoFactor, String lockOnRequest) {
Map<String, String> data = new HashMap<String, String>();
data.put("parentId", parentId);
Expand All @@ -284,18 +383,40 @@ public LatchResponse createOperation(String parentId, String name, String twoFac
return HTTP_PUT_proxy(new StringBuilder(API_OPERATION_URL).toString(), data);
}

/**
* Remove an operation
* @param operationId The operation identifier
* @return LatchResponse containing the status
*/
public LatchResponse removeOperation(String operationId) {
return HTTP_DELETE_proxy(new StringBuilder(API_OPERATION_URL).append("/").append(operationId).toString());
}

/**
* Get information about the operation
* @return LatchResponse containing the status
*/
public LatchResponse getOperations() {
return HTTP_GET_proxy(new StringBuilder(API_OPERATION_URL).toString());
}

/**
* Get information about the operation
* @param operationId The operation identifier
* @return LatchResponse containing the status
*/
public LatchResponse getOperations(String operationId) {
return HTTP_GET_proxy(new StringBuilder(API_OPERATION_URL).append("/").append(operationId).toString());
}

/**
* Update an operation
* @param operationId The operation identifier
* @param name The name of the operation
* @param twoFactor Specifies if the Two Factor protection is enabled for this operation
* @param lockOnRequest Specifies if the 'Lock latches on status request' feature is disabled, opt-in or mandatory for this operation
* @return LatchResponse containing the status
*/
public LatchResponse updateOperation(String operationId, String name, String twoFactor, String lockOnRequest) {
Map<String, String> data = new HashMap<String, String>();
data.put("name", name);
Expand All @@ -304,4 +425,56 @@ public LatchResponse updateOperation(String operationId, String name, String two
return HTTP_POST_proxy(new StringBuilder(API_OPERATION_URL).append("/").append(operationId).toString(), data);
}

/**
* Create a Time-based one-time password
* @param userId User identifier (mail)
* @param commonName Name for the Totp
* @return LatchResponse containing the status
*/
public LatchResponse createTotp(String userId, String commonName) {
Map<String, String> data = new HashMap<String, String>();
data.put("userId", userId);
data.put("commonName", commonName);
return HTTP_POST_proxy(API_TOTP_URL, data);
}

/**
* Get data information about the totp
* @param totpId Totp Identifier
* @return LatchResponse containing the status
*/
public LatchResponse getTotp(String totpId) {
return HTTP_GET_proxy(new StringBuilder(API_TOTP_URL).append("/").append(totpId).toString());
}

/**
* Validate a code from a totp
* @param totpId Totp Identifier
* @param code Code generated
* @return LatchResponse containing the status
*/
public LatchResponse validateTotp(String totpId, String code) {
Map<String, String> data = new HashMap<String, String>();
data.put("code", code);
return HTTP_POST_proxy(new StringBuilder(API_TOTP_URL).append("/").append(totpId).append("/validate").toString(), data);
}

/**
* Remove a totp
* @param totpId Totp Identifier
* @return LatchResponse containing the status
*/
public LatchResponse removeTotp(String totpId) {
return HTTP_DELETE_proxy(new StringBuilder(API_TOTP_URL).append("/").append(totpId).toString());
}

/**
* Check operation status
* @param controlId Control status identifier
* @return LatchResponse containing the status
*/
public LatchResponse checkControlStatus(String controlId) {
return HTTP_GET_proxy(new StringBuilder(API_CONTROL_STATUS_CHECK_URL).append("/").append(controlId).toString());
}

}
6 changes: 4 additions & 2 deletions src/main/java/com/elevenpaths/latch/LatchAuth.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*Latch Java SDK - Set of reusable classes to allow developers integrate Latch on their applications.
Copyright (C) 2023 Telefonica Digital
Copyright (C) 2024 Telefonica Innovación Digital

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -48,7 +48,7 @@
*/
public class LatchAuth {
protected static final String API_VERSION = "2.0";
public static String API_HOST = "https://latch.telefonica.com";
public static String API_HOST = "https://latch.tu.com";

//App API
public static final String API_CHECK_STATUS_URL = "/api/"+API_VERSION+"/status";
Expand All @@ -60,6 +60,8 @@ public class LatchAuth {
public static final String API_HISTORY_URL = "/api/"+API_VERSION+"/history";
public static final String API_OPERATION_URL = "/api/"+API_VERSION+"/operation";
public static final String API_INSTANCE_URL = "/api/"+API_VERSION+"/instance";
public static final String API_TOTP_URL = "/api/" + API_VERSION + "/totps";
public static final String API_CONTROL_STATUS_CHECK_URL = "/api/" + API_VERSION + "/control-status";

//User API
public static final String API_APPLICATION_URL = "/api/"+API_VERSION+"/application";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/elevenpaths/latch/LatchResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*Latch Java SDK - Set of reusable classes to allow developers integrate Latch on their applications.
Copyright (C) 2023 Telefonica Digital
Copyright (C) 2024 Telefonica Innovación Digital

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/elevenpaths/latch/LatchUser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*Latch Java SDK - Set of reusable classes to allow developers integrate Latch on their applications.
Copyright (C) 2023 Telefonica Digital
Copyright (C) 2024 Telefonica Innovación Digital

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
Loading