Commit 29318f3b authored by Misagh Moayyed's avatar Misagh Moayyed
Browse files

fixed test case

parent 442f492b
......@@ -37,6 +37,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import javax.servlet.ServletContextEvent;
import javax.servlet.annotation.WebListener;
......@@ -112,8 +113,10 @@ public class SamlServletContextListener extends AbstractServletContextInitialize
}
final PrivateKeyFactoryBean bean = new PrivateKeyFactoryBean();
bean.setLocation(new FileSystemResource(this.publicKeyLocation));
bean.setLocation(new FileSystemResource(ResourceUtils.getFile(this.privateKeyLocation).getCanonicalPath()));
bean.setAlgorithm(this.keyAlgorithm);
bean.afterPropertiesSet();
logger.debug("Creating Google Apps private key instance via {}", this.publicKeyLocation);
return bean.getObject();
}
......@@ -126,8 +129,9 @@ public class SamlServletContextListener extends AbstractServletContextInitialize
}
final PublicKeyFactoryBean bean = new PublicKeyFactoryBean();
bean.setLocation(new FileSystemResource(this.publicKeyLocation));
bean.setLocation(new FileSystemResource(ResourceUtils.getFile(this.publicKeyLocation).getCanonicalPath()));
bean.setAlgorithm(this.keyAlgorithm);
bean.afterPropertiesSet();
logger.debug("Creating Google Apps public key instance via {}", this.publicKeyLocation);
return bean.getObject();
......
......@@ -24,29 +24,21 @@ import org.jdom.Document;
import org.jdom.input.DOMBuilder;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.SAMLObjectBuilder;
import org.opensaml.saml.common.xml.SAMLConstants;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.io.Marshaller;
import org.opensaml.core.xml.io.MarshallerFactory;
import org.opensaml.core.xml.schema.XSString;
import org.opensaml.core.xml.schema.impl.XSStringBuilder;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.SAMLObjectBuilder;
import org.opensaml.saml.common.xml.SAMLConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import javax.xml.crypto.dsig.CanonicalizationMethod;
import javax.xml.crypto.dsig.DigestMethod;
import javax.xml.crypto.dsig.Reference;
import javax.xml.crypto.dsig.SignatureMethod;
import javax.xml.crypto.dsig.SignedInfo;
import javax.xml.crypto.dsig.Transform;
import javax.xml.crypto.dsig.XMLSignature;
import javax.xml.crypto.dsig.XMLSignatureFactory;
import javax.xml.crypto.dsig.*;
import javax.xml.crypto.dsig.dom.DOMSignContext;
import javax.xml.crypto.dsig.keyinfo.KeyInfo;
import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
......@@ -68,8 +60,6 @@ import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.interfaces.DSAPublicKey;
import java.security.interfaces.RSAPublicKey;
import java.util.Collections;
import java.util.List;
/**
......@@ -278,14 +268,18 @@ public abstract class AbstractSamlObjectBuilder {
// Create the SignatureMethod based on the type of key
final SignatureMethod signatureMethod;
if (pubKey instanceof DSAPublicKey) {
signatureMethod = sigFactory.newSignatureMethod(
SignatureMethod.DSA_SHA1, null);
} else if (pubKey instanceof RSAPublicKey) {
signatureMethod = sigFactory.newSignatureMethod(
SignatureMethod.RSA_SHA1, null);
} else {
throw new RuntimeException("Error signing SAML element: Unsupported type of key");
final String algorithm = pubKey.getAlgorithm();
switch (algorithm) {
case "DSA":
signatureMethod = sigFactory.newSignatureMethod(
SignatureMethod.DSA_SHA1, null);
break;
case "RSA":
signatureMethod = sigFactory.newSignatureMethod(
SignatureMethod.RSA_SHA1, null);
break;
default:
throw new RuntimeException("Error signing SAML element: Unsupported type of key");
}
final CanonicalizationMethod canonicalizationMethod = sigFactory
......
......@@ -35,6 +35,6 @@ cas.saml.ticketid.saml2=false
##
# Google Apps public/private key
#
cas.saml.googleapps.publickey.file=classpath:DSAPrivateKey01.key
cas.saml.googleapps.publickey.file=classpath:DSAPublicKey01.key
cas.saml.googleapps.privatekey.file=classpath:DSAPrivateKey01.key
cas.saml.googleapps.key.alg=DSA
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment