@Test public void test_add_certs_keys_only() throws Exception { config.setKeys(EMPTY_MAP); config.addAndActivateKey("cert-only", new SamlKey(null, null, certificate1)); JKSKeyManager manager1 = (JKSKeyManager) SamlKeyManagerFactory.getKeyManager(config); assertNotNull(manager1.getDefaultCredential().getPublicKey()); assertNull(manager1.getDefaultCredential().getPrivateKey()); }
/** * Get the key contained within the credential. * * @param credential the credential containing a key * @return the key from the credential */ private Key getKey(Credential credential) { if (credential.getPublicKey() != null) { return credential.getPublicKey(); } else if (credential.getSecretKey() != null) { return credential.getSecretKey(); } else if (credential.getPrivateKey() != null) { // There should have been a corresponding public key, but just in case... return credential.getPrivateKey(); } else { return null; } }
/** * Determine whether the credential is a local credential. * * A local credential will have either a private key or a secret (symmetric) key. * * @param credential the credential to evaluate * @return true if the credential has either a private or secret key, false otherwise */ protected boolean isLocalCredential(Credential credential) { return credential.getPrivateKey() != null || credential.getSecretKey() != null; }
/** * Extract the verification key from the credential. * * @param credential the credential containing the verification key * @return the verification key (either a public key or a secret (symmetric) key */ public static Key extractVerificationKey(Credential credential) { if (credential == null) { return null; } if (credential.getPublicKey() != null) { return credential.getPublicKey(); } else { return credential.getSecretKey(); } }
/** {@inheritDoc} */ public Boolean evaluate(Credential target) { if (target == null) { log.error("Credential target was null"); return null; } PublicKey key = target.getPublicKey(); if (key == null) { log.info("Credential contained no public key, does not satisfy public key criteria"); return Boolean.FALSE; } Boolean result = publicKey.equals(key); return result; }
protected KeyInfo getServerKeyInfo(String alias) { Credential serverCredential = keyManager.getCredential(alias); if (serverCredential == null) { throw new RuntimeException("Key for alias " + alias + " not found"); } else if (serverCredential.getPrivateKey() == null) { throw new RuntimeException("Key with alias " + alias + " doesn't have a private key"); } return generateKeyInfoForCredential(serverCredential); }
/** {@inheritDoc} */ public Boolean evaluate(Credential target) { if (target == null) { log.error("Credential target was null"); return null; } if (DatatypeHelper.isEmpty(target.getEntityId())) { log.info("Could not evaluate criteria, credential contained no entity ID"); return null; } Boolean result = entityID.equals(target.getEntityId()); return result; }
/** * Get the factory which produces KeyInfoGenerators which can handle * the specified credential. * * @param credential the credential for which to locate a factory * @return a KeyInfoGeneratorFactory instance appropriate for the credential */ public KeyInfoGeneratorFactory getFactory(Credential credential) { return factories.get(credential.getCredentialType()); }
/** {@inheritDoc} */ public Boolean evaluate(Credential target) { if (target == null) { log.error("Credential target was null"); return null; } if (target.getKeyNames().isEmpty()) { log.info("Could not evaluate criteria, credential contained no key names"); return null; } Boolean result = target.getKeyNames().contains(keyName); return result; }
/** {@inheritDoc} */ public Boolean evaluate(Credential target) { if (target == null) { log.error("Credential target was null"); return null; } UsageType credUsage = target.getUsageType(); if (credUsage == null) { log.info("Could not evaluate criteria, credential contained no usage specifier"); return null; } Boolean result = matchUsage(credUsage, usage); return result; }
/** * Get the key contained within the credential. * * @param credential the credential containing a key * @return the key from the credential */ private Key getKey(Credential credential) { if (credential.getPublicKey() != null) { return credential.getPublicKey(); } else if (credential.getSecretKey() != null) { return credential.getSecretKey(); } else if (credential.getPrivateKey() != null) { // There should have been a corresponding public key, but just in case... return credential.getPrivateKey(); } else { return null; } }
/** * Determine whether the credential is a local credential. * * A local credential will have either a private key or a secret (symmetric) key. * * @param credential the credential to evaluate * @return true if the credential has either a private or secret key, false otherwise */ protected boolean isLocalCredential(Credential credential) { return credential.getPrivateKey() != null || credential.getSecretKey() != null; }
/** * Extract the encryption key from the credential. * * @param credential the credential containing the encryption key * @return the encryption key (either a public key or a secret (symmetric) key */ public static Key extractEncryptionKey(Credential credential) { if (credential == null) { return null; } if (credential.getPublicKey() != null) { return credential.getPublicKey(); } else { return credential.getSecretKey(); } }
/** {@inheritDoc} */ public Boolean evaluate(Credential target) { if (target == null) { log.error("Credential target was null"); return null; } PublicKey key = target.getPublicKey(); if (key == null) { log.info("Credential contained no public key, does not satisfy public key criteria"); return Boolean.FALSE; } Boolean result = publicKey.equals(key); return result; }
/** * Gets the credential that should be used for sign a message. Credential <strong>MUST</strong> include a private * key. * * @param credential credential that should be used for sign a message */ public void setSigningCredential(Credential credential) { if (credential != null && credential.getPrivateKey() == null) { throw new IllegalArgumentException("Credential does not contain a private key"); } signingCredential = credential; }
/** {@inheritDoc} */ public Boolean evaluate(Credential target) { if (target == null) { log.error("Credential target was null"); return null; } if (DatatypeHelper.isEmpty(target.getEntityId())) { log.info("Could not evaluate criteria, credential contained no entity ID"); return null; } Boolean result = entityID.equals(target.getEntityId()); return result; }
/** * Get the factory which produces KeyInfoGenerators which can handle * the specified credential. * * @param credential the credential for which to locate a factory * @return a KeyInfoGeneratorFactory instance appropriate for the credential */ public KeyInfoGeneratorFactory getFactory(Credential credential) { return factories.get(credential.getCredentialType()); }
/** {@inheritDoc} */ public Boolean evaluate(Credential target) { if (target == null) { log.error("Credential target was null"); return null; } if (target.getKeyNames().isEmpty()) { log.info("Could not evaluate criteria, credential contained no key names"); return null; } Boolean result = target.getKeyNames().contains(keyName); return result; }
/** {@inheritDoc} */ public Boolean evaluate(Credential target) { if (target == null) { log.error("Credential target was null"); return null; } UsageType credUsage = target.getUsageType(); if (credUsage == null) { log.info("Could not evaluate criteria, credential contained no usage specifier"); return null; } Boolean result = matchUsage(credUsage, usage); return result; }
/** * Get the key contained within the credential. * * @param credential the credential containing a key * @return the key from the credential */ private Key getKey(Credential credential) { if (credential.getPublicKey() != null) { return credential.getPublicKey(); } else if (credential.getSecretKey() != null) { return credential.getSecretKey(); } else if (credential.getPrivateKey() != null) { // There should have been a corresponding public key, but just in case... return credential.getPrivateKey(); } else { return null; } }