Java Code Examples for java.security.KeyException#getMessage()

The following examples show how to use java.security.KeyException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignatureVerifier.java    From IDES-Data-Preparation-Java with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, 
		AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException {
	if (keyInfo == null)
		throw new KeySelectorException("Null KeyInfo");
	List<?> list = keyInfo.getContent();
	PublicKey pk = null;

	for (int i = 0; i < list.size(); i++) {
		XMLStructure xmlStructure = (XMLStructure) list.get(i);
		if (xmlStructure instanceof KeyValue) {
			try {
				pk = ((KeyValue)xmlStructure).getPublicKey();
			} catch(KeyException ke) {
				throw new KeySelectorException(ke.getMessage());
			}
			break;
		} else if (xmlStructure instanceof X509Data) {
			X509Data x509data = (X509Data)xmlStructure;
			List<?> x509datalist = x509data.getContent();
			for (int j = 0; j < x509datalist.size(); j++) {
				if (x509datalist.get(j) instanceof X509Certificate) {
					X509Certificate cert = (X509Certificate)x509datalist.get(j);
					pk = cert.getPublicKey();
					break;
				}
			}
		}
	}
	if (pk != null) {
		final PublicKey retpk = pk;
		logger.debug("PublicKey from XML=" + pk);
		return new KeySelectorResult() {public Key getKey(){return retpk;}};
	}
	throw new KeySelectorException("Missing KeyValue");
}
 
Example 2
Source File: SmartProxyImpl.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void init(ConnectionInfo connectionInfo) throws SchedulerException, LoginException {
    this.connectionInfo = connectionInfo;
    if (connectionInfo.getCredentialFile() != null) {
        try {
            Credentials credentials = Credentials.getCredentials(connectionInfo.getCredentialFile()
                                                                               .getAbsolutePath());
            init(connectionInfo.getUrl(), credentials);
        } catch (KeyException e) {
            throw new LoginException(e.getMessage());
        }
    } else {
        CredData cred = new CredData(CredData.parseLogin(connectionInfo.getLogin()),
                                     CredData.parseDomain(connectionInfo.getLogin()),
                                     connectionInfo.getPassword());
        init(connectionInfo.getUrl(), cred);
    }
}
 
Example 3
Source File: SignatureVerifier.java    From IDES-Data-Preparation-Java with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
protected void setSigPublicKeyFromXml(String xml, DocumentBuilder docBuilderNSTrue) throws Exception {
	xml = sigStartElemToWrapXml + xml + sigEndElemToWrapXml;
       Document doc = docBuilderNSTrue.parse(new InputSource(new StringReader(xml)));
       DOMStructure ds = new DOMStructure(doc.getDocumentElement().getFirstChild());
       KeyInfo keyInfo = KeyInfoFactory.getInstance().unmarshalKeyInfo(ds);
	List<?> list = keyInfo.getContent();
	for (int i = 0; i < list.size(); i++) {
		XMLStructure xmlStructure = (XMLStructure) list.get(i);
		if (xmlStructure instanceof KeyValue) {
			try {
				sigPublicKey = ((KeyValue)xmlStructure).getPublicKey();
			} catch(KeyException ke) {
				throw new KeySelectorException(ke.getMessage());
			}
			break;
		} else if (xmlStructure instanceof X509Data) {
			X509Data x509data = (X509Data)xmlStructure;
			List<?> x509datalist = x509data.getContent();
			for (int j = 0; j < x509datalist.size(); j++) {
				if (x509datalist.get(j) instanceof X509Certificate) {
					X509Certificate cert = (X509Certificate)x509datalist.get(j);
					sigPublicKey = cert.getPublicKey();
					break;
				}
			}
		}
	}
}
 
Example 4
Source File: SchedulerFrontend.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
@ImmediateService
public void putThirdPartyCredential(String key, String value) throws NotConnectedException, PermissionException {
    UserIdentificationImpl ident = frontendState.checkPermission("putThirdPartyCredential",
                                                                 YOU_DO_NOT_HAVE_PERMISSION_TO_PUT_THIRD_PARTY_CREDENTIALS_IN_THE_SCHEDULER);

    HybridEncryptionUtil.HybridEncryptedData encryptedData = null;
    try {
        encryptedData = HybridEncryptionUtil.encryptString(value, corePublicKey);
    } catch (KeyException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    dbManager.putThirdPartyCredential(ident.getUsername(), key, encryptedData);
}
 
Example 5
Source File: KeyExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test for <code>KeyException(Throwable)</code> constructor Assertion:
 * constructs KeyException when <code>cause</code> is not null
 */
public void testKeyException05() {
    KeyException tE = new KeyException(tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        assertTrue("getMessage() should contain ".concat(toS), (getM
                .indexOf(toS) != -1));
    }
    assertNotNull("getCause() must not return null", tE.getCause());
    assertEquals("getCause() must return ".concat(tCause.toString()), tE
            .getCause(), tCause);
}
 
Example 6
Source File: KeyExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test for <code>KeyException(String, Throwable)</code> constructor
 * Assertion: constructs KeyException when <code>cause</code> is not null
 * <code>msg</code> is null
 */
public void testKeyException08() {
    KeyException tE = new KeyException(null, tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        assertTrue("getMessage() must should ".concat(toS), (getM
                .indexOf(toS) != -1));
    }
    assertNotNull("getCause() must not return null", tE.getCause());
    assertEquals("getCause() must return ".concat(tCause.toString()), tE
            .getCause(), tCause);
}