From ef7b24639fbd2111c10f5240fab4266a2d0721a4 Mon Sep 17 00:00:00 2001 From: lukasmatusiewicz Date: Wed, 20 Nov 2024 11:46:01 +0100 Subject: [PATCH] change some private fields to protected or public --- src/main/java/org/privacyidea/Challenge.java | 14 +- src/main/java/org/privacyidea/Endpoint.java | 24 ++-- src/main/java/org/privacyidea/PIConfig.java | 128 ++---------------- src/main/java/org/privacyidea/PIError.java | 14 +- src/main/java/org/privacyidea/PIResponse.java | 128 +++--------------- .../java/org/privacyidea/PrivacyIDEA.java | 50 +++---- 6 files changed, 76 insertions(+), 282 deletions(-) diff --git a/src/main/java/org/privacyidea/Challenge.java b/src/main/java/org/privacyidea/Challenge.java index 3da7fa4..5e7e9d7 100644 --- a/src/main/java/org/privacyidea/Challenge.java +++ b/src/main/java/org/privacyidea/Challenge.java @@ -21,13 +21,13 @@ public class Challenge { - private final List attributes = new ArrayList<>(); - private final String serial; - private final String clientMode; - private final String message; - private final String transactionID; - private final String type; - private final String image; + protected final List attributes = new ArrayList<>(); + protected final String serial; + protected final String clientMode; + protected final String message; + protected final String transactionID; + protected final String type; + protected final String image; public Challenge(String serial, String message, String clientMode, String image, String transactionID, String type) { diff --git a/src/main/java/org/privacyidea/Endpoint.java b/src/main/java/org/privacyidea/Endpoint.java index db2aab7..fb5ab4a 100644 --- a/src/main/java/org/privacyidea/Endpoint.java +++ b/src/main/java/org/privacyidea/Endpoint.java @@ -68,11 +68,11 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() this.piConfig = privacyIDEA.configuration(); OkHttpClient.Builder builder = new OkHttpClient.Builder(); - builder.connectTimeout(piConfig.getHttpTimeoutMs(), TimeUnit.MILLISECONDS) - .writeTimeout(piConfig.getHttpTimeoutMs(), TimeUnit.MILLISECONDS) - .readTimeout(piConfig.getHttpTimeoutMs(), TimeUnit.MILLISECONDS); + builder.connectTimeout(piConfig.httpTimeoutMs, TimeUnit.MILLISECONDS) + .writeTimeout(piConfig.httpTimeoutMs, TimeUnit.MILLISECONDS) + .readTimeout(piConfig.httpTimeoutMs, TimeUnit.MILLISECONDS); - if (!this.piConfig.getVerifySSL()) + if (!this.piConfig.verifySSL) { // Trust all certs and verify every host try @@ -89,9 +89,9 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() } } - if (!piConfig.getProxyHost().isEmpty()) + if (!piConfig.proxyHost.isEmpty()) { - Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(piConfig.getProxyHost(), piConfig.getProxyPort())); + Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(piConfig.proxyHost, piConfig.proxyPort)); builder.proxy(proxy); } @@ -109,19 +109,19 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() */ void sendRequestAsync(String endpoint, Map params, Map headers, String method, Callback callback) { - HttpUrl httpUrl = HttpUrl.parse(piConfig.getServerURL() + endpoint); + HttpUrl httpUrl = HttpUrl.parse(piConfig.serverURL + endpoint); if (httpUrl == null) { - privacyIDEA.error("Server url could not be parsed: " + (piConfig.getServerURL() + endpoint)); + privacyIDEA.error("Server url could not be parsed: " + (piConfig.serverURL + endpoint)); // Invoke the callback to terminate the thread that called this function. callback.onFailure(null, new IOException("Request could not be created because the url could not be parsed")); return; } HttpUrl.Builder urlBuilder = httpUrl.newBuilder(); - if (!piConfig.getForwardClientIP().isEmpty()) + if (!piConfig.forwardClientIP.isEmpty()) { - privacyIDEA.log("Forwarding client IP: " + piConfig.getForwardClientIP()); - params.put(CLIENT_IP, piConfig.getForwardClientIP()); + privacyIDEA.log("Forwarding client IP: " + piConfig.forwardClientIP); + params.put(CLIENT_IP, piConfig.forwardClientIP); } privacyIDEA.log(method + " " + endpoint); params.forEach((k, v) -> @@ -147,7 +147,7 @@ void sendRequestAsync(String endpoint, Map params, Map messages = new ArrayList<>(); - List multiChallenge = new ArrayList<>(); - String transactionID = ""; - String serial = ""; - String image = ""; - int id = 0; - String jsonRPCVersion = ""; - boolean status = false; - boolean value = false; - AuthenticationStatus authentication = AuthenticationStatus.NONE; - String piVersion = ""; // e.g. 3.2.1 - String rawMessage = ""; - String signature = ""; - String type = ""; // Type of token that was matching the request - int otpLength = 0; - PIError error = null; + public String message = ""; + public String preferredClientMode = ""; + public List messages = new ArrayList<>(); + public List multiChallenge = new ArrayList<>(); + public String transactionID = ""; + public String serial = ""; + public String image = ""; + public int id = 0; + public String jsonRPCVersion = ""; + public boolean status = false; + public boolean value = false; + public AuthenticationStatus authentication = AuthenticationStatus.NONE; + public String piVersion = ""; // e.g. 3.2.1 + public String rawMessage = ""; + public String signature = ""; + public String type = ""; // Type of token that was matching the request + public int otpLength = 0; + public PIError error = null; /** * Check if a PUSH token was triggered. @@ -163,96 +163,4 @@ public String toString() { return rawMessage; } - - // GETTERS - - public String getMessage() - { - return message; - } - - public String getPreferredClientMode() - { - return preferredClientMode; - } - - public List getMessages() - { - return messages; - } - - public List getMultiChallenge() - { - return multiChallenge; - } - - public String getTransactionID() - { - return transactionID; - } - - public String getSerial() - { - return serial; - } - - public String getImage() - { - return image; - } - - public int getId() - { - return id; - } - - public String getJsonRPCVersion() - { - return jsonRPCVersion; - } - - public boolean getStatus() - { - return status; - } - - public boolean getValue() - { - return value; - } - - public AuthenticationStatus getAuthentication() - { - return authentication; - } - - public String getPiVersion() - { - return piVersion; - } - - public String getRawMessage() - { - return rawMessage; - } - - public String getSignature() - { - return signature; - } - - public String getType() - { - return type; - } - - public int getOtpLength() - { - return otpLength; - } - - public PIError getError() - { - return error; - } } diff --git a/src/main/java/org/privacyidea/PrivacyIDEA.java b/src/main/java/org/privacyidea/PrivacyIDEA.java index 3c58284..85ec839 100644 --- a/src/main/java/org/privacyidea/PrivacyIDEA.java +++ b/src/main/java/org/privacyidea/PrivacyIDEA.java @@ -262,16 +262,16 @@ public String getAuthToken() Map serviceAccountParam() { Map authTokenParams = new LinkedHashMap<>(); - authTokenParams.put(USERNAME, configuration.getServiceAccountName()); - authTokenParams.put(PASSWORD, configuration.getServiceAccountPass()); + authTokenParams.put(USERNAME, configuration.serviceAccountName); + authTokenParams.put(PASSWORD, configuration.serviceAccountPass); - if (configuration.getServiceAccountRealm() != null && !configuration.getServiceAccountRealm().isEmpty()) + if (configuration.serviceAccountRealm != null && !configuration.serviceAccountRealm.isEmpty()) { - authTokenParams.put(REALM, configuration.getServiceAccountRealm()); + authTokenParams.put(REALM, configuration.serviceAccountRealm); } - else if (configuration.getRealm() != null && !configuration.getRealm().isEmpty()) + else if (configuration.realm != null && !configuration.realm.isEmpty()) { - authTokenParams.put(REALM, configuration.getRealm()); + authTokenParams.put(REALM, configuration.realm); } return authTokenParams; } @@ -350,9 +350,9 @@ public RolloutInfo tokenInit(String username, String typeToEnroll, String otpKey private void appendRealm(Map params) { - if (configuration.getRealm() != null && !configuration.getRealm().isEmpty()) + if (configuration.realm != null && !configuration.realm.isEmpty()) { - params.put(REALM, configuration.getRealm()); + params.put(REALM, configuration.realm); } } @@ -370,9 +370,9 @@ private void appendRealm(Map params) private String runRequestAsync(String path, Map params, Map headers, boolean authTokenRequired, String method) { - if (!configuration.getForwardClientIP().isEmpty()) + if (!configuration.forwardClientIP.isEmpty()) { - params.put(CLIENT_IP,configuration.getForwardClientIP()); + params.put(CLIENT_IP,configuration.forwardClientIP); } Callable callable = new AsyncRequestCallable(this, endpoint, path, params, headers, authTokenRequired, method); Future future = threadPool.submit(callable); @@ -409,9 +409,9 @@ public void logExcludedEndpoints(List list) */ public boolean serviceAccountAvailable() { - return configuration.getServiceAccountName() != null && !configuration.getServiceAccountName().isEmpty() - && configuration.getServiceAccountPass() != null && - !configuration.getServiceAccountPass().isEmpty(); + return configuration.serviceAccountName != null && !configuration.serviceAccountName.isEmpty() + && configuration.serviceAccountPass != null && + !configuration.serviceAccountPass.isEmpty(); } PIConfig configuration() @@ -426,7 +426,7 @@ PIConfig configuration() */ void error(String message) { - if (!configuration.getDisableLog()) + if (!configuration.disableLog) { if (this.log != null) { @@ -450,7 +450,7 @@ else if (this.simpleLog != null) */ void error(Throwable e) { - if (!configuration.getDisableLog()) + if (!configuration.disableLog) { if (this.log != null) { @@ -474,7 +474,7 @@ else if (this.simpleLog != null) */ void log(String message) { - if (!configuration.getDisableLog()) + if (!configuration.disableLog) { if (this.log != null) { @@ -498,7 +498,7 @@ else if (this.simpleLog != null) */ void log(Throwable e) { - if (!configuration.getDisableLog()) + if (!configuration.disableLog) { if (this.log != null) { @@ -694,14 +694,14 @@ public Builder proxy(String proxyHost, int proxyPort) public PrivacyIDEA build() { PIConfig configuration = new PIConfig(serverURL, userAgent); - configuration.setRealm(realm); - configuration.setVerifySSL(verifySSL); - configuration.setServiceAccountName(serviceAccountName); - configuration.setServiceAccountPass(serviceAccountPass); - configuration.setServiceAccountRealm(serviceAccountRealm); - configuration.setForwardClientIP(forwardClientIP); - configuration.setDisableLog(disableLog); - configuration.setHttpTimeoutMs(httpTimeoutMs); + configuration.realm = realm; + configuration.verifySSL = verifySSL; + configuration.serviceAccountName = serviceAccountName; + configuration.serviceAccountPass = serviceAccountPass; + configuration.serviceAccountRealm = serviceAccountRealm; + configuration.forwardClientIP = forwardClientIP; + configuration.disableLog = disableLog; + configuration.httpTimeoutMs = httpTimeoutMs; configuration.setProxy(proxyHost, proxyPort); return new PrivacyIDEA(configuration, logger, simpleLogBridge); }