save then commit
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / idp / profile / AbstractSAMLProfileHandler.java
index bd0c81a..0e8876d 100644 (file)
@@ -240,6 +240,21 @@ public abstract class AbstractSAMLProfileHandler extends
         supportedOutboundBindings = bindings;
     }
 
+    /** {@inheritDoc} */
+    public RelyingPartyConfiguration getRelyingPartyConfiguration(String relyingPartyId) {
+        try {
+            if (getMetadataProvider().getEntityDescriptor(relyingPartyId) == null) {
+                log.warn("No metadata for relying party {}, treating party as anonymous", relyingPartyId);
+                return getRelyingPartyConfigurationManager().getAnonymousRelyingConfiguration();
+            }
+        } catch (MetadataProviderException e) {
+            log.error("Unable to look up relying party metadata", e);
+            return null;
+        }
+
+        return super.getRelyingPartyConfiguration(relyingPartyId);
+    }
+
     /**
      * Populates the request context with information.
      * 
@@ -275,25 +290,18 @@ public abstract class AbstractSAMLProfileHandler extends
     protected void populateRelyingPartyInformation(BaseSAMLProfileRequestContext requestContext)
             throws ProfileException {
         MetadataProvider metadataProvider = requestContext.getMetadataProvider();
-        String relyingPartyId = requestContext.getPeerEntityId();
+        String relyingPartyId = requestContext.getInboundMessageIssuer();
 
         EntityDescriptor relyingPartyMetadata;
         try {
             relyingPartyMetadata = metadataProvider.getEntityDescriptor(relyingPartyId);
+            requestContext.setPeerEntityMetadata(relyingPartyMetadata);
         } catch (MetadataProviderException e) {
             log.error("Error looking up metadata for relying party " + relyingPartyId, e);
             throw new ProfileException("Error looking up metadata for relying party " + relyingPartyId);
         }
 
-        RelyingPartyConfiguration rpConfig = null;
-        if (relyingPartyMetadata != null) {
-            requestContext.setPeerEntityMetadata(relyingPartyMetadata);
-            rpConfig = getRelyingPartyConfiguration(relyingPartyId);
-        } else {
-            log.warn("No metadata for relying party {}, treating party as anonymous", relyingPartyId);
-            rpConfig = getRelyingPartyConfigurationManager().getAnonymousRelyingConfiguration();
-        }
-
+        RelyingPartyConfiguration rpConfig = getRelyingPartyConfiguration(relyingPartyId);
         if (rpConfig == null) {
             log.error("Unable to retrieve relying party configuration data for entity with ID {}", relyingPartyId);
             throw new ProfileException("Unable to retrieve relying party configuration data for entity with ID "
@@ -368,7 +376,6 @@ public abstract class AbstractSAMLProfileHandler extends
      * @throws ProfileException thrown if there is a problem populating the profile information
      */
     protected void populateProfileInformation(BaseSAMLProfileRequestContext requestContext) throws ProfileException {
-        requestContext.setCommunicationProfileId(getProfileId());
         AbstractSAMLProfileConfiguration profileConfig = (AbstractSAMLProfileConfiguration) requestContext
                 .getRelyingPartyConfiguration().getProfileConfiguration(getProfileId());
         if (profileConfig != null) {
@@ -376,7 +383,12 @@ public abstract class AbstractSAMLProfileHandler extends
             requestContext.setOutboundMessageArtifactType(profileConfig.getOutboundArtifactType());
         }
 
-        requestContext.setPeerEntityEndpoint(selectEndpoint(requestContext));
+        Endpoint endpoint = selectEndpoint(requestContext);
+        if (endpoint == null) {
+            log.error("No return endpoint available for relying party {}", requestContext.getInboundMessageIssuer());
+            throw new ProfileException("No peer endpoint available to which to send SAML response");
+        }
+        requestContext.setPeerEntityEndpoint(endpoint);
     }
 
     /**
@@ -417,15 +429,6 @@ public abstract class AbstractSAMLProfileHandler extends
      */
     protected void encodeResponse(BaseSAMLProfileRequestContext requestContext) throws ProfileException {
         try {
-
-            Endpoint peerEndpoint = requestContext.getPeerEntityEndpoint();
-            if (peerEndpoint == null) {
-                log
-                        .error("No return endpoint available for relying party {}", requestContext
-                                .getInboundMessageIssuer());
-                throw new ProfileException("No peer endpoint available to which to send SAML response");
-            }
-
             SAMLMessageEncoder encoder = getMessageEncoders().get(requestContext.getPeerEntityEndpoint().getBinding());
             if (encoder == null) {
                 log.error("No outbound message encoder configured for binding {}", requestContext