io.electrum.vas.Utils Maven / Gradle / Ivy
package io.electrum.vas;
import org.glassfish.jersey.internal.util.Base64;
public class Utils {
public static String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public static String getBasicAuthString(String authHeader) {
if (authHeader == null || authHeader.isEmpty() || !authHeader.startsWith("Basic ")) {
return null;
}
String credsSubstring = authHeader.substring("Basic ".length());
String usernameAndPassword = Base64.decodeAsString(credsSubstring);
return usernameAndPassword;
}
public static String getUsernameFromBasicAuth(String authString) {
String username = "null";
if (authString != null && !authString.isEmpty()) {
username = authString.substring(0, authString.indexOf(':'));
}
return username;
}
public static String getPasswordFromBasicAuth(String authString) {
String password = "null";
if (authString != null && !authString.isEmpty()) {
password = authString.substring(authString.indexOf(':') + 1);
}
return password;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy