From d6c7784ca84200e177fbeb6cc5f6b7b5666ff95e Mon Sep 17 00:00:00 2001 From: Misagh Moayyed Date: Tue, 12 May 2015 11:14:35 -0700 Subject: [PATCH] initial commit --- .gitignore | 3 + build.xml | 94 ++++++ pom.xml | 271 ++++++++++++++++++ .../profile/logic/AuthnClassPredicate.java | 69 +++++ 4 files changed, 437 insertions(+) create mode 100644 build.xml create mode 100644 pom.xml create mode 100644 src/main/java/net/shibboleth/idp/profile/logic/AuthnClassPredicate.java diff --git a/.gitignore b/.gitignore index 32858aa..5f91013 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +.idea +target/ +*.iml diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..abce644 --- /dev/null +++ b/build.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4f69330 --- /dev/null +++ b/pom.xml @@ -0,0 +1,271 @@ + + + 4.0.0 + + edu.uchicago.identity + shibidp-extensions + 1.0-SNAPSHOT + jar + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.plugin.compiler} + + ${project.build.sourceVersion} + ${project.build.targetVersion} + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven.plugin.jar} + + shib-extensions + + + + + + + + org.opensaml + opensaml-core + ${opensaml.version} + + + org.opensaml + opensaml-messaging-api + ${opensaml.version} + + + org.opensaml + opensaml-messaging-impl + ${opensaml.version} + + + org.opensaml + opensaml-profile-api + ${opensaml.version} + + + org.opensaml + opensaml-profile-impl + ${opensaml.version} + + + org.opensaml + opensaml-saml-api + ${opensaml.version} + + + org.opensaml + opensaml-saml-impl + ${opensaml.version} + + + org.opensaml + opensaml-security-api + ${opensaml.version} + + + org.opensaml + opensaml-security-impl + ${opensaml.version} + + + org.opensaml + opensaml-soap-api + ${opensaml.version} + + + org.opensaml + opensaml-soap-impl + ${opensaml.version} + + + org.opensaml + opensaml-storage-api + ${opensaml.version} + + + org.opensaml + opensaml-storage-impl + ${opensaml.version} + + + org.opensaml + opensaml-xmlsec-api + ${opensaml.version} + + + org.opensaml + opensaml-xmlsec-impl + ${opensaml.version} + + + + net.shibboleth.idp + idp-attribute-api + ${idp.version} + + + net.shibboleth.idp + idp-attribute-filter-api + ${idp.version} + + + net.shibboleth.idp + idp-attribute-filter-impl + ${idp.version} + + + net.shibboleth.idp + idp-attribute-resolver-api + ${idp.version} + + + net.shibboleth.idp + idp-attribute-resolver-impl + ${idp.version} + + + net.shibboleth.idp + idp-attribute-resolver-spring + ${idp.version} + + + net.shibboleth.idp + idp-attribute-filter-spring + ${idp.version} + + + net.shibboleth.idp + idp-authn-api + ${idp.version} + + + net.shibboleth.idp + idp-authn-impl + ${idp.version} + + + net.shibboleth.idp + idp-cas-api + ${idp.version} + + + net.shibboleth.idp + idp-cas-impl + ${idp.version} + + + net.shibboleth.idp + idp-profile-api + ${idp.version} + + + net.shibboleth.idp + idp-profile-impl + ${idp.version} + + + net.shibboleth.idp + idp-profile-spring + ${idp.version} + + + net.shibboleth.idp + idp-saml-api + ${idp.version} + + + net.shibboleth.idp + idp-saml-impl + ${idp.version} + + + net.shibboleth.idp + idp-session-api + ${idp.version} + + + net.shibboleth.idp + idp-session-impl + ${idp.version} + + + net.shibboleth.idp + idp-ui + ${idp.version} + + + net.shibboleth.idp + idp-core + ${idp.version} + + + net.shibboleth.idp + idp-consent + ${idp.version} + + + net.shibboleth.idp + idp-schema + ${idp.version} + + + + com.google.guava + guava + ${guava.version} + + + + + 3.1.1 + 18.0 + 3.1.1 + 2.6 + 3.3 + 1.8 + 1.8 + + + + + shib-release + https://build.shibboleth.net/nexus/content/groups/public + + false + + + true + + + + shib-snapshot + https://build.shibboleth.net/nexus/content/repositories/snapshots + + false + + + true + + + + central + http://repo1.maven.org/maven2 + + false + + + false + + + + diff --git a/src/main/java/net/shibboleth/idp/profile/logic/AuthnClassPredicate.java b/src/main/java/net/shibboleth/idp/profile/logic/AuthnClassPredicate.java new file mode 100644 index 0000000..769d149 --- /dev/null +++ b/src/main/java/net/shibboleth/idp/profile/logic/AuthnClassPredicate.java @@ -0,0 +1,69 @@ +package net.shibboleth.idp.profile.logic; + +import net.shibboleth.idp.authn.context.AuthenticationContext; +import net.shibboleth.idp.authn.context.RequestedPrincipalContext; +import org.opensaml.profile.context.ProfileRequestContext; +import com.google.common.base.Predicate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.security.Principal; +import java.util.Arrays; +import java.util.Set; + +/** + * @author Misagh Moayyed + */ +public final class AuthnClassPredicate implements Predicate { + private final Logger log = LoggerFactory.getLogger(AuthnClassPredicate.class); + + private Set authnClassesToMatch; + + private Predicate predicateToDelegate; + + public AuthnClassPredicate(Set authnClassesToMatch, Predicate predicateToDelegate) { + this.authnClassesToMatch = authnClassesToMatch; + this.predicateToDelegate = predicateToDelegate; + } + + @Override + public boolean apply(ProfileRequestContext profileRequestContext) { + log.debug("Evaluating profile request context for authn class..."); + + log.debug("Getting authn context from the profile request context..."); + final AuthenticationContext authnContext = profileRequestContext.getSubcontext(AuthenticationContext.class); + + log.debug("Getting requested principal from the authn context..."); + final RequestedPrincipalContext principalContext = authnContext.getSubcontext(RequestedPrincipalContext.class); + + if (principalContext == null) { + log.debug("No principal context was requested. predicate wil ignore the context"); + return true; + } + + log.debug("Getting matching principal from the principal context..."); + final Principal principal = principalContext.getMatchingPrincipal(); + final String principalName = principal.getName(); + log.debug("Matching principal name is {}", principalName); + + if (this.authnClassesToMatch.contains(principalName)) { + log.debug("Found matching principal name {} for the requested authn class. Calling delegate...", + principalName); + + boolean delegateResult = this.predicateToDelegate.apply(profileRequestContext); + if (delegateResult) { + log.debug("Delegate {} returned true. Moving on...", this.predicateToDelegate.getClass().getSimpleName()); + return true; + } else { + log.debug("Delegate could not evaluate the context. Failing..."); + return false; + } + + } + log.debug("Could not match the requested authn principal {} against {}", + principalName, Arrays.toString(this.authnClassesToMatch.toArray())); + return false; + } + + +}