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); }
@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()); }
@Test public void testWithWorkingCertificate() throws Exception { SamlConfig config = new SamlConfig(); config.setPrivateKey(KEY); config.setPrivateKeyPassword(PASSWORD); config.setCertificate(CERTIFICATE); keyManager = SamlKeyManagerFactory.getKeyManager(config); Credential credential = keyManager.getDefaultCredential(); assertNotNull(credential.getPrivateKey()); assertNotNull(credential.getPublicKey()); assertNotNull(credential); }
keyManager = SamlKeyManagerFactory.getKeyManager(config); Credential credential = keyManager.getDefaultCredential(); assertNotNull(credential.getPrivateKey()); assertNotNull(credential.getPublicKey()); assertNotNull(credential);
/** * 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; }
/** * Extract the signing key from the credential. * * @param credential the credential containing the signing key * @return the signing key (either a private key or a secret (symmetric) key */ public static Key extractSigningKey(Credential credential) { if (credential == null) { return null; } if (credential.getPrivateKey() != null) { return credential.getPrivateKey(); } else { return credential.getSecretKey(); } }
/** * Extract the signing key from the credential. * * @param credential the credential containing the signing key * @return the signing key (either a private key or a secret (symmetric) key */ public static Key extractSigningKey(Credential credential) { if (credential == null) { return null; } if (credential.getPrivateKey() != null) { return credential.getPrivateKey(); } else { return credential.getSecretKey(); } }
/** * Extract the decryption key from the credential. * * @param credential the credential containing the decryption key * @return the decryption key (either a private key or a secret (symmetric) key */ public static Key extractDecryptionKey(Credential credential) { if (credential == null) { return null; } if (credential.getPrivateKey() != null) { return credential.getPrivateKey(); } else { return credential.getSecretKey(); } }
/** * Extract the decryption key from the credential. * * @param credential the credential containing the decryption key * @return the decryption key (either a private key or a secret (symmetric) key */ public static Key extractDecryptionKey(Credential credential) { if (credential == null) { return null; } if (credential.getPrivateKey() != null) { return credential.getPrivateKey(); } else { return credential.getSecretKey(); } }
/** * 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; }
/** * 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; }
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); }
/** * 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; } }
/** * 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; } }
/** * 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; } }
/** * 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; } }
/** * Utility method to extract any key that might be present in the specified Credential. * * @param cred the Credential to evaluate * @return the Key contained in the credential, or null if it does not contain a key. */ protected Key extractKeyValue(Credential cred) { if (cred == null) { return null; } if (cred.getPublicKey() != null) { return cred.getPublicKey(); } // This could happen if key is derived, e.g. key agreement, etc if (cred.getSecretKey() != null) { return cred.getSecretKey(); } // Perhaps unlikely, but go ahead and check if (cred.getPrivateKey() != null) { return cred.getPrivateKey(); } return null; }
/** * Utility method to extract any key that might be present in the specified Credential. * * @param cred the Credential to evaluate * @return the Key contained in the credential, or null if it does not contain a key. */ protected Key extractKeyValue(Credential cred) { if (cred == null) { return null; } if (cred.getPublicKey() != null) { return cred.getPublicKey(); } // This could happen if key is derived, e.g. key agreement, etc if (cred.getSecretKey() != null) { return cred.getSecretKey(); } // Perhaps unlikely, but go ahead and check if (cred.getPrivateKey() != null) { return cred.getPrivateKey(); } return null; }
/** * Utility method to extract any key that might be present in the specified Credential. * * @param cred the Credential to evaluate * @return the Key contained in the credential, or null if it does not contain a key. */ protected Key extractKeyValue(Credential cred) { if (cred == null) { return null; } if (cred.getPublicKey() != null) { return cred.getPublicKey(); } // This could happen if key is derived, e.g. key agreement, etc if (cred.getSecretKey() != null) { return cred.getSecretKey(); } // Perhaps unlikely, but go ahead and check if (cred.getPrivateKey() != null) { return cred.getPrivateKey(); } return null; }
/** * Utility method to extract any key that might be present in the specified Credential. * * @param cred the Credential to evaluate * @return the Key contained in the credential, or null if it does not contain a key. */ protected Key extractKeyValue(Credential cred) { if (cred == null) { return null; } if (cred.getPublicKey() != null) { return cred.getPublicKey(); } // This could happen if key is derived, e.g. key agreement, etc if (cred.getSecretKey() != null) { return cred.getSecretKey(); } // Perhaps unlikely, but go ahead and check if (cred.getPrivateKey() != null) { return cred.getPrivateKey(); } return null; }