List of usage examples for java.lang ClassLoader getClassLoader
static ClassLoader getClassLoader(Class<?> caller)
From source file:com.eviware.soapui.impl.wsdl.support.wss.crypto.KeyMaterialWssCrypto.java
public KeyStore load() throws Exception { if (keyStore != null) return keyStore; try {/* ww w. j a v a 2 s .c o m*/ UISupport.setHourglassCursor(); String crypotFilePath = sourceProperty.expand(); String fileExtension = Files.getFileExtension(crypotFilePath); String keystoreType = fileExtensionToKeystoreType(fileExtension); ClassLoader loader = Loader.getClassLoader(KeyMaterialWssCrypto.class); InputStream input = Merlin.loadInputStream(loader, crypotFilePath); keyStore = KeyStore.getInstance(keystoreType); keyStore.load(input, getPassword().toCharArray()); return keyStore; } catch (Exception exceptionFromNormalLoad) { log.warn("Using fallback method to load keystore/truststore due to: " + exceptionFromNormalLoad.getMessage()); try { keyStore = fallbackLoad(); return keyStore; } catch (Exception exceptionFromFallbackLoad) { keyStore = null; SoapUI.logError(exceptionFromFallbackLoad, "Could not load keystore/truststore"); throw new Exception(exceptionFromFallbackLoad); } } finally { UISupport.resetCursor(); } }
From source file:org.apache.ws.security.message.SignaturePartsTest.java
/** * Test signing of a header through a STR Dereference Transform *///from w ww . java2 s . c o m @SuppressWarnings("unchecked") @org.junit.Test public void testSOAPHeaderSTRTransform() throws Exception { // Construct issuer and user crypto instances Crypto issuerCrypto = new Merlin(); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); ClassLoader loader = Loader.getClassLoader(SignedSamlTokenHOKTest.class); InputStream input = Merlin.loadInputStream(loader, "keys/wss40_server.jks"); keyStore.load(input, "security".toCharArray()); ((Merlin) issuerCrypto).setKeyStore(keyStore); Crypto userCrypto = CryptoFactory.getInstance("wss40.properties"); SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler(); callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN); callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY); SAMLIssuer saml = new SAMLIssuerImpl(); saml.setIssuerName("www.example.com"); saml.setIssuerCrypto(issuerCrypto); saml.setIssuerKeyName("wss40_server"); saml.setIssuerKeyPassword("security"); saml.setSignAssertion(true); saml.setCallbackHandler(callbackHandler); AssertionWrapper assertion = saml.newAssertion(); WSSecSignatureSAML wsSign = new WSSecSignatureSAML(); wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); wsSign.setUserInfo("wss40", "security"); Document doc = SOAPUtil.toSOAPPart(SOAPMSG); WSSecHeader secHeader = new WSSecHeader(); secHeader.insertSecurityHeader(doc); List<WSEncryptionPart> parts = new ArrayList<WSEncryptionPart>(); WSEncryptionPart encP = new WSEncryptionPart("STRTransform", "", "Element"); parts.add(encP); wsSign.setParts(parts); // // set up for keyHolder // Document signedDoc = wsSign.build(doc, userCrypto, assertion, null, null, null, secHeader); if (LOG.isDebugEnabled()) { LOG.debug("Signed SAML message (key holder):"); String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc); LOG.debug(outputString); } // Construct trust crypto instance Crypto trustCrypto = new Merlin(); KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); input = Merlin.loadInputStream(loader, "keys/wss40CA.jks"); trustStore.load(input, "security".toCharArray()); ((Merlin) trustCrypto).setTrustStore(trustStore); List<WSSecurityEngineResult> results = secEngine.processSecurityHeader(doc, null, null, trustCrypto); WSSecurityEngineResult stUnsignedActionResult = WSSecurityUtil.fetchActionResult(results, WSConstants.ST_SIGNED); AssertionWrapper receivedAssertion = (AssertionWrapper) stUnsignedActionResult .get(WSSecurityEngineResult.TAG_SAML_ASSERTION); assertTrue(receivedAssertion != null); assertTrue(receivedAssertion.isSigned()); WSSecurityEngineResult signActionResult = WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN); assertTrue(signActionResult != null); assertFalse(signActionResult.isEmpty()); final List<WSDataRef> refs = (List<WSDataRef>) signActionResult .get(WSSecurityEngineResult.TAG_DATA_REF_URIS); WSDataRef wsDataRef = (WSDataRef) refs.get(0); String xpath = wsDataRef.getXpath(); assertEquals("/soapenv:Envelope/soapenv:Header/wsse:Security/saml1:Assertion", xpath); }
From source file:org.apache.ws.security.saml.SamlNegativeTest.java
public SamlNegativeTest() throws Exception { WSSConfig.init();//from ww w . jav a 2 s . co m // Load the issuer keystore issuerCrypto = new Merlin(); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); ClassLoader loader = Loader.getClassLoader(SamlNegativeTest.class); InputStream input = Merlin.loadInputStream(loader, "keys/wss40_server.jks"); keyStore.load(input, "security".toCharArray()); ((Merlin) issuerCrypto).setKeyStore(keyStore); // Load the server truststore trustCrypto = new Merlin(); KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); input = Merlin.loadInputStream(loader, "keys/wss40CA.jks"); trustStore.load(input, "security".toCharArray()); ((Merlin) trustCrypto).setTrustStore(trustStore); }
From source file:org.apache.ws.security.saml.SamlReferenceTest.java
public SamlReferenceTest() throws Exception { WSSConfig.init();/*from w ww .j a v a 2 s. com*/ // Load the issuer keystore issuerCrypto = new Merlin(); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); ClassLoader loader = Loader.getClassLoader(SignedSamlTokenHOKTest.class); InputStream input = Merlin.loadInputStream(loader, "keys/wss40_server.jks"); keyStore.load(input, "security".toCharArray()); ((Merlin) issuerCrypto).setKeyStore(keyStore); // Load the server truststore trustCrypto = new Merlin(); KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); input = Merlin.loadInputStream(loader, "keys/wss40CA.jks"); trustStore.load(input, "security".toCharArray()); ((Merlin) trustCrypto).setTrustStore(trustStore); }
From source file:org.apache.ws.security.saml.SignedSamlTokenHOKTest.java
public SignedSamlTokenHOKTest() throws Exception { WSSConfig.init();/*from w w w . j a v a2 s.c om*/ // Load the issuer keystore issuerCrypto = new Merlin(); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); ClassLoader loader = Loader.getClassLoader(SignedSamlTokenHOKTest.class); InputStream input = Merlin.loadInputStream(loader, "keys/wss40_server.jks"); keyStore.load(input, "security".toCharArray()); ((Merlin) issuerCrypto).setKeyStore(keyStore); // Load the server truststore trustCrypto = new Merlin(); KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); input = Merlin.loadInputStream(loader, "keys/wss40CA.jks"); trustStore.load(input, "security".toCharArray()); ((Merlin) trustCrypto).setTrustStore(trustStore); }