com.cybersource.authsdk.util.Utility Maven / Gradle / Ivy
The newest version!
package com.cybersource.authsdk.util;
import java.security.cert.X509Certificate;
import java.util.StringTokenizer;
public class Utility {
private enum validationType {
HTTP_SIGNATURE, JWT
};
/**
* Checks whether the authentication type is rightly entered with no typo
* error.
*
* @param authenticationType
* : HTTP or JWT
* @return -true if valid authentication type else return false.
*/
public static boolean checkAuthenticationValidation(String authenticationType) {
boolean status = false;
if (authenticationType.equalsIgnoreCase(validationType.HTTP_SIGNATURE.toString())
|| authenticationType.equalsIgnoreCase(validationType.JWT.toString())) {
status = true;
}
return status;
}
/**
*
* @param requestTarget
* : request target from where we will retrieve Id
* @return id from request target.
*/
public static String retrieveGetIDFromRequestTarget(String requestTarget) {
StringTokenizer str = new StringTokenizer(requestTarget, "/");
String temp = null;
while (str.hasMoreTokens()) {
temp = str.nextToken();
if (temp.matches("^[0-9]+$")) {
return temp;
}
}
return temp;
}
public static String extractSerialNumber(X509Certificate x509Certificate) {
String serialNumber = null;
String serialNumberPrefix = "SERIALNUMBER=";
String principal = x509Certificate.getSubjectDN().getName().toUpperCase();
int beg = principal.indexOf(serialNumberPrefix);
if (beg >= 0) {
int end = principal.indexOf(",", beg);
if (end == -1) {
end = principal.length();
}
serialNumber = principal.substring(beg + serialNumberPrefix.length(), end);
} else {
serialNumber = x509Certificate.getSerialNumber().toString();
}
return serialNumber;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy