Skip to content

Commit d8aaa82

Browse files
authored
Merge pull request #107 from cgroix/master
Add onelogin.saml2.organization.lang attribute
2 parents 05bf024 + 95549b5 commit d8aaa82

File tree

10 files changed

+209
-17
lines changed

10 files changed

+209
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ onelogin.saml2.security.signature_algorithm = http://www.w3.org/2000/09/xmldsig#
329329
onelogin.saml2.organization.name = SP Java
330330
onelogin.saml2.organization.displayname = SP Java Example
331331
onelogin.saml2.organization.url = http://sp.example.com
332+
onelogin.saml2.organization.lang = en
332333

333334
# Contacts
334335
onelogin.saml2.contacts.technical.given_name = Technical Guy

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

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.net.URL;
44

5+
import org.apache.commons.lang3.StringUtils;
6+
57

68
/**
79
* Organization class of OneLogin's Java Toolkit.
@@ -23,6 +25,11 @@ public class Organization {
2325
* Organization URL
2426
*/
2527
private final String orgUrl;
28+
29+
/**
30+
* Organization lang attribute
31+
*/
32+
private final String orgLangAttribute;
2633

2734
/**
2835
* Constructor
@@ -32,12 +39,27 @@ public class Organization {
3239
* @param orgDisplayName
3340
* String. Organization display name
3441
* @param orgUrl
42+
* URL. Organization URL
43+
* @param orgLangAttribute
44+
* The xml lang attribute, describing name and display name
45+
*/
46+
public Organization(String orgName, String orgDisplayName, URL orgUrl, String orgLangAttribute) {
47+
this(orgName, orgDisplayName, orgUrl != null ? orgUrl.toString() : "", orgLangAttribute);
48+
}
49+
50+
/**
51+
* Constructor<br>
52+
* Default the lang attribute to "en"
53+
*
54+
* @param orgName
55+
* String. Organization name
56+
* @param orgDisplayName
57+
* String. Organization display name
58+
* @param orgUrl
3559
* URL. Organization URL
3660
*/
3761
public Organization(String orgName, String orgDisplayName, URL orgUrl) {
38-
this.orgName = orgName != null ? orgName : "";
39-
this.orgDisplayName = orgDisplayName != null ? orgDisplayName : "";
40-
this.orgUrl = orgUrl != null ? orgUrl.toString() : "";
62+
this(orgName, orgDisplayName, orgUrl, "en");
4163
}
4264

4365
/**
@@ -49,11 +71,29 @@ public Organization(String orgName, String orgDisplayName, URL orgUrl) {
4971
* String. Organization display name
5072
* @param orgUrl
5173
* String. Organization URL
74+
* @param orgLangAttribute
75+
* The xml lang attribute, describing name and display name
5276
*/
53-
public Organization(String orgName, String orgDisplayName, String orgUrl) {
77+
public Organization(String orgName, String orgDisplayName, String orgUrl, String orgLangAttribute) {
5478
this.orgName = orgName != null ? orgName : "";
5579
this.orgDisplayName = orgDisplayName != null ? orgDisplayName : "";
5680
this.orgUrl = orgUrl != null ? orgUrl : "";
81+
this.orgLangAttribute = StringUtils.defaultIfBlank(orgLangAttribute, "en");
82+
}
83+
84+
/**
85+
* Constructor<br>
86+
* Default the lang attribute to "en"
87+
*
88+
* @param orgName
89+
* String. Organization name
90+
* @param orgDisplayName
91+
* String. Organization display name
92+
* @param orgUrl
93+
* String. Organization URL
94+
*/
95+
public Organization(String orgName, String orgDisplayName, String orgUrl) {
96+
this(orgName, orgDisplayName, orgUrl, "en");
5797
}
5898

5999
/**
@@ -76,6 +116,13 @@ public final String getOrgDisplayName() {
76116
public final String getOrgUrl() {
77117
return orgUrl;
78118
}
119+
120+
/**
121+
* @return string the lang attribute
122+
*/
123+
public final String getOrgLangAttribute() {
124+
return orgLangAttribute;
125+
}
79126

80127
/**
81128
* Compare with another organization
@@ -85,6 +132,6 @@ public final String getOrgUrl() {
85132
* @return boolean true if organizations are equals
86133
*/
87134
public final Boolean equalsTo(Organization org) {
88-
return orgName.equals(org.getOrgName()) && orgDisplayName.equals(org.getOrgDisplayName()) && orgUrl.equals(org.getOrgUrl());
135+
return orgName.equals(org.getOrgName()) && orgDisplayName.equals(org.getOrgDisplayName()) && orgUrl.equals(org.getOrgUrl()) && orgLangAttribute.equals(org.getOrgLangAttribute());
89136
}
90137
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) throws Certif
152152

