@@ -60,7 +60,7 @@ public class PrivacyIDEA
6060 private final IPISimpleLogger simpleLog ;
6161 private final Endpoint endpoint ;
6262 // Thread pool for connections
63- private final BlockingQueue <Runnable > queue = new ArrayBlockingQueue <Runnable >(100 );
63+ private final BlockingQueue <Runnable > queue = new ArrayBlockingQueue <>(100 );
6464 private final ExecutorService threadPool = new ThreadPoolExecutor (20 , 20 , 10 , TimeUnit .SECONDS , queue );
6565 final JSONParser parser ;
6666 // Responses from these endpoints will not be logged. The list can be overwritten.
@@ -79,25 +79,25 @@ private PrivacyIDEA(PIConfig configuration, IPILogger logger, IPISimpleLogger si
7979 /**
8080 * @see PrivacyIDEA#validateCheck(String, String, String, Map)
8181 */
82- public PIResponse validateCheck (String username , String otp )
82+ public PIResponse validateCheck (String username , String pass )
8383 {
84- return this .validateCheck (username , otp , null , Collections .emptyMap ());
84+ return this .validateCheck (username , pass , null , Collections .emptyMap ());
8585 }
8686
8787 /**
8888 * @see PrivacyIDEA#validateCheck(String, String, String, Map)
8989 */
90- public PIResponse validateCheck (String username , String otp , Map <String , String > headers )
90+ public PIResponse validateCheck (String username , String pass , Map <String , String > headers )
9191 {
92- return this .validateCheck (username , otp , null , headers );
92+ return this .validateCheck (username , pass , null , headers );
9393 }
9494
9595 /**
9696 * @see PrivacyIDEA#validateCheck(String, String, String, Map)
9797 */
98- public PIResponse validateCheck (String username , String otp , String transactionId )
98+ public PIResponse validateCheck (String username , String pass , String transactionId )
9999 {
100- return this .validateCheck (username , otp , transactionId , Collections .emptyMap ());
100+ return this .validateCheck (username , pass , transactionId , Collections .emptyMap ());
101101 }
102102
103103 /**
@@ -106,75 +106,75 @@ public PIResponse validateCheck(String username, String otp, String transactionI
106106 * (E.g. this can also be used to trigger challenges without a service account)
107107 *
108108 * @param username username
109- * @param otp the OTP, PIN+OTP or password to use.
109+ * @param pass pass/otp value
110110 * @param transactionId optional, will be appended if set
111111 * @param headers optional headers for the request
112112 * @return PIResponse object containing the response or null if error
113113 */
114- public PIResponse validateCheck (String username , String otp , String transactionId , Map <String , String > headers )
114+ public PIResponse validateCheck (String username , String pass , String transactionId , Map <String , String > headers )
115115 {
116- Map <String , String > params = new LinkedHashMap <>();
117-
118- params .put (USER , username );
119- params .put (PASS , (otp != null ? otp : "" ));
120-
121- if (transactionId != null && !transactionId .isEmpty ())
122- {
123- params .put (TRANSACTION_ID , transactionId );
124- }
125-
126- appendRealm (params );
127-
128- String response = runRequestAsync (ENDPOINT_VALIDATE_CHECK , params , headers , false , POST );
129- return this .parser .parsePIResponse (response );
116+ return getPIResponse (USER , username , pass , headers , transactionId );
130117 }
131118
132-
133119 /**
134120 * @see PrivacyIDEA#validateCheckSerial(String, String, String, Map)
135121 */
136- public PIResponse validateCheckSerial (String serial , String otp )
122+ public PIResponse validateCheckSerial (String serial , String pass )
137123 {
138- return this .validateCheckSerial (serial , otp , null , Collections .emptyMap ());
124+ return this .validateCheckSerial (serial , pass , null , Collections .emptyMap ());
139125 }
140126
141127 /**
142128 * @see PrivacyIDEA#validateCheckSerial(String, String, String, Map)
143129 */
144- public PIResponse validateCheckSerial (String serial , String otp , Map <String , String > headers )
130+ public PIResponse validateCheckSerial (String serial , String pass , Map <String , String > headers )
145131 {
146- return this .validateCheckSerial (serial , otp , null , headers );
132+ return this .validateCheckSerial (serial , pass , null , headers );
147133 }
148134
149135 /**
150136 * @see PrivacyIDEA#validateCheckSerial(String, String, String, Map)
151137 */
152- public PIResponse validateCheckSerial (String serial , String otp , String transactionId )
138+ public PIResponse validateCheckSerial (String serial , String pass , String transactionId )
153139 {
154- return this .validateCheckSerial (serial , otp , transactionId , Collections .emptyMap ());
140+ return this .validateCheckSerial (serial , pass , transactionId , Collections .emptyMap ());
155141 }
156142
157143 /**
158- * Send a request to /validate/check with the serial rather than the username to identify the token.
144+ * Send a request to /validate/check with the serial rather than the username to identify exact token.
159145 *
160146 * @param serial serial of the token
161- * @param otp otp value
147+ * @param pass pass/ otp value
162148 * @param transactionId transactionId
163149 * @return PIResponse or null if error
164150 */
165- public PIResponse validateCheckSerial (String serial , String otp , String transactionId , Map <String , String > headers )
151+ public PIResponse validateCheckSerial (String serial , String pass , String transactionId , Map <String , String > headers )
166152 {
167- Map <String , String > params = new LinkedHashMap <>();
153+ return getPIResponse (SERIAL , serial , pass , headers , transactionId );
154+ }
168155
169- params .put (SERIAL , serial );
170- params .put (PASS , (otp != null ? otp : "" ));
156+ /**
157+ * Used by validateCheck and validateCheckSerial to get the PI Response.
158+ *
159+ * @param type distinguish between user and serial to set forwarded input to the right PI-request param
160+ * @param input forwarded username for classic validateCheck or serial to trigger exact token
161+ * @param pass OTP, PIN+OTP or password to use
162+ * @param headers optional headers for the request
163+ * @param transactionId optional, will be appended if set
164+ * @return PIResponse object containing the response or null if error
165+ */
166+ private PIResponse getPIResponse (String type , String input , String pass , Map <String , String > headers ,
167+ String transactionId )
168+ {
169+ Map <String , String > params = new LinkedHashMap <>();
170+ // Add forwarded user or serial to the params
171+ params .put (type , input );
172+ params .put (PASS , (pass != null ? pass : "" ));
173+ appendRealm (params );
171174 if (transactionId != null && !transactionId .isEmpty ())
172175 {
173176 params .put (TRANSACTION_ID , transactionId );
174177 }
175-
176- appendRealm (params );
177-
178178 String response = runRequestAsync (ENDPOINT_VALIDATE_CHECK , params , headers , false , POST );
179179 return this .parser .parsePIResponse (response );
180180 }
@@ -555,13 +555,13 @@ public static Builder newBuilder(String serverURL, String userAgent)
555555
556556 public static class Builder
557557 {
558- private String serverURL = "" ;
558+ private final String serverURL ;
559+ private final String userAgent ;
559560 private String realm = "" ;
560561 private boolean doSSLVerify = true ;
561562 private String serviceAccountName = "" ;
562563 private String serviceAccountPass = "" ;
563564 private String serviceAccountRealm = "" ;
564- private String userAgent = "" ;
565565 private IPILogger logger = null ;
566566 private boolean disableLog = false ;
567567 private IPISimpleLogger simpleLogBridge = null ;
0 commit comments