use of org.opensaml.security.x509.X509Credential in project airavata by apache.
the class UNICORESecurityContext method getDefaultConfiguration.
public DefaultClientConfiguration getDefaultConfiguration(Boolean enableMessageLogging, UserConfigurationData userData) throws GFacException, ApplicationSettingsException {
X509Credential cred = null;
try {
boolean genCert = userData.isGenerateCert();
if (genCert) {
String userDN = userData.getUserDN();
if (userDN == null && "".equals(userDN)) {
log.warn("Cannot generate cert, falling back to container configured MyProxy credentials");
return getDefaultConfiguration(enableMessageLogging);
} else {
log.info("Generating X.509 certificate for: " + userDN);
try {
String caCertPath = ServerSettings.getSetting(BESConstants.PROP_CA_CERT_PATH, "");
String caKeyPath = ServerSettings.getSetting(BESConstants.PROP_CA_KEY_PATH, "");
String caKeyPass = ServerSettings.getSetting(BESConstants.PROP_CA_KEY_PASS, "");
if (caCertPath.equals("") || caKeyPath.equals("")) {
throw new Exception("CA certificate or key file path missing in the properties file. " + "Please make sure " + BESConstants.PROP_CA_CERT_PATH + " or " + BESConstants.PROP_CA_KEY_PATH + " are not empty.");
}
if ("".equals(caKeyPass)) {
log.warn("Caution: CA key has no password. For security reasons it is highly recommended to set a CA key password");
}
cred = generateShortLivedCredential(userDN, caCertPath, caKeyPath, caKeyPass);
} catch (Exception e) {
throw new GFacProviderException("Error occured while generating a short lived credential for user:" + userDN, e);
}
}
} else {
return getDefaultConfiguration(enableMessageLogging);
}
secProperties = new DefaultClientConfiguration(dcValidator, cred);
setExtraSettings();
} catch (Exception e) {
throw new GFacException(e.getMessage(), e);
}
secProperties.getETDSettings().setExtendTrustDelegation(true);
if (enableMessageLogging)
secProperties.setMessageLogging(true);
// secProperties.setDoSignMessage(true);
secProperties.getETDSettings().setIssuerCertificateChain(secProperties.getCredential().getCertificateChain());
return secProperties;
}
use of org.opensaml.security.x509.X509Credential in project airavata by apache.
the class UNICORESecurityContext method getDefaultConfiguration.
/**
* Get client configuration from MyProxy credentials.
*
* @return an instance of the default client configuration
* @throws GFacException
* @throws ApplicationSettingsException
* @throws GFacException, ApplicationSettingsException
*/
public DefaultClientConfiguration getDefaultConfiguration(Boolean enableMessageLogging) throws GFacException, ApplicationSettingsException {
try {
X509Credential cred = getX509Credentials();
secProperties = new DefaultClientConfiguration(dcValidator, cred);
setExtraSettings();
} catch (Exception e) {
throw new GFacException(e.getMessage(), e);
}
secProperties.getETDSettings().setExtendTrustDelegation(true);
if (enableMessageLogging)
secProperties.setMessageLogging(true);
// secProperties.setMessageLogging(true);
// secProperties.setDoSignMessage(true);
secProperties.getETDSettings().setIssuerCertificateChain(secProperties.getCredential().getCertificateChain());
return secProperties;
}
use of org.opensaml.security.x509.X509Credential in project airavata by apache.
the class UNICORESecurityContext method getDefaultConfiguration.
public DefaultClientConfiguration getDefaultConfiguration(Boolean enableMessageLogging) throws GFacException, ApplicationSettingsException {
try {
X509Credential cred = getX509Credentials();
secProperties = new DefaultClientConfiguration(dcValidator, cred);
setExtraSettings();
} catch (Exception e) {
throw new GFacException(e.getMessage(), e);
}
if (enableMessageLogging)
secProperties.setMessageLogging(true);
return secProperties;
}
use of org.opensaml.security.x509.X509Credential in project pac4j by pac4j.
the class KeyStoreCredentialProvider method getCredential.
@Override
public final Credential getCredential() {
try {
final CriteriaSet cs = new CriteriaSet();
final EntityIdCriterion criteria = new EntityIdCriterion(this.privateKey);
cs.add(criteria);
final X509Credential creds = (X509Credential) this.credentialResolver.resolveSingle(cs);
return creds;
} catch (final ResolverException e) {
throw new SAMLException("Can't obtain SP private key", e);
}
}
use of org.opensaml.security.x509.X509Credential in project cas by apereo.
the class WsFederationConfiguration method getSigningCredential.
/**
* getSigningCredential loads up an X509Credential from a file.
*
* @param resource the signing certificate file
* @return an X509 credential
*/
private static Credential getSigningCredential(final Resource resource) {
try (InputStream inputStream = resource.getInputStream()) {
final CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
final X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(inputStream);
final Credential publicCredential = new BasicX509Credential(certificate);
LOGGER.debug("Signing credential key retrieved from [{}].", resource);
return publicCredential;
} catch (final Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
return null;
}
Aggregations