Skip to content

Commit 6714bda

Browse files
committed
Move allow_duplicated_attribute_name from sp settings to security. Add documentation
1 parent abec336 commit 6714bda

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ java-saml (com.onelogin:java-saml-toolkit) has the following dependencies:
110110
* For CI:
111111
* org.jacoco:jacoco-maven-plugin
112112

113-
also the [Java Cryptography Extension (JCE)](https://en.wikipedia.org/wiki/Java_Cryptography_Extension) is required. If you don't have it, download the version of [jce-6](http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html), [jce-7](http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html) or [jce-8](http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html), unzip it, and drop its content at
114-
*${java.home}/jre/lib/security/*
113+
also the [Java Cryptography Extension (JCE)](https://en.wikipedia.org/wiki/Java_Cryptography_Extension) is required. If you don't have it, download the version of [jce-8](http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html), unzip it, and drop its content at
114+
*${java.home}/jre/lib/security/*. JDK 9 and later offer the stronger cryptographic algorithms by default.
115115

116116
*toolkit:*
117117
* com.onelogin:java-saml-core
@@ -123,7 +123,7 @@ also the [Java Cryptography Extension (JCE)](https://en.wikipedia.org/wiki/Java_
123123
* org.apache.maven.plugins:maven-enforcer-plugin
124124

125125
For more info, open and read the different pom.xml files:
126-
[core/pom.xml](https://github.com/onelogin/java-saml/blob/v2.2.0/core/pom.xml), [toolkit/pom.xml](https://github.com/onelogin/java-saml/blob/v2.2.0/toolkit/pom.xml)
126+
[core/pom.xml](https://github.com/onelogin/java-saml/blob/v2.5.0/core/pom.xml), [toolkit/pom.xml](https://github.com/onelogin/java-saml/blob/v2.5.0/toolkit/pom.xml)
127127

128128
## Working with the github repository code and Eclipse.
129129
### Get the toolkit.
@@ -329,6 +329,9 @@ onelogin.saml2.security.requested_authncontext = urn:oasis:names:tc:SAML:2.0:ac:
329329
# Allows the authn comparison parameter to be set, defaults to 'exact'
330330
onelogin.saml2.security.requested_authncontextcomparison = exact
331331

332+
# Allows duplicated names in the attribute statement
333+
onelogin.saml2.security.allow_duplicated_attribute_name = false
334+
332335
# Indicates if the SP will validate all received xmls.
333336
# (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true).
334337
onelogin.saml2.security.want_xml_validation = true

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,14 @@ public HashMap<String, List<String>> getAttributes() throws XPathExpressionExcep
549549
for (int i = 0; i < nodes.getLength(); i++) {
550550
NamedNodeMap attrName = nodes.item(i).getAttributes();
551551
String attName = attrName.getNamedItem("Name").getNodeValue();
552-
if (attributes.containsKey(attName) && !settings.isSpAllowRepeatAttributeName()) {
552+
if (attributes.containsKey(attName) && !settings.isAllowRepeatAttributeName()) {
553553
throw new ValidationError("Found an Attribute element with duplicated Name", ValidationError.DUPLICATED_ATTRIBUTE_NAME_FOUND);
554554
}
555555

556556
NodeList childrens = nodes.item(i).getChildNodes();
557557

558558
List<String> attrValues = null;
559-
if (attributes.containsKey(attName) && settings.isSpAllowRepeatAttributeName()) {
559+
if (attributes.containsKey(attName) && settings.isAllowRepeatAttributeName()) {
560560
attrValues = attributes.get(attName);
561561
} else {
562562
attrValues = new ArrayList<String>();

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public class Saml2Settings {
3939
private URL spSingleLogoutServiceUrl = null;
4040
private String spSingleLogoutServiceBinding = Constants.BINDING_HTTP_REDIRECT;
4141
private String spNameIDFormat = Constants.NAMEID_UNSPECIFIED;
42-
private boolean spAllowRepeatAttributeName = false;
4342
private X509Certificate spX509cert = null;
4443
private X509Certificate spX509certNew = null;
4544
private PrivateKey spPrivateKey = null;
@@ -73,6 +72,7 @@ public class Saml2Settings {
7372
private String signatureAlgorithm = Constants.RSA_SHA1;
7473
private String digestAlgorithm = Constants.SHA1;
7574
private boolean rejectUnsolicitedResponsesWithInResponseTo = false;
75+
private boolean allowRepeatAttributeName = false;
7676
private String uniqueIDPrefix = null;
7777

7878
// Compress
@@ -135,10 +135,10 @@ public final String getSpNameIDFormat() {
135135
}
136136

137137
/**
138-
* @return the spAllowRepeatAttributeName setting value
138+
* @return the allowRepeatAttributeName setting value
139139
*/
140-
public boolean isSpAllowRepeatAttributeName () {
141-
return spAllowRepeatAttributeName;
140+
public boolean isAllowRepeatAttributeName () {
141+
return allowRepeatAttributeName;
142142
}
143143

144144
/**
@@ -450,13 +450,13 @@ protected final void setSpNameIDFormat(String spNameIDFormat) {
450450
}
451451

452452
/**
453-
* Set the spAllowRepeatAttributeName setting value
453+
* Set the allowRepeatAttributeName setting value
454454
*
455-
* @param spAllowRepeatAttributeName
456-
* the spAllowRepeatAttributeName value to be set
455+
* @param allowRepeatAttributeName
456+
* the allowRepeatAttributeName value to be set
457457
*/
458-
public void setSpAllowRepeatAttributeName (boolean spAllowRepeatAttributeName) {
459-
this.spAllowRepeatAttributeName = spAllowRepeatAttributeName;
458+
public void setAllowRepeatAttributeName (boolean allowRepeatAttributeName) {
459+
this.allowRepeatAttributeName = allowRepeatAttributeName;
460460
}
461461

462462
/**

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public class SettingsBuilder {
6060
public final static String SP_SINGLE_LOGOUT_SERVICE_URL_PROPERTY_KEY = "onelogin.saml2.sp.single_logout_service.url";
6161
public final static String SP_SINGLE_LOGOUT_SERVICE_BINDING_PROPERTY_KEY = "onelogin.saml2.sp.single_logout_service.binding";
6262
public final static String SP_NAMEIDFORMAT_PROPERTY_KEY = "onelogin.saml2.sp.nameidformat";
63-
public final static String SP_ALLOW_REPEAT_ATTRIBUTE_NAME_PROPERTY_KEY = "onelogin.saml2.sp.allow_duplicated_attribute_name";
6463

6564
public final static String SP_X509CERT_PROPERTY_KEY = "onelogin.saml2.sp.x509cert";
6665
public final static String SP_PRIVATEKEY_PROPERTY_KEY = "onelogin.saml2.sp.privatekey";
@@ -100,6 +99,7 @@ public class SettingsBuilder {
10099
public final static String SECURITY_WANT_XML_VALIDATION = "onelogin.saml2.security.want_xml_validation";
101100
public final static String SECURITY_SIGNATURE_ALGORITHM = "onelogin.saml2.security.signature_algorithm";
102101
public final static String SECURITY_REJECT_UNSOLICITED_RESPONSES_WITH_INRESPONSETO = "onelogin.saml2.security.reject_unsolicited_responses_with_inresponseto";
102+
public final static String SECURITY_ALLOW_REPEAT_ATTRIBUTE_NAME_PROPERTY_KEY = "onelogin.saml2.security.allow_duplicated_attribute_name";
103103

104104
// Compress
105105
public final static String COMPRESS_REQUEST = "onelogin.saml2.compress.request";
@@ -369,6 +369,10 @@ private void loadSecuritySetting() {
369369
if (rejectUnsolicitedResponsesWithInResponseTo != null) {
370370
saml2Setting.setRejectUnsolicitedResponsesWithInResponseTo(rejectUnsolicitedResponsesWithInResponseTo);
371371
}
372+
373+
Boolean allowRepeatAttributeName = loadBooleanProperty(SECURITY_ALLOW_REPEAT_ATTRIBUTE_NAME_PROPERTY_KEY);
374+
if (allowRepeatAttributeName != null)
375+
saml2Setting.setAllowRepeatAttributeName(allowRepeatAttributeName);
372376
}
373377

374378
/**
@@ -469,10 +473,6 @@ private void loadSpSetting() {
469473
if (spNameIDFormat != null && !spNameIDFormat.isEmpty())
470474
saml2Setting.setSpNameIDFormat(spNameIDFormat);
471475

472-
Boolean spAllowRepeatAttributeName = loadBooleanProperty(SP_ALLOW_REPEAT_ATTRIBUTE_NAME_PROPERTY_KEY);
473-
if (spAllowRepeatAttributeName != null)
474-
saml2Setting.setSpAllowRepeatAttributeName(spAllowRepeatAttributeName);
475-
476476
boolean keyStoreEnabled = this.samlData.get(KEYSTORE_KEY) != null && this.samlData.get(KEYSTORE_ALIAS) != null
477477
&& this.samlData.get(KEYSTORE_KEY_PASSWORD) != null;
478478

core/src/test/resources/config/config.allowduplicatednames.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ onelogin.saml2.sp.single_logout_service.binding = urn:oasis:names:tc:SAML:2.0:bi
3131
# Take a look on lib/Saml2/Constants.php to see the NameIdFormat supported
3232
onelogin.saml2.sp.nameidformat = urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
3333

34-
# Enable duplicated names in the attribute statement
35-
onelogin.saml2.sp.allow_duplicated_attribute_name = true
3634

3735
# Usually x509cert and privateKey of the SP are provided by files placed at
3836
# the certs folder. But we can also provide them with the following parameters
@@ -115,6 +113,8 @@ onelogin.saml2.security.requested_authncontext = urn:oasis:names:tc:SAML:2.0:ac:
115113
# Allows the authn comparison parameter to be set, defaults to 'exact'
116114
onelogin.saml2.security.requested_authncontextcomparison = exact
117115

116+
# Enable duplicated names in the attribute statement
117+
onelogin.saml2.security.allow_duplicated_attribute_name = true
118118

119119
# Indicates if the SP will validate all received xmls.
120120
# (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true).

samples/java-saml-tookit-jspsample/src/main/resources/onelogin.saml.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ onelogin.saml2.security.requested_authncontext = urn:oasis:names:tc:SAML:2.0:ac:
132132
# Allows the authn comparison parameter to be set, defaults to 'exact'
133133
onelogin.saml2.security.onelogin.saml2.security.requested_authncontextcomparison = exact
134134

135+
# Allows duplicated names in the attribute statement
136+
onelogin.saml2.security.allow_duplicated_attribute_name = false
135137

136138
# Indicates if the SP will validate all received xmls.
137139
# (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true).

0 commit comments

Comments
 (0)