Skip to content

Commit

Permalink
change some private fields to protected or public
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmatusiewicz committed Nov 20, 2024
1 parent f2c22dd commit ef7b246
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 282 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/privacyidea/Challenge.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

public class Challenge
{
private final List<String> 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<String> 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)
{
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/privacyidea/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -109,19 +109,19 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers()
*/
void sendRequestAsync(String endpoint, Map<String, String> params, Map<String, String> 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) ->
Expand All @@ -147,7 +147,7 @@ void sendRequestAsync(String endpoint, Map<String, String> params, Map<String, S
Request.Builder requestBuilder = new Request.Builder().url(url);

// Add the headers
requestBuilder.addHeader(HEADER_USER_AGENT, piConfig.getUserAgent());
requestBuilder.addHeader(HEADER_USER_AGENT, piConfig.userAgent);
if (headers != null && !headers.isEmpty())
{
headers.forEach(requestBuilder::addHeader);
Expand Down
128 changes: 12 additions & 116 deletions src/main/java/org/privacyidea/PIConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,132 +18,28 @@

class PIConfig
{
private final String serverURL;
private final String userAgent;
private String realm = "";
private boolean verifySSL = true;
private String serviceAccountName = "";
private String serviceAccountPass = "";
private String serviceAccountRealm = "";
private boolean disableLog = false;
private String forwardClientIP = "";
private int httpTimeoutMs = 30000;
private String proxyHost = "";
private int proxyPort = 0;
public final String serverURL;
public final String userAgent;
public String realm = "";
public boolean verifySSL = true;
public String serviceAccountName = "";
public String serviceAccountPass = "";
public String serviceAccountRealm = "";
public boolean disableLog = false;
public String forwardClientIP = "";
public int httpTimeoutMs = 30000;
protected String proxyHost = "";
protected int proxyPort = 0;

public PIConfig(String serverURL, String userAgent)
{
this.serverURL = serverURL;
this.userAgent = userAgent;
}

// SETTERS

public void setRealm(String realm)
{
this.realm = realm;
}

public void setVerifySSL(boolean verifySSL)
{
this.verifySSL = verifySSL;
}

public void setServiceAccountName(String serviceAccountName)
{
this.serviceAccountName = serviceAccountName;
}

public void setServiceAccountPass(String serviceAccountPass)
{
this.serviceAccountPass = serviceAccountPass;
}

public void setServiceAccountRealm(String serviceAccountRealm)
{
this.serviceAccountRealm = serviceAccountRealm;
}

public void setForwardClientIP(String forwardClientIP)
{
this.forwardClientIP = forwardClientIP;
}

public void setDisableLog(boolean disableLog)
{
this.disableLog = disableLog;
}

public void setHttpTimeoutMs(int httpTimeoutMs)
{
this.httpTimeoutMs = httpTimeoutMs;
}

public void setProxy(String proxyHost, int proxyPort)
{
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
}

// GETTERS

public String getServerURL()
{
return serverURL;
}

public String getUserAgent()
{
return userAgent;
}

public String getRealm()
{
return realm;
}

public boolean getVerifySSL()
{
return verifySSL;
}

public String getServiceAccountName()
{
return serviceAccountName;
}

public String getServiceAccountPass()
{
return serviceAccountPass;
}

public String getServiceAccountRealm()
{
return serviceAccountRealm;
}

public boolean getDisableLog()
{
return disableLog;
}

public String getForwardClientIP()
{
return forwardClientIP;
}

public int getHttpTimeoutMs()
{
return httpTimeoutMs;
}

public String getProxyHost()
{
return proxyHost;
}

public int getProxyPort()
{
return proxyPort;
}
}
14 changes: 2 additions & 12 deletions src/main/java/org/privacyidea/PIError.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,12 @@

public class PIError
{
private final int code;
private final String message;
public final int code;
public final String message;

public PIError(int code, String message)
{
this.code = code;
this.message = message;
}

public int getCode()
{
return code;
}

public String getMessage()
{
return message;
}
}
128 changes: 18 additions & 110 deletions src/main/java/org/privacyidea/PIResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@
*/
public class PIResponse
{
String message = "";
String preferredClientMode = "";
List<String> messages = new ArrayList<>();
List<Challenge> 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<String> messages = new ArrayList<>();
public List<Challenge> 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.
Expand Down Expand Up @@ -163,96 +163,4 @@ public String toString()
{
return rawMessage;
}

// GETTERS

public String getMessage()
{
return message;
}

public String getPreferredClientMode()
{
return preferredClientMode;
}

public List<String> getMessages()
{
return messages;
}

public List<Challenge> 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;
}
}
Loading

0 comments on commit ef7b246

Please sign in to comment.