From 996774dbf06b037d9f843e57a2cfac9bcc111a51 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 24 May 2019 08:14:55 +0200 Subject: update Demo-OA to illustrate SAML2 SubjectNameId --- .../egovernment/moa/id/demoOA/Configuration.java | 16 +++++++- .../moa/id/demoOA/servlet/pvp2/Authenticate.java | 44 +++++++++++++--------- .../id/demoOA/servlet/pvp2/DemoApplication.java | 23 ++++++++--- .../moa/id/demoOA/utils/ApplicationBean.java | 9 +++++ id/oa/src/main/webapp/demoapp.jsp | 6 ++- id/oa/src/main/webapp/index.jsp | 2 + 6 files changed, 76 insertions(+), 24 deletions(-) (limited to 'id/oa') diff --git a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/Configuration.java b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/Configuration.java index 09069ac7f..8ada01cb6 100644 --- a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/Configuration.java +++ b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/Configuration.java @@ -182,6 +182,21 @@ public class Configuration { return Boolean.parseBoolean(props.getProperty("general.login.pvp2.binding.resp.redirect", "false")); } + + public boolean setAuthnContextClassRef() { + return Boolean.parseBoolean(props.getProperty("general.login.pvp2.req.set.authncontextclassref", "true")); + } + + public String getScopeRequesterId() { + return props.getProperty("general.login.pvp2.sp.requesterId"); + } + + public boolean setNameIdPolicy() { + return Boolean.parseBoolean(props.getProperty("general.login.pvp2.req.set.nameIDPolicy", "true")); + } + + + public void initializePVP2Login() throws ConfigurationException { if (!pvp2logininitialzied) initalPVP2Login(); @@ -276,6 +291,5 @@ public class Configuration { throw new ConfigurationException("PVP2 authentification can not be initialized.", e); } } - } diff --git a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/Authenticate.java b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/Authenticate.java index 4c909ff80..0671b8c14 100644 --- a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/Authenticate.java +++ b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/Authenticate.java @@ -35,6 +35,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.lang3.RandomUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.runtime.RuntimeConstants; import org.joda.time.DateTime; @@ -52,6 +53,8 @@ import org.opensaml.saml2.core.NameID; import org.opensaml.saml2.core.NameIDPolicy; import org.opensaml.saml2.core.NameIDType; import org.opensaml.saml2.core.RequestedAuthnContext; +import org.opensaml.saml2.core.RequesterID; +import org.opensaml.saml2.core.Scoping; import org.opensaml.saml2.metadata.EntityDescriptor; import org.opensaml.saml2.metadata.SingleSignOnService; import org.opensaml.saml2.metadata.impl.SingleSignOnServiceBuilder; @@ -136,11 +139,12 @@ public class Authenticate extends HttpServlet { issuer.setFormat(NameIDType.ENTITY); authReq.setIssuer(issuer); - NameIDPolicy policy = SAML2Utils - .createSAMLObject(NameIDPolicy.class); - policy.setAllowCreate(true); - policy.setFormat(NameID.PERSISTENT); - authReq.setNameIDPolicy(policy); + if (config.setNameIdPolicy()) { + NameIDPolicy policy = SAML2Utils.createSAMLObject(NameIDPolicy.class); + policy.setAllowCreate(true); + policy.setFormat(NameID.PERSISTENT); + authReq.setNameIDPolicy(policy); + } String entityname = config.getPVP2IDPMetadataEntityName(); if (MiscUtil.isEmpty(entityname)) { @@ -183,20 +187,26 @@ public class Authenticate extends HttpServlet { //authReq.setDestination("http://test.test.test"); + if (config.setAuthnContextClassRef()) { + RequestedAuthnContext reqAuthContext = + SAML2Utils.createSAMLObject(RequestedAuthnContext.class); + AuthnContextClassRef authnClassRef = + SAML2Utils.createSAMLObject(AuthnContextClassRef.class); + authnClassRef.setAuthnContextClassRef("http://www.stork.gov.eu/1.0/citizenQAALevel/4"); + reqAuthContext.setComparison(AuthnContextComparisonTypeEnumeration.MINIMUM); + reqAuthContext.getAuthnContextClassRefs().add(authnClassRef); + authReq.setRequestedAuthnContext(reqAuthContext); + } - RequestedAuthnContext reqAuthContext = - SAML2Utils.createSAMLObject(RequestedAuthnContext.class); - - AuthnContextClassRef authnClassRef = - SAML2Utils.createSAMLObject(AuthnContextClassRef.class); - - authnClassRef.setAuthnContextClassRef("http://www.stork.gov.eu/1.0/citizenQAALevel/4"); - - reqAuthContext.setComparison(AuthnContextComparisonTypeEnumeration.MINIMUM); - - reqAuthContext.getAuthnContextClassRefs().add(authnClassRef); + if (StringUtils.isNotEmpty(config.getScopeRequesterId())) { + Scoping scope = SAML2Utils.createSAMLObject(Scoping.class); + RequesterID requesterId = SAML2Utils.createSAMLObject(RequesterID.class); + requesterId.setRequesterID(config.getScopeRequesterId()); + scope.getRequesterIDs().add(requesterId ); + authReq.setScoping(scope ); + + } - authReq.setRequestedAuthnContext(reqAuthContext); //sign authentication request KeyStore keyStore = config.getPVP2KeyStore(); diff --git a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/DemoApplication.java b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/DemoApplication.java index aeb4d8eac..e36a880ba 100644 --- a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/DemoApplication.java +++ b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/DemoApplication.java @@ -198,11 +198,7 @@ public class DemoApplication extends HttpServlet { } - //set assertion - org.w3c.dom.Document doc = SAML2Utils.asDOMDocument(samlResponse); - String assertion = DOMUtils.serializeNode(doc); - bean.setAssertion(assertion); - + if (samlResponse.getStatus().getStatusCode().getValue().equals(StatusCode.SUCCESS_URI)) { List saml2assertions = new ArrayList(); @@ -245,12 +241,28 @@ public class DemoApplication extends HttpServlet { } + samlResponse.getAssertions().clear(); + samlResponse.getAssertions().addAll(saml2assertions); + + //set assertion + org.w3c.dom.Document doc = SAML2Utils.asDOMDocument(samlResponse); + String assertion = DOMUtils.serializeNode(doc); + bean.setAssertion(assertion); + + String principleId = null; String givenName = null; String familyName = null; String birthday = null; for (org.opensaml.saml2.core.Assertion saml2assertion : saml2assertions) { + try { + principleId = saml2assertion.getSubject().getNameID().getValue(); + + } catch (Exception e) { + log.warn("Can not read SubjectNameId", e); + } + //loop through the nodes to get what we want List attributeStatements = saml2assertion.getAttributeStatements(); for (int i = 0; i < attributeStatements.size(); i++) @@ -277,6 +289,7 @@ public class DemoApplication extends HttpServlet { } + bean.setPrincipleId(principleId); bean.setDateOfBirth(birthday); bean.setFamilyName(familyName); bean.setGivenName(givenName); diff --git a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/utils/ApplicationBean.java b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/utils/ApplicationBean.java index 05c253b6e..59090cbcc 100644 --- a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/utils/ApplicationBean.java +++ b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/utils/ApplicationBean.java @@ -32,6 +32,7 @@ public class ApplicationBean implements Serializable { private String givenName; private String dateOfBirth; private String assertion; + private String principleId; private boolean isLogin = false; @@ -122,6 +123,14 @@ public class ApplicationBean implements Serializable { public void setSuccessMessage(String successMessage) { this.successMessage = successMessage; } + + public String getPrincipleId() { + return principleId; + } + public void setPrincipleId(String principleId) { + this.principleId = principleId; + } + diff --git a/id/oa/src/main/webapp/demoapp.jsp b/id/oa/src/main/webapp/demoapp.jsp index c6b005deb..7d511a5ce 100644 --- a/id/oa/src/main/webapp/demoapp.jsp +++ b/id/oa/src/main/webapp/demoapp.jsp @@ -31,7 +31,11 @@
- + + + + + diff --git a/id/oa/src/main/webapp/index.jsp b/id/oa/src/main/webapp/index.jsp index 49f3e3e3a..628d3e7a3 100644 --- a/id/oa/src/main/webapp/index.jsp +++ b/id/oa/src/main/webapp/index.jsp @@ -21,6 +21,8 @@ -- cgit v1.2.3 From b0a0f1baf5a17df00c61d151c03ba3e6f6a99685 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 5 Aug 2019 14:40:23 +0200 Subject: change version structure of project --- id/oa/pom.xml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'id/oa') diff --git a/id/oa/pom.xml b/id/oa/pom.xml index 07b84ed1b..4c5d16571 100644 --- a/id/oa/pom.xml +++ b/id/oa/pom.xml @@ -4,7 +4,7 @@ MOA id - 3.x + 4.0.1-snapshot 4.0.0 @@ -139,6 +139,19 @@ + + org.bouncycastle + bcpkix-jdk15on + 1.62 + test + + + + org.bouncycastle + bcprov-jdk15on + 1.62 + + -- cgit v1.2.3 From 9ac6dded6ec870f6d6ae03dbb43214ef2489e3c3 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 5 Aug 2019 15:21:30 +0200 Subject: update paths to maven repos --- id/oa/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'id/oa') diff --git a/id/oa/pom.xml b/id/oa/pom.xml index 4c5d16571..c57f09a44 100644 --- a/id/oa/pom.xml +++ b/id/oa/pom.xml @@ -22,12 +22,12 @@ shibboleth.internet2.edu Internet2 - https://build.shibboleth.net/nexus/content/groups/public/ + https://apps.egiz.gv.at/shibboleth_nexus/ IAIK Local iaik/libs - http://nexus.iaik.tugraz.at/nexus/content/repositories/iaik/ + https://apps.egiz.gv.at/maven/ -- cgit v1.2.3 From abc2537a4d2e6d6a06b3b24d7268daf379aa949b Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 9 Sep 2019 12:27:09 +0200 Subject: read requested LoA from configuration --- .../java/at/gv/egovernment/moa/id/demoOA/Configuration.java | 5 +++++ .../egovernment/moa/id/demoOA/servlet/pvp2/Authenticate.java | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'id/oa') diff --git a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/Configuration.java b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/Configuration.java index 8ada01cb6..d6c14fd07 100644 --- a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/Configuration.java +++ b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/Configuration.java @@ -187,6 +187,11 @@ public class Configuration { return Boolean.parseBoolean(props.getProperty("general.login.pvp2.req.set.authncontextclassref", "true")); } + public String getAuthnContextClassRefValue() { + return props.getProperty("general.login.pvp2.req.authncontextclassref.value"); + + } + public String getScopeRequesterId() { return props.getProperty("general.login.pvp2.sp.requesterId"); } diff --git a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/Authenticate.java b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/Authenticate.java index 0671b8c14..4e8e12499 100644 --- a/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/Authenticate.java +++ b/id/oa/src/main/java/at/gv/egovernment/moa/id/demoOA/servlet/pvp2/Authenticate.java @@ -191,8 +191,16 @@ public class Authenticate extends HttpServlet { RequestedAuthnContext reqAuthContext = SAML2Utils.createSAMLObject(RequestedAuthnContext.class); AuthnContextClassRef authnClassRef = - SAML2Utils.createSAMLObject(AuthnContextClassRef.class); - authnClassRef.setAuthnContextClassRef("http://www.stork.gov.eu/1.0/citizenQAALevel/4"); + SAML2Utils.createSAMLObject(AuthnContextClassRef.class); + + if (MiscUtil.isNotEmpty(config.getAuthnContextClassRefValue())) { + authnClassRef.setAuthnContextClassRef(config.getAuthnContextClassRefValue()); + + } else { + authnClassRef.setAuthnContextClassRef("http://www.stork.gov.eu/1.0/citizenQAALevel/4"); + + } + reqAuthContext.setComparison(AuthnContextComparisonTypeEnumeration.MINIMUM); reqAuthContext.getAuthnContextClassRefs().add(authnClassRef); authReq.setRequestedAuthnContext(reqAuthContext); -- cgit v1.2.3 From 31e23d3cedeecf980e39b9637237cb8f3d01ad9f Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Wed, 11 Dec 2019 16:08:19 +0100 Subject: change version to 4.1.0 --- id/oa/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'id/oa') diff --git a/id/oa/pom.xml b/id/oa/pom.xml index c57f09a44..29a37f2c4 100644 --- a/id/oa/pom.xml +++ b/id/oa/pom.xml @@ -4,7 +4,7 @@ MOA id - 4.0.1-snapshot + 4.1.0 4.0.0 -- cgit v1.2.3
Benutzerdaten:PrincipleId: <%= bean.getPrincipleId()%>
Benutzerdaten: <%= bean.getGivenName()%>  <%= bean.getFamilyName()%>  <%= bean.getDateOfBirth()%>