Skip to content

Commit ddf6328

Browse files
committed
Code clean
1 parent 90960e2 commit ddf6328

17 files changed

Lines changed: 88 additions & 46 deletions

File tree

core/src/main/java/com/onelogin/saml2/authn/AuthnRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public class AuthnRequest {
6363
*/
6464
private final Calendar issueInstant;
6565

66+
/**
67+
* Constructs the AuthnRequest object.
68+
*
69+
* @param settings
70+
* OneLogin_Saml2_Settings
71+
*/
6672
public AuthnRequest(Saml2Settings settings) {
6773
this(settings, false, false, true);
6874
}

core/src/main/java/com/onelogin/saml2/authn/SamlResponse.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import java.util.HashMap;
77
import java.util.List;
88
import java.util.Map;
9+
import java.util.Objects;
910

1011
import javax.xml.xpath.XPathExpressionException;
1112

12-
import org.apache.commons.lang3.ObjectUtils;
1313
import org.joda.time.DateTime;
1414
import org.joda.time.Instant;
1515
import org.slf4j.Logger;
@@ -187,7 +187,7 @@ public boolean isValid(String requestId) {
187187
}
188188

189189
// Check if the InResponseTo of the Response matches the ID of the AuthNRequest (requestId) if provided
190-
if (requestId != null && !ObjectUtils.equals(responseInResponseTo, requestId)) {
190+
if (requestId != null && !Objects.equals(responseInResponseTo, requestId)) {
191191
throw new Exception("The InResponseTo of the Response: " + responseInResponseTo
192192
+ ", does not match the ID of the AuthNRequest sent by the SP: " + requestId);
193193
}
@@ -290,7 +290,7 @@ public boolean isValid(String requestId) {
290290

291291
LOGGER.debug("SAMLResponse validated --> " + samlResponseString);
292292
return true;
293-
} catch (Error | Exception e) {
293+
} catch (Exception e) {
294294
error = e.getMessage();
295295
LOGGER.debug("SAMLResponse invalid --> " + samlResponseString);
296296
LOGGER.error(error);
@@ -417,7 +417,6 @@ public HashMap<String,String> getNameIdData() throws Exception {
417417
nameIdData.put("Format", nameIdElem.getAttribute("Format"));
418418
}
419419
if (nameIdElem.hasAttribute("SPNameQualifier")) {
420-
String spId = settings.getSpEntityId();
421420
String spNameQualifier = nameIdElem.getAttribute("SPNameQualifier");
422421
if (settings.isStrict() && !spNameQualifier.equals(settings.getSpEntityId())) {
423422
throw new Exception("The SPNameQualifier value mistmatch the SP entityID value.");
@@ -891,7 +890,7 @@ public void setDestinationUrl(String urld) {
891890
*/
892891
public String getError() {
893892
if (error != null) {
894-
return error.toString();
893+
return error;
895894
}
896895
return null;
897896
}

core/src/main/java/com/onelogin/saml2/http/HttpRequest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@ public Map<String, List<String>> getParameters() {
112112

113113
@Override
114114
public boolean equals(Object o) {
115-
if (this == o) return true;
116-
if (o == null || getClass() != o.getClass()) return false;
115+
if (this == o) {
116+
return true;
117+
}
118+
119+
if (o == null || getClass() != o.getClass()) {
120+
return false;
121+
}
122+
117123
HttpRequest that = (HttpRequest) o;
118124
return Objects.equals(requestURL, that.requestURL) &&
119125
Objects.equals(parameters, that.parameters);

core/src/main/java/com/onelogin/saml2/logout/LogoutRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public LogoutRequest(Saml2Settings settings, HttpRequest request, String nameId,
105105

106106
if (request != null) {
107107
samlLogoutRequest = request.getParameter("SAMLRequest");
108-
currentUrl = request.getRequestURL().toString();
108+
currentUrl = request.getRequestURL();
109109
}
110110

111111
if (samlLogoutRequest == null) {

core/src/main/java/com/onelogin/saml2/logout/LogoutResponse.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public LogoutResponse(Saml2Settings settings, HttpRequest request) throws XMLEnt
9595

9696
String samlLogoutResponse = null;
9797
if (request != null) {
98-
currentUrl = request.getRequestURL().toString();
98+
currentUrl = request.getRequestURL();
9999
samlLogoutResponse = request.getParameter("SAMLResponse");
100100
}
101101

@@ -148,8 +148,6 @@ protected String getLogoutResponseXml() {
148148
* @param requestId
149149
* The ID of the LogoutRequest sent by this SP to the IdP
150150
*
151-
* @throws Exception
152-
*
153151
* @return if the SAML LogoutResponse is or not valid
154152
*/
155153
public Boolean isValid(String requestId) {

core/src/main/java/com/onelogin/saml2/model/RequestedAttribute.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.onelogin.saml2.model;
22

3-
import java.util.ArrayList;
43
import java.util.List;
54

65

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.onelogin.saml2.settings;
22

33
import java.net.URL;
4-
import java.util.ArrayList;
54
import java.util.Calendar;
65
import java.util.HashMap;
76
import java.util.List;
@@ -147,11 +146,11 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) throws Certif
147146
valueMap.put("spNameIDFormat", settings.getSpNameIDFormat());
148147
valueMap.put("spAssertionConsumerServiceBinding", settings.getSpAssertionConsumerServiceBinding());
149148
valueMap.put("spAssertionConsumerServiceUrl", settings.getSpAssertionConsumerServiceUrl().toString());
150-
valueMap.put("sls", toSLSXml(settings.getSpSingleLogoutServiceUrl(), settings.getSpSingleLogoutServiceBinding()).toString());
149+
valueMap.put("sls", toSLSXml(settings.getSpSingleLogoutServiceUrl(), settings.getSpSingleLogoutServiceBinding()));
151150

152151
valueMap.put("strAttributeConsumingService", getAttributeConsumingServiceXml());
153152

154-
valueMap.put("strKeyDescriptor", toX509KeyDescriptorsXML(settings.getSPcert()).toString());
153+
valueMap.put("strKeyDescriptor", toX509KeyDescriptorsXML(settings.getSPcert()));
155154
valueMap.put("strContacts", toContactsXml(settings.getContacts()));
156155
valueMap.put("strOrganization", toOrganizationXml(settings.getOrganization(), "en"));
157156

core/src/main/java/com/onelogin/saml2/util/Constants.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
* A class that contains several constants related to the SAML protocol
77
*/
88
public final class Constants {
9-
// Value added to the current time in time condition validations
9+
/**
10+
* Value added to the current time in time condition validations.
11+
*/
1012
public static Integer ALOWED_CLOCK_DRIFT = 180; // 3 min in seconds
1113

12-
// NameID Formats
14+
// NameID Formats
1315
public static String NAMEID_EMAIL_ADDRESS = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress";
1416
public static String NAMEID_X509_SUBJECT_NAME = "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName";
1517
public static String NAMEID_WINDOWS_DOMAIN_QUALIFIED_NAME = "urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName";
@@ -95,4 +97,8 @@ public final class Constants {
9597

9698
public static String ENVSIG = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
9799

100+
private Constants() {
101+
//not called
102+
}
103+
98104
}

core/src/main/java/com/onelogin/saml2/util/SchemaFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
* A class that read SAML schemas that will be used to validate XMLs of the OneLogin's Java Toolkit
1414
*/
1515
public abstract class SchemaFactory {
16+
17+
private SchemaFactory() {
18+
//not called
19+
}
20+
1621
public static final URL SAML_SCHEMA_METADATA_2_0 = SchemaFactory.class
1722
.getResource("/schemas/saml-schema-metadata-2.0.xsd");
1823
public static final URL SAML_SCHEMA_PROTOCOL_2_0 = SchemaFactory.class

core/src/main/java/com/onelogin/saml2/util/Util.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.apache.commons.codec.binary.Base64;
5555
import org.apache.commons.codec.digest.DigestUtils;
5656
import org.apache.commons.lang3.StringUtils;
57-
import org.apache.xml.security.encryption.CipherData;
5857
import org.apache.xml.security.encryption.EncryptedData;
5958
import org.apache.xml.security.encryption.EncryptedKey;
6059
import org.apache.xml.security.encryption.XMLCipher;
@@ -102,6 +101,10 @@ public final class Util {
102101

103102
private static final Logger log = LoggerFactory.getLogger(Util.class);
104103

104+
private Util() {
105+
//not called
106+
}
107+
105108
/**
106109
* This function load an XML string in a save way. Prevent XEE/XXE Attacks
107110
*
@@ -144,6 +147,7 @@ public static NodeList query(Document dom, String query, Node context) throws XP
144147
XPath xpath = XPathFactory.newInstance().newXPath();
145148
xpath.setNamespaceContext(new NamespaceContext() {
146149

150+
@Override
147151
public String getNamespaceURI(String prefix) {
148152
String result = null;
149153
if (prefix.equals("samlp") || prefix.equals("samlp2")) {
@@ -160,11 +164,13 @@ public String getNamespaceURI(String prefix) {
160164
return result;
161165
}
162166

167+
@Override
163168
public String getPrefix(String namespaceURI) {
164169
return null;
165170
}
166171

167172
@SuppressWarnings("rawtypes")
173+
@Override
168174
public Iterator getPrefixes(String namespaceURI) {
169175
return null;
170176
}
@@ -262,28 +268,28 @@ public static Document convertStringToDocument(String xmlStr) throws ParserConfi
262268
try {
263269
// do not include external general entities
264270
docfactory.setAttribute("http://xml.org/sax/features/external-general-entities", Boolean.FALSE);
265-
} catch (Throwable t) {}
271+
} catch (Exception e) {}
266272
try {
267273
// do not include external parameter entities or the external DTD subset
268274
docfactory.setAttribute("http://xml.org/sax/features/external-parameter-entities", Boolean.FALSE);
269-
} catch (Throwable t) {}
275+
} catch (Exception e) {}
270276
try {
271277
docfactory.setAttribute("http://apache.org/xml/features/disallow-doctype-decl", Boolean.TRUE);
272-
} catch (Throwable t) {}
278+
} catch (Exception e) {}
273279
try {
274280
docfactory.setAttribute("http://javax.xml.XMLConstants/feature/secure-processing", Boolean.TRUE);
275-
} catch (Throwable t) {}
281+
} catch (Exception e) {}
276282
try {
277283
// ignore the external DTD completely
278284
docfactory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
279-
} catch (Throwable t) {}
285+
} catch (Exception e) {}
280286
try {
281287
// build the grammar but do not use the default attributes and attribute types information it contains
282288
docfactory.setAttribute("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", Boolean.FALSE);
283-
} catch (Throwable t) {}
289+
} catch (Exception e) {}
284290
try {
285291
docfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
286-
} catch (Throwable t) {}
292+
} catch (Exception e) {}
287293

288294
DocumentBuilder builder = docfactory.newDocumentBuilder();
289295
Document doc = builder.parse(new InputSource(new StringReader(xmlStr)));

0 commit comments

Comments
 (0)