153153
valueMap.put("strKeyDescriptor", toX509KeyDescriptorsXML(settings.getSPcert()));
154154
valueMap.put("strContacts", toContactsXml(settings.getContacts()));
155-
valueMap.put("strOrganization", toOrganizationXml(settings.getOrganization(), "en"));
155+
valueMap.put("strOrganization", toOrganizationXml(settings.getOrganization()));
156156

157157
return new StrSubstitutor(valueMap);
158158
}
@@ -271,19 +271,13 @@ private String toContactsXml(List<Contact> contacts) {
271271
*
272272
* @param organization
273273
* organization object
274-
* @param lang
275-
* language
276-
*
277274
* @return the organization section of the metadata's template
278275
*/
279-
private String toOrganizationXml(Organization organization, String lang) {
276+
private String toOrganizationXml(Organization organization) {
280277
String orgXml = "";
281278

282-
if (lang == null) {
283-
lang = "en";
284-
}
285-
286279
if (organization != null) {
280+
String lang = organization.getOrgLangAttribute();
287281
orgXml = "<md:Organization><md:OrganizationName xml:lang=\"" + lang + "\">" + organization.getOrgName()
288282
+ "</md:OrganizationName><md:OrganizationDisplayName xml:lang=\"" + lang + "\">"
289283
+ organization.getOrgDisplayName() + "</md:OrganizationDisplayName><md:OrganizationURL xml:lang=\""

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class SettingsBuilder {
9898
public final static String ORGANIZATION_NAME = "onelogin.saml2.organization.name";
9999
public final static String ORGANIZATION_DISPLAYNAME = "onelogin.saml2.organization.displayname";
100100
public final static String ORGANIZATION_URL = "onelogin.saml2.organization.url";
101+
public final static String ORGANIZATION_LANG = "onelogin.saml2.organization.lang";
101102

102103
/**
103104
* Load settings from the file
@@ -324,9 +325,10 @@ private Organization loadOrganization() {
324325
String orgName = loadStringProperty(ORGANIZATION_NAME);
325326
String orgDisplayName = loadStringProperty(ORGANIZATION_DISPLAYNAME);
326327
URL orgUrl = loadURLProperty(ORGANIZATION_URL);
328+
String orgLangAttribute = loadStringProperty(ORGANIZATION_LANG);
327329

328330
if ((orgName != null && !orgName.isEmpty()) || (orgDisplayName != null && !orgDisplayName.isEmpty()) || (orgUrl != null)) {
329-
orgResult = new Organization(orgName, orgDisplayName, orgUrl);
331+
orgResult = new Organization(orgName, orgDisplayName, orgUrl, orgLangAttribute);
330332
}
331333

332334
return orgResult;

core/src/test/java/com/onelogin/saml2/test/model/OrganizationTest.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class OrganizationTest {
1818

1919
/**
20-
* Tests the Organization constructor
20+
* Tests the Organization constructors
2121
*
2222
* @throws MalformedURLException
2323
*
@@ -30,29 +30,58 @@ public void testOrganization() throws MalformedURLException {
3030
assertEquals("", org.getOrgName());
3131
assertEquals("", org.getOrgDisplayName());
3232
assertEquals("", org.getOrgUrl());
33+
assertEquals("en", org.getOrgLangAttribute());
3334

3435
String urlStr = null;
3536
Organization org2 = new Organization(null, null, urlStr);
3637
assertEquals("", org2.getOrgName());
3738
assertEquals("", org2.getOrgDisplayName());
3839
assertEquals("", org2.getOrgUrl());
40+
assertEquals("en", org2.getOrgLangAttribute());
3941

4042
URL urlExample = new URL("http://example.com");
4143
Organization org3 = new Organization("", "", urlExample);
4244
assertEquals("", org3.getOrgName());
4345
assertEquals("", org3.getOrgDisplayName());
4446
assertEquals("http://example.com", org3.getOrgUrl());
47+
assertEquals("en", org3.getOrgLangAttribute());
4548

4649
String urlExampleStr = "http://example.com";
4750
Organization org4 = new Organization("", "", urlExampleStr);
4851
assertEquals("", org4.getOrgName());
4952
assertEquals("", org4.getOrgDisplayName());
5053
assertEquals("http://example.com", org4.getOrgUrl());
54+
assertEquals("en", org4.getOrgLangAttribute());
5155

5256
Organization org5 = new Organization("OrgName", "DisplayName", urlExampleStr);
5357
assertEquals("OrgName", org5.getOrgName());
5458
assertEquals("DisplayName", org5.getOrgDisplayName());
5559
assertEquals("http://example.com", org5.getOrgUrl());
60+
assertEquals("en", org5.getOrgLangAttribute());
61+
62+
Organization org6 = new Organization("NomOrg", "DisplayName", urlExampleStr, "fr");
63+
assertEquals("NomOrg", org6.getOrgName());
64+
assertEquals("DisplayName", org6.getOrgDisplayName());
65+
assertEquals("http://example.com", org6.getOrgUrl());
66+
assertEquals("fr", org6.getOrgLangAttribute());
67+
68+
Organization org7 = new Organization("NomOrg", "DisplayName", urlExample, "fr");
69+
assertEquals("NomOrg", org7.getOrgName());
70+
assertEquals("DisplayName", org7.getOrgDisplayName());
71+
assertEquals("http://example.com", org7.getOrgUrl());
72+
assertEquals("fr", org7.getOrgLangAttribute());
73+
74+
Organization org8 = new Organization("OrgName", "DisplayName", urlExampleStr, "");
75+
assertEquals("OrgName", org8.getOrgName());
76+
assertEquals("DisplayName", org8.getOrgDisplayName());
77+
assertEquals("http://example.com", org8.getOrgUrl());
78+
assertEquals("en", org8.getOrgLangAttribute());
79+
80+
Organization org9 = new Organization("OrgName", "DisplayName", urlExampleStr, null);
81+
assertEquals("OrgName", org9.getOrgName());
82+
assertEquals("DisplayName", org9.getOrgDisplayName());
83+
assertEquals("http://example.com", org9.getOrgUrl());
84+
assertEquals("en", org9.getOrgLangAttribute());
5685
}
5786

5887
/**
@@ -67,11 +96,14 @@ public void testEqualsTo() {
6796
Organization org3 = new Organization("SP Java 3", "SP Java Example", "http://sp.example.com");
6897
Organization org4 = new Organization("SP Java", "SP Java Example 4", "http://sp.example.com");
6998
Organization org5 = new Organization("SP Java", "SP Java Example", "http://sp.example.com/5");
70-
Organization org6 = new Organization("SP Java 6", "SP Java Example 6", "http://sp.example.com/6");
99+
Organization org6 = new Organization("SP Java", "SP Java Example", "http://sp.example.com", "en");
100+
Organization org7 = new Organization("SP Java", "SP Java Example", "http://sp.example.com", "fr");
71101

72102
assertTrue(org.equalsTo(org2));
73103
assertFalse(org.equalsTo(org3));
74104
assertFalse(org.equalsTo(org4));
75105
assertFalse(org.equalsTo(org5));
106+
assertTrue(org.equalsTo(org6));
107+
assertFalse(org.equalsTo(org7));
76108
}
77109
}

core/src/test/java/com/onelogin/saml2/test/settings/MetadataTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,57 @@ public void testToOrganizationXml() throws IOException, CertificateEncodingExcep
143143

144144
assertThat(metadataStr2, not(containsString(orgStr)));
145145
}
146+
147+
/**
148+
* Tests the toOrganizationXml method of Metadata without any "lang" attribute
149+
*
150+
* @throws IOException
151+
* @throws CertificateEncodingException
152+
* @throws Error
153+
*
154+
* @see com.onelogin.saml2.settings.Metadata#toOrganizationXml
155+
*/
156+
@Test
157+
public void testToNonLocalizedOrganizationXml() throws IOException, CertificateEncodingException, Error {
158+
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.org.properties").build();
159+
Metadata metadataObj = new Metadata(settings);
160+
String metadataStr = metadataObj.getMetadataString();
161+
162+
String orgStr = "<md:Organization><md:OrganizationName xml:lang=\"en\">SP Java</md:OrganizationName><md:OrganizationDisplayName xml:lang=\"en\">SP Java Example</md:OrganizationDisplayName><md:OrganizationURL xml:lang=\"en\">http://sp.example.com</md:OrganizationURL></md:Organization>";
163+
assertThat(metadataStr, containsString(orgStr));
164+
165+
Saml2Settings settings2 = new SettingsBuilder().fromFile("config/config.min.properties").build();
166+
Metadata metadataObj2 = new Metadata(settings2);
167+
String metadataStr2 = metadataObj2.getMetadataString();
168+
169+
assertThat(metadataStr2, not(containsString(orgStr)));
170+
}
171+
172+
173+
/**
174+
* Tests the toOrganizationXml method of Metadata using a non default "lang" attribute
175+
*
176+
* @throws IOException
177+
* @throws CertificateEncodingException
178+
* @throws Error
179+
*
180+
* @see com.onelogin.saml2.settings.Metadata#toOrganizationXml
181+
*/
182+
@Test
183+
public void testToLocalizedOrganizationXml() throws IOException, CertificateEncodingException, Error {
184+
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.org.localized.properties").build();
185+
Metadata metadataObj = new Metadata(settings);
186+
String metadataStr = metadataObj.getMetadataString();
187+
188+
String orgStr = "<md:Organization><md:OrganizationName xml:lang=\"fr\">SP Java</md:OrganizationName><md:OrganizationDisplayName xml:lang=\"fr\">SP Exemple Java</md:OrganizationDisplayName><md:OrganizationURL xml:lang=\"fr\">http://sp.example.com/fr</md:OrganizationURL></md:Organization>";
189+
assertThat(metadataStr, containsString(orgStr));
190+
191+
Saml2Settings settings2 = new SettingsBuilder().fromFile("config/config.min.properties").build();
192+
Metadata metadataObj2 = new Metadata(settings2);
193+
String metadataStr2 = metadataObj2.getMetadataString();
194+
195+
assertThat(metadataStr2, not(containsString(orgStr)));
196+
}
146197

147198
/**
148199
* Tests the toSLSXml method of Metadata

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ onelogin.saml2.security.signature_algorithm = http://www.w3.org/2001/04/xmldsig-
131131
onelogin.saml2.organization.name = SP Java
132132
onelogin.saml2.organization.displayname = SP Java Example
133133
onelogin.saml2.organization.url = http://sp.example.com
134+
onelogin.saml2.organization.lang = en
134135

135136
# Contacts
136137
onelogin.saml2.contacts.technical.given_name = Technical Guy
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
config.all.properties# Service Provider Data that we are deploying
2+
# Identifier of the SP entity (must be a URI)
3+
onelogin.saml2.sp.entityid = http://localhost:8080/java-saml-jspsample/metadata.jsp
4+
# Specifies info about where and how the <AuthnResponse> message MUST be
5+
# returned to the requester, in this case our SP.
6+
# URL Location where the <Response> from the IdP will be returned
7+
onelogin.saml2.sp.assertion_consumer_service.url = http://localhost:8080/java-saml-jspsample/acs.jsp
8+
9+
# Specifies info about Logout service
10+
# URL Location where the <LogoutResponse> from the IdP will be returned or where to send the <LogoutRequest>
11+
onelogin.saml2.sp.single_logout_service.url = http://localhost:8080/java-saml-jspsample/sls.jsp
12+
13+
# Identity Provider Data that we want connect with our SP
14+
# Identifier of the IdP entity (must be a URI)
15+
onelogin.saml2.idp.entityid = http://idp.example.com/
16+
17+
# SSO endpoint info of the IdP. (Authentication Request protocol)
18+
# URL Target of the IdP where the SP will send the Authentication Request Message
19+
onelogin.saml2.idp.single_sign_on_service.url = http://idp.example.com/simplesaml/saml2/idp/SSOService.php
20+
21+
# SLO endpoint info of the IdP.
22+
# URL Location of the IdP where the SP will send the SLO Request
23+
onelogin.saml2.idp.single_logout_service.url = http://idp.example.com/simplesaml/saml2/idp/SingleLogoutService.php
24+
25+
# Public x509 certificate of the IdP
26+
onelogin.saml2.idp.x509cert = -----BEGIN CERTIFICATE-----\nMIIBrTCCAaGgAwIBAgIBATADBgEAMGcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRUwEwYDVQQHDAxTYW50YSBNb25pY2ExETAPBgNVBAoMCE9uZUxvZ2luMRkwFwYDVQQDDBBhcHAub25lbG9naW4uY29tMB4XDTEwMTAxMTIxMTUxMloXDTE1MTAxMTIxMTUxMlowZzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFTATBgNVBAcMDFNhbnRhIE1vbmljYTERMA8GA1UECgwIT25lTG9naW4xGTAXBgNVBAMMEGFwcC5vbmVsb2dpbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMPmjfjy7L35oDpeBXBoRVCgktPkLno9DOEWB7MgYMMVKs2B6ymWQLEWrDugMK1hkzWFhIb5fqWLGbWy0J0veGR9/gHOQG+rD/I36xAXnkdiXXhzoiAG/zQxM0edMOUf40n314FC8moErcUg6QabttzesO59HFz6shPuxcWaVAgxAgMBAAEwAwYBAAMBAA==\n-----END CERTIFICATE-----
27+
28+
# Organization
29+
onelogin.saml2.organization.name = SP Java
30+
onelogin.saml2.organization.displayname = SP Exemple Java
31+
onelogin.saml2.organization.url = http://sp.example.com/fr
32+
onelogin.saml2.organization.lang = fr
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
config.all.properties# Service Provider Data that we are deploying
2+
# Identifier of the SP entity (must be a URI)
3+
onelogin.saml2.sp.entityid = http://localhost:8080/java-saml-jspsample/metadata.jsp
4+
# Specifies info about where and how the <AuthnResponse> message MUST be
5+
# returned to the requester, in this case our SP.
6+
# URL Location where the <Response> from the IdP will be returned
7+
onelogin.saml2.sp.assertion_consumer_service.url = http://localhost:8080/java-saml-jspsample/acs.jsp
8+
9+
# Specifies info about Logout service
10+
# URL Location where the <LogoutResponse> from the IdP will be returned or where to send the <LogoutRequest>
11+
onelogin.saml2.sp.single_logout_service.url = http://localhost:8080/java-saml-jspsample/sls.jsp
12+
13+
# Identity Provider Data that we want connect with our SP
14+
# Identifier of the IdP entity (must be a URI)
15+
onelogin.saml2.idp.entityid = http://idp.example.com/
16+
17+
# SSO endpoint info of the IdP. (Authentication Request protocol)
18+
# URL Target of the IdP where the SP will send the Authentication Request Message
19+
onelogin.saml2.idp.single_sign_on_service.url = http://idp.example.com/simplesaml/saml2/idp/SSOService.php
20+
21+
# SLO endpoint info of the IdP.
22+
# URL Location of the IdP where the SP will send the SLO Request
23+
onelogin.saml2.idp.single_logout_service.url = http://idp.example.com/simplesaml/saml2/idp/SingleLogoutService.php
24+
25+
# Public x509 certificate of the IdP
26+
onelogin.saml2.idp.x509cert = -----BEGIN CERTIFICATE-----\nMIIBrTCCAaGgAwIBAgIBATADBgEAMGcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRUwEwYDVQQHDAxTYW50YSBNb25pY2ExETAPBgNVBAoMCE9uZUxvZ2luMRkwFwYDVQQDDBBhcHAub25lbG9naW4uY29tMB4XDTEwMTAxMTIxMTUxMloXDTE1MTAxMTIxMTUxMlowZzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFTATBgNVBAcMDFNhbnRhIE1vbmljYTERMA8GA1UECgwIT25lTG9naW4xGTAXBgNVBAMMEGFwcC5vbmVsb2dpbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMPmjfjy7L35oDpeBXBoRVCgktPkLno9DOEWB7MgYMMVKs2B6ymWQLEWrDugMK1hkzWFhIb5fqWLGbWy0J0veGR9/gHOQG+rD/I36xAXnkdiXXhzoiAG/zQxM0edMOUf40n314FC8moErcUg6QabttzesO59HFz6shPuxcWaVAgxAgMBAAEwAwYBAAMBAA==\n-----END CERTIFICATE-----
27+
28+
# Organization
29+
onelogin.saml2.organization.name = SP Java
30+
onelogin.saml2.organization.displayname = SP Java Example
31+
onelogin.saml2.organization.url = http://sp.example.com

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ onelogin.saml2.security.signature_algorithm = http://www.w3.org/2000/09/xmldsig#
151151
onelogin.saml2.organization.name = SP Java
152152
onelogin.saml2.organization.displayname = SP Java Example
153153
onelogin.saml2.organization.url = http://sp.example.com
154+
onelogin.saml2.organization.lang =
154155

155156
# Contacts
156157
onelogin.saml2.contacts.technical.given_name = Technical Guy

0 commit comments

Comments
 (0)