Skip to content

Commit 5f522ce

Browse files
author
Jose Alfredo Serrano
committed
Improve Test coverage. Fix white spaces
1 parent b34d3fe commit 5f522ce

File tree

5 files changed

+183
-140
lines changed

5 files changed

+183
-140
lines changed

core/src/main/java/com/onelogin/saml2/settings/DynamicSettingsBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public DynamicSettingsBuilder wantAssertionsEncrypted(boolean wantAssertionsEncr
336336
*
337337
* @param wantNameId the wantNameId value to be set. Based on it the SP expects a NameID
338338
*/
339-
public DynamicSettingsBuilder wantNameId(Boolean wantNameId) {
339+
public DynamicSettingsBuilder wantNameId(boolean wantNameId) {
340340
this.saml2Settings.setWantNameId(wantNameId);
341341
return this;
342342
}

core/src/main/java/com/onelogin/saml2/settings/Saml2Settings.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class Saml2Settings {
6666
private Boolean wantNameId = true;
6767
private Boolean wantNameIdEncrypted = false;
6868
private Boolean signMetadata = false;
69-
private List<String> requestedAuthnContext = new ArrayList<>();
69+
private List<String> requestedAuthnContext = new ArrayList<>();
7070
private String requestedAuthnContextComparison = "exact";
7171
private Boolean wantXMLValidation = true;
7272
private String signatureAlgorithm = Constants.RSA_SHA1;
@@ -629,9 +629,9 @@ public void setSignMetadata(Boolean signMetadata) {
629629
* the requestedAuthnContext value to be set on the AuthNRequest.
630630
*/
631631
public void setRequestedAuthnContext(List<String> requestedAuthnContext) {
632-
if (requestedAuthnContext != null) {
633-
this.requestedAuthnContext = requestedAuthnContext;
634-
}
632+
if (requestedAuthnContext != null) {
633+
this.requestedAuthnContext = requestedAuthnContext;
634+
}
635635
}
636636

637637
/**

core/src/main/java/com/onelogin/saml2/settings/SettingsBuilder.java

Lines changed: 88 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,12 @@ public Saml2Settings build() throws IOException {
175175
saml2Setting = new Saml2Settings();
176176

177177
Boolean strict = loadBooleanProperty(STRICT_PROPERTY_KEY);
178-
if (strict != null) {
179-
saml2Setting.setStrict(strict);
180-
}
178+
if (strict != null)
179+
saml2Setting.setStrict(strict);
181180

182181
Boolean debug = loadBooleanProperty(DEBUG_PROPERTY_KEY);
183-
if (debug != null) {
184-
saml2Setting.setDebug(debug);
185-
}
182+
if (debug != null)
183+
saml2Setting.setDebug(debug);
186184

187185
this.loadSpSetting();
188186
this.loadIdpSetting();
@@ -201,124 +199,101 @@ public Saml2Settings build() throws IOException {
201199
*/
202200
private void loadIdpSetting() {
203201
String idpEntityID = loadStringProperty(IDP_ENTITYID_PROPERTY_KEY);
204-
if (idpEntityID != null) {
205-
saml2Setting.setIdpEntityId(idpEntityID);
206-
}
202+
if (idpEntityID != null)
203+
saml2Setting.setIdpEntityId(idpEntityID);
207204

208205
URL idpSingleSignOnServiceUrl = loadURLProperty(IDP_SINGLE_SIGN_ON_SERVICE_URL_PROPERTY_KEY);
209-
if (idpSingleSignOnServiceUrl != null) {
210-
saml2Setting.setIdpSingleSignOnServiceUrl(idpSingleSignOnServiceUrl);
211-
}
206+
if (idpSingleSignOnServiceUrl != null)
207+
saml2Setting.setIdpSingleSignOnServiceUrl(idpSingleSignOnServiceUrl);
212208

213209
String idpSingleSignOnServiceBinding = loadStringProperty(IDP_SINGLE_SIGN_ON_SERVICE_BINDING_PROPERTY_KEY);
214-
if (idpSingleSignOnServiceBinding != null) {
215-
saml2Setting.setIdpSingleSignOnServiceBinding(idpSingleSignOnServiceBinding);
216-
}
210+
if (idpSingleSignOnServiceBinding != null)
211+
saml2Setting.setIdpSingleSignOnServiceBinding(idpSingleSignOnServiceBinding);
217212

218213
URL idpSingleLogoutServiceUrl = loadURLProperty(IDP_SINGLE_LOGOUT_SERVICE_URL_PROPERTY_KEY);
219-
if (idpSingleLogoutServiceUrl != null) {
220-
saml2Setting.setIdpSingleLogoutServiceUrl(idpSingleLogoutServiceUrl);
221-
}
214+
if (idpSingleLogoutServiceUrl != null)
215+
saml2Setting.setIdpSingleLogoutServiceUrl(idpSingleLogoutServiceUrl);
222216

223217
URL idpSingleLogoutServiceResponseUrl = loadURLProperty(IDP_SINGLE_LOGOUT_SERVICE_RESPONSE_URL_PROPERTY_KEY);
224-
if (idpSingleLogoutServiceResponseUrl != null) {
225-
saml2Setting.setIdpSingleLogoutServiceResponseUrl(idpSingleLogoutServiceResponseUrl);
226-
}
218+
if (idpSingleLogoutServiceResponseUrl != null)
219+
saml2Setting.setIdpSingleLogoutServiceResponseUrl(idpSingleLogoutServiceResponseUrl);
227220

228221
String idpSingleLogoutServiceBinding = loadStringProperty(IDP_SINGLE_LOGOUT_SERVICE_BINDING_PROPERTY_KEY);
229-
if (idpSingleLogoutServiceBinding != null) {
230-
saml2Setting.setIdpSingleLogoutServiceBinding(idpSingleLogoutServiceBinding);
231-
}
222+
if (idpSingleLogoutServiceBinding != null)
223+
saml2Setting.setIdpSingleLogoutServiceBinding(idpSingleLogoutServiceBinding);
232224

233225
X509Certificate idpX509cert = loadCertificateFromProp(IDP_X509CERT_PROPERTY_KEY);
234-
if (idpX509cert != null) {
235-
saml2Setting.setIdpx509cert(idpX509cert);
236-
}
226+
if (idpX509cert != null)
227+
saml2Setting.setIdpx509cert(idpX509cert);
237228

238229
String idpCertFingerprint = loadStringProperty(CERTFINGERPRINT_PROPERTY_KEY);
239-
if (idpCertFingerprint != null) {
240-
saml2Setting.setIdpCertFingerprint(idpCertFingerprint);
241-
}
230+
if (idpCertFingerprint != null)
231+
saml2Setting.setIdpCertFingerprint(idpCertFingerprint);
242232

243233
String idpCertFingerprintAlgorithm = loadStringProperty(CERTFINGERPRINT_ALGORITHM_PROPERTY_KEY);
244-
if (idpCertFingerprintAlgorithm != null && !idpCertFingerprintAlgorithm.isEmpty()) {
245-
saml2Setting.setIdpCertFingerprintAlgorithm(idpCertFingerprintAlgorithm);
246-
}
234+
if (idpCertFingerprintAlgorithm != null && !idpCertFingerprintAlgorithm.isEmpty())
235+
saml2Setting.setIdpCertFingerprintAlgorithm(idpCertFingerprintAlgorithm);
247236
}
248237

249238
/**
250239
* Loads the security settings from the properties file
251240
*/
252241
private void loadSecuritySetting() {
253242
Boolean nameIdEncrypted = loadBooleanProperty(SECURITY_NAMEID_ENCRYPTED);
254-
if (nameIdEncrypted != null) {
255-
saml2Setting.setNameIdEncrypted(nameIdEncrypted);
256-
}
243+
if (nameIdEncrypted != null)
244+
saml2Setting.setNameIdEncrypted(nameIdEncrypted);
257245

258246
Boolean authnRequestsSigned = loadBooleanProperty(SECURITY_AUTHREQUEST_SIGNED);
259-
if (authnRequestsSigned != null) {
260-
saml2Setting.setAuthnRequestsSigned(authnRequestsSigned);
261-
}
247+
if (authnRequestsSigned != null)
248+
saml2Setting.setAuthnRequestsSigned(authnRequestsSigned);
262249

263250
Boolean logoutRequestSigned = loadBooleanProperty(SECURITY_LOGOUTREQUEST_SIGNED);
264-
if (logoutRequestSigned != null) {
265-
saml2Setting.setLogoutRequestSigned(logoutRequestSigned);
266-
}
251+
if (logoutRequestSigned != null)
252+
saml2Setting.setLogoutRequestSigned(logoutRequestSigned);
267253

268254
Boolean logoutResponseSigned = loadBooleanProperty(SECURITY_LOGOUTRESPONSE_SIGNED);
269-
if (logoutResponseSigned != null) {
270-
saml2Setting.setLogoutResponseSigned(logoutResponseSigned);
271-
}
255+
if (logoutResponseSigned != null)
256+
saml2Setting.setLogoutResponseSigned(logoutResponseSigned);
272257

273258
Boolean wantMessagesSigned = loadBooleanProperty(SECURITY_WANT_MESSAGES_SIGNED);
274-
if (wantMessagesSigned != null) {
275-
saml2Setting.setWantMessagesSigned(wantMessagesSigned);
276-
}
259+
if (wantMessagesSigned != null)
260+
saml2Setting.setWantMessagesSigned(wantMessagesSigned);
277261

278262
Boolean wantAssertionsSigned = loadBooleanProperty(SECURITY_WANT_ASSERTIONS_SIGNED);
279-
if (wantAssertionsSigned != null) {
280-
saml2Setting.setWantAssertionsSigned(wantAssertionsSigned);
281-
}
263+
if (wantAssertionsSigned != null)
264+
saml2Setting.setWantAssertionsSigned(wantAssertionsSigned);
282265

283266
Boolean wantAssertionsEncrypted = loadBooleanProperty(SECURITY_WANT_ASSERTIONS_ENCRYPTED);
284-
if (wantAssertionsEncrypted != null) {
285-
saml2Setting.setWantAssertionsEncrypted(wantAssertionsEncrypted);
286-
}
267+
if (wantAssertionsEncrypted != null)
268+
saml2Setting.setWantAssertionsEncrypted(wantAssertionsEncrypted);
287269

288270
Boolean wantNameId = loadBooleanProperty(SECURITY_WANT_NAMEID);
289-
if (wantNameId != null) {
290-
saml2Setting.setWantNameId(wantNameId);
291-
}
271+
if (wantNameId != null)
272+
saml2Setting.setWantNameId(wantNameId);
292273

293274
Boolean wantNameIdEncrypted = loadBooleanProperty(SECURITY_WANT_NAMEID_ENCRYPTED);
294-
if (wantNameIdEncrypted != null) {
295-
saml2Setting.setWantNameIdEncrypted(wantNameIdEncrypted);
296-
}
275+
if (wantNameIdEncrypted != null)
276+
saml2Setting.setWantNameIdEncrypted(wantNameIdEncrypted);
297277

298278
Boolean wantXMLValidation = loadBooleanProperty(SECURITY_WANT_XML_VALIDATION);
299-
if (wantXMLValidation != null) {
300-
saml2Setting.setWantXMLValidation(wantXMLValidation);
301-
}
279+
if (wantXMLValidation != null)
280+
saml2Setting.setWantXMLValidation(wantXMLValidation);
302281

303282
Boolean signMetadata = loadBooleanProperty(SECURITY_SIGN_METADATA);
304-
if (signMetadata != null) {
305-
saml2Setting.setSignMetadata(signMetadata);
306-
}
283+
if (signMetadata != null)
284+
saml2Setting.setSignMetadata(signMetadata);
307285

308286
List<String> requestedAuthnContext = loadListProperty(SECURITY_REQUESTED_AUTHNCONTEXT);
309-
if (requestedAuthnContext != null) {
310-
saml2Setting.setRequestedAuthnContext(requestedAuthnContext);
311-
}
287+
if (requestedAuthnContext != null)
288+
saml2Setting.setRequestedAuthnContext(requestedAuthnContext);
312289

313290
String requestedAuthnContextComparison = loadStringProperty(SECURITY_REQUESTED_AUTHNCONTEXTCOMPARISON);
314-
if (requestedAuthnContextComparison != null && !requestedAuthnContextComparison.isEmpty()) {
315-
saml2Setting.setRequestedAuthnContextComparison(requestedAuthnContextComparison);
316-
}
291+
if (requestedAuthnContextComparison != null && !requestedAuthnContextComparison.isEmpty())
292+
saml2Setting.setRequestedAuthnContextComparison(requestedAuthnContextComparison);
317293

318294
String signatureAlgorithm = loadStringProperty(SECURITY_SIGNATURE_ALGORITHM);
319-
if (signatureAlgorithm != null && !signatureAlgorithm.isEmpty()) {
320-
saml2Setting.setSignatureAlgorithm(signatureAlgorithm);
321-
}
295+
if (signatureAlgorithm != null && !signatureAlgorithm.isEmpty())
296+
saml2Setting.setSignatureAlgorithm(signatureAlgorithm);
322297

323298
Boolean rejectUnsolicitedResponsesWithInResponseTo = loadBooleanProperty(SECURITY_REJECT_UNSOLICITED_RESPONSES_WITH_INRESPONSETO);
324299
if (rejectUnsolicitedResponsesWithInResponseTo != null) {
@@ -389,44 +364,36 @@ private List<Contact> loadContacts() {
389364
*/
390365
private void loadSpSetting() {
391366
String spEntityID = loadStringProperty(SP_ENTITYID_PROPERTY_KEY);
392-
if (spEntityID != null) {
393-
saml2Setting.setSpEntityId(spEntityID);
394-
}
367+
if (spEntityID != null)
368+
saml2Setting.setSpEntityId(spEntityID);
395369

396370
URL assertionConsumerServiceUrl = loadURLProperty(SP_ASSERTION_CONSUMER_SERVICE_URL_PROPERTY_KEY);
397-
if (assertionConsumerServiceUrl != null) {
398-
saml2Setting.setSpAssertionConsumerServiceUrl(assertionConsumerServiceUrl);
399-
}
371+
if (assertionConsumerServiceUrl != null)
372+
saml2Setting.setSpAssertionConsumerServiceUrl(assertionConsumerServiceUrl);
400373

401374
String spAssertionConsumerServiceBinding = loadStringProperty(SP_ASSERTION_CONSUMER_SERVICE_BINDING_PROPERTY_KEY);
402-
if (spAssertionConsumerServiceBinding != null) {
403-
saml2Setting.setSpAssertionConsumerServiceBinding(spAssertionConsumerServiceBinding);
404-
}
375+
if (spAssertionConsumerServiceBinding != null)
376+
saml2Setting.setSpAssertionConsumerServiceBinding(spAssertionConsumerServiceBinding);
405377

406378
URL spSingleLogoutServiceUrl = loadURLProperty(SP_SINGLE_LOGOUT_SERVICE_URL_PROPERTY_KEY);
407-
if (spSingleLogoutServiceUrl != null) {
408-
saml2Setting.setSpSingleLogoutServiceUrl(spSingleLogoutServiceUrl);
409-
}
379+
if (spSingleLogoutServiceUrl != null)
380+
saml2Setting.setSpSingleLogoutServiceUrl(spSingleLogoutServiceUrl);
410381

411382
String spSingleLogoutServiceBinding = loadStringProperty(SP_SINGLE_LOGOUT_SERVICE_BINDING_PROPERTY_KEY);
412-
if (spSingleLogoutServiceBinding != null) {
413-
saml2Setting.setSpSingleLogoutServiceBinding(spSingleLogoutServiceBinding);
414-
}
383+
if (spSingleLogoutServiceBinding != null)
384+
saml2Setting.setSpSingleLogoutServiceBinding(spSingleLogoutServiceBinding);
415385

416386
String spNameIDFormat = loadStringProperty(SP_NAMEIDFORMAT_PROPERTY_KEY);
417-
if (spNameIDFormat != null && !spNameIDFormat.isEmpty()) {
418-
saml2Setting.setSpNameIDFormat(spNameIDFormat);
419-
}
387+
if (spNameIDFormat != null && !spNameIDFormat.isEmpty())
388+
saml2Setting.setSpNameIDFormat(spNameIDFormat);
420389

421390
X509Certificate spX509cert = loadCertificateFromProp(SP_X509CERT_PROPERTY_KEY);
422-
if (spX509cert != null) {
423-
saml2Setting.setSpX509cert(spX509cert);
424-
}
391+
if (spX509cert != null)
392+
saml2Setting.setSpX509cert(spX509cert);
425393

426394
PrivateKey spPrivateKey = loadPrivateKeyFromProp(SP_PRIVATEKEY_PROPERTY_KEY);
427-
if (spPrivateKey != null) {
428-
saml2Setting.setSpPrivateKey(spPrivateKey);
429-
}
395+
if (spPrivateKey != null)
396+
saml2Setting.setSpPrivateKey(spPrivateKey);
430397
}
431398

432399
/**
@@ -458,7 +425,7 @@ private Boolean loadBooleanProperty(String propertyKey) {
458425
if (booleanPropValue != null) {
459426
return Boolean.parseBoolean(booleanPropValue.trim());
460427
}
461-
return null;
428+
return null;
462429
}
463430

464431
/**
@@ -478,7 +445,7 @@ private List<String> loadListProperty(String propertyKey) {
478445
}
479446
return Arrays.asList(values);
480447
}
481-
return null;
448+
return null;
482449
}
483450

484451
/**
@@ -493,14 +460,14 @@ private URL loadURLProperty(String propertyKey) {
493460

494461
String urlPropValue = prop.getProperty(propertyKey);
495462

496-
if (StringUtils.isBlank(urlPropValue)) {
497-
return null;
498-
}
463+
if (StringUtils.isBlank(urlPropValue)) {
464+
return null;
465+
}
499466

500-
try {
501-
return new URL(urlPropValue.trim());
502-
} catch (MalformedURLException e) {
503-
LOGGER.error("'" + propertyKey + "' contains malformed url.", e);
467+
try {
468+
return new URL(urlPropValue.trim());
469+
} catch (MalformedURLException e) {
470+
LOGGER.error("'" + propertyKey + "' contains malformed url.", e);
504471
return null;
505472
}
506473
}
@@ -516,15 +483,15 @@ private URL loadURLProperty(String propertyKey) {
516483
protected X509Certificate loadCertificateFromProp(String propertyKey) {
517484
String certString = prop.getProperty(propertyKey);
518485

519-
if (StringUtils.isBlank(certString)) {
486+
if (StringUtils.isBlank(certString)) {
520487
return null;
521-
}
488+
}
522489

523-
try {
524-
return Util.loadCert(certString);
525-
} catch (CertificateException e) {
526-
LOGGER.error("Error loading certificate from properties.", e);
527-
return null;
490+
try {
491+
return Util.loadCert(certString);
492+
} catch (CertificateException e) {
493+
LOGGER.error("Error loading certificate from properties.", e);
494+
return null;
528495
}
529496
}
530497

@@ -578,12 +545,12 @@ protected PrivateKey loadPrivateKeyFromProp(String propertyKey) {
578545
return null;
579546
}
580547

581-
try {
582-
return Util.loadPrivateKey(keyString);
583-
} catch (Exception e) {
584-
LOGGER.error("Error loading privatekey from properties.", e);
585-
return null;
586-
}
548+
try {
549+
return Util.loadPrivateKey(keyString);
550+
} catch (Exception e) {
551+
LOGGER.error("Error loading privatekey from properties.", e);
552+
return null;
553+
}
587554
}
588555

589556
/**

0 commit comments

Comments
 (0)