[java-identity-provider COMMIT] in /trunk: idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthnEventIds.java id...

noreply at shibboleth.net noreply at shibboleth.net
Mon Jan 27 12:26:29 EST 2014


Author: scantor
Date: Mon Jan 27 12:26:29 2014
New Revision: 5245

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=5245&view=rev
Log:
Rework error handling and pre-checking of Simple c14n flow

Modified:
    trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthnEventIds.java
    trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/SimpleSubjectCanonicalization.java
    trunk/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/SimpleSubjectCanonicalizationTest.java
    trunk/idp-conf/src/main/resources/system/flows/c14n/subject-c14n-abstract-flow.xml

Modified: trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthnEventIds.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthnEventIds.java?rev=5245&r1=5244&r2=5245&view=diff
==============================================================================
--- trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthnEventIds.java (original)
+++ trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthnEventIds.java Mon Jan 27 12:26:29 2014
@@ -55,8 +55,11 @@
      * is missing or invalid.
      */
     public static final String INVALID_SUBJECT_C14N_CTX = "InvalidSubjectCanonicalizationContext";
-    
+
     /** ID of event returned if a Subject cannot be canonicalized. */
+    public static final String INVALID_SUBJECT = "InvalidSubject";
+
+    /** ID of event returned if an error occurs canonicalizing a Subject. */
     public static final String SUBJECT_C14N_ERROR = "SubjectCanonicalizationError";
     
     /** ID of event returned if authentication throws an exception unrelated to credential validation. */

Modified: trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/SimpleSubjectCanonicalization.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/SimpleSubjectCanonicalization.java?rev=5245&r1=5244&r2=5245&view=diff
==============================================================================
--- trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/SimpleSubjectCanonicalization.java (original)
+++ trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/SimpleSubjectCanonicalization.java Mon Jan 27 12:26:29 2014
@@ -46,35 +46,29 @@
  *  || SubjectCanonicalizationContext.getException() != null</pre>
  */
 public class SimpleSubjectCanonicalization extends AbstractSubjectCanonicalizationAction {
+
+    /** Supplies logic for pre-execute test. */
+    @Nonnull private final ActivationCondition embeddedPredicate;
     
     /** The custom Principal to operate on. */
     @Nullable private UsernamePrincipal usernamePrincipal;
+    
+    /** Constructor. */
+    public SimpleSubjectCanonicalization() {
+        embeddedPredicate = new ActivationCondition();
+    }
     
     /** {@inheritDoc} */
     @Override
     protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext, 
             @Nonnull final SubjectCanonicalizationContext c14nContext) throws SubjectCanonicalizationException {
-        
-        final Set<UsernamePrincipal> usernames;
-        if (c14nContext.getSubject() != null) {
-            usernames = c14nContext.getSubject().getPrincipals(UsernamePrincipal.class);
-        } else {
-            usernames = null;
+
+        if (embeddedPredicate.apply(profileRequestContext, c14nContext, true)) {
+            usernamePrincipal = c14nContext.getSubject().getPrincipals(UsernamePrincipal.class).iterator().next();
+            return super.doPreExecute(profileRequestContext, c14nContext);
         }
         
-        if (usernames == null || usernames.isEmpty()) {
-            c14nContext.setException(new SubjectCanonicalizationException("No UsernamePrincipals were found"));
-            ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.SUBJECT_C14N_ERROR);
-            return false;
-        } else if (usernames.size() > 1) {
-            c14nContext.setException(new SubjectCanonicalizationException("Multiple UsernamePrincipals were found"));
-            ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.SUBJECT_C14N_ERROR);
-            return false;
-        }
-        
-        usernamePrincipal = usernames.iterator().next();
-        
-        return super.doPreExecute(profileRequestContext, c14nContext);
+        return false;
     }
     
     /** {@inheritDoc} */
@@ -95,15 +89,52 @@
             if (input != null) {
                 final SubjectCanonicalizationContext c14nContext =
                         input.getSubcontext(SubjectCanonicalizationContext.class, false);
-                if (c14nContext != null || c14nContext.getSubject() != null) {
-                    final Set<UsernamePrincipal> usernames =
-                            c14nContext.getSubject().getPrincipals(UsernamePrincipal.class);
-                    return usernames != null && usernames.size() == 1;
+                if (c14nContext != null) {

[... 95 lines stripped ...]


More information about the commits mailing list