/**
 * SamlIdpSoapBindingImpl.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
 */

package axiom.soap;

import java.io.File;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;

import org.apache.axis.MessageContext;
import org.apache.axis.transport.http.HTTPConstants;
import org.apache.log4j.Logger;
import org.opensaml.xml.util.Base64;

import axiom.saml.idp.IdentityProvider;
import axiom.saml.idp.IdpConfiguation;
import axiom.saml.idp.XmlObjectSerializer;



public class SamlIdpSoapBindingImpl implements axiom.soap.SamlIdp{
	
	private static Logger logger = Logger.getLogger(SamlIdpSoapBindingImpl.class);
	
    public java.lang.String generateSamlResponse(axiom.soap.AxiomSamlRequest axiomSamlRequest) throws java.rmi.RemoteException {
		
    	logger.debug("entering SOAP-based generateSamlResponse implementation");
    	
    	IdpConfiguation idpConfig = new IdpConfiguation();
			
    		logger.debug("Getting servlet context");
    		HttpServlet servlet = (HttpServlet)MessageContext.getCurrentContext().getProperty(HTTPConstants.MC_HTTP_SERVLET);
    		ServletConfig servletConfig = servlet.getServletConfig();
    		ServletContext servletContext = servletConfig.getServletContext();
    	
    		logger.debug("configuring keystore");
    		String keystoreFile = servletContext.getInitParameter("keystoreFile");
			if(keystoreFile != null && !keystoreFile.equals("")){
				idpConfig.setKeystoreFile(new File(servletContext.getRealPath("/") + keystoreFile));
			}
			idpConfig.setKeystoreAlias(servletContext.getInitParameter("keystoreAlias"));
			idpConfig.setKeystorePassword(servletContext.getInitParameter("keystorePassword").toCharArray());
			idpConfig.setKeystoreAliasPassword(servletContext.getInitParameter("keystoreAliasPassword").toCharArray());
    	
			logger.debug("configuring idp with request from SOAP API");
    		idpConfig.setSamlVersion(axiom.saml.idp.SamlVersion.valueOf(axiomSamlRequest.getSamlVersion().getValue()));
    		idpConfig.setIssuer(axiomSamlRequest.getIssuer());
    		idpConfig.setRecipient(axiomSamlRequest.getRecipient());
    		idpConfig.setUserId(axiomSamlRequest.getUserId());
    		idpConfig.setSamlUserIdLocation(axiom.saml.idp.SamlUserIdLocation.valueOf(axiomSamlRequest.getSamlUserIdLocation().getValue()));
    		idpConfig.setAttributeName(axiomSamlRequest.getAttributeName());
    		idpConfig.setAttributeUri(axiomSamlRequest.getAttributeUri());
    		
  
    	logger.debug("Calling IdP to create SAML response");
		String rawSamlResponse = XmlObjectSerializer.xmlObjectToString(new IdentityProvider(idpConfig).generateSamlResponse());
				
		if(axiomSamlRequest.getBase64EncodeResponse() != null && axiomSamlRequest.getBase64EncodeResponse()==false){
			logger.debug("Returning plain text SAMLResponse via SOAP");
			return rawSamlResponse;
		} else {
			logger.debug("Returning Base 64 encoded SAMLResponse via SOAP");
			return Base64.encodeBytes(rawSamlResponse.getBytes());
		}
		
    }

}

@@ -319,16 +319,132 @@
 ervlet;%0D
+%0Aimport javax.xml.transform.TransformerException;%0D%0Aimport javax.xml.transform.TransformerFactoryConfigurationError;%0D
 %0A%0D%0Aimpor
@@ -561,24 +561,74 @@
 4j.Logger;%0D%0A
+import org.opensaml.xml.io.MarshallingException;%0D%0A
 import org.o
@@ -2852,16 +2852,53 @@
 sponse =
+ null;%0D%0A%09%09try %7B%0D%0A%09%09%09rawSamlResponse =
  XmlObje
@@ -2986,16 +2986,256 @@
 se());%0D%0A
+%09%09%7D catch (MarshallingException e) %7B%0D%0A%09%09%09throw new RuntimeException(e);%0D%0A%09%09%7D catch (TransformerFactoryConfigurationError e) %7B%0D%0A%09%09%09throw new RuntimeException(e);%0D%0A%09%09%7D catch (TransformerException e) %7B%0D%0A%09%09%09throw new RuntimeException(e);%0D%0A%09%09%7D%0D%0A
 %09%09%09%09%0D%0A%09%09

throw new RuntimeException(e) for SOAP errors....temp solution