/** Creates the SAML Bearer Token that will be used to authenticate to the S-RAMP Atom API. */ private static String createSAMLBearerTokenAssertion() { String issuer = SrampUIConfig.config.getString(SrampUIConfig.SRAMP_API_SAML_AUTH_ISSUER); String service = SrampUIConfig.config.getString(SrampUIConfig.SRAMP_API_SAML_AUTH_SERVICE); String samlAssertion = SAMLAssertionUtil.createSAMLAssertion(issuer, service); boolean signAssertion = "true" .equals( SrampUIConfig.config.getString( SrampUIConfig.SRAMP_API_SAML_AUTH_SIGN_ASSERTIONS)); // $NON-NLS-1$ if (signAssertion) { String keystorePath = SrampUIConfig.config.getString(SrampUIConfig.SRAMP_API_SAML_AUTH_KEYSTORE); String keystorePassword = SrampUIConfig.config.getString(SrampUIConfig.SRAMP_API_SAML_AUTH_KEYSTORE_PASSWORD); String keyAlias = SrampUIConfig.config.getString(SrampUIConfig.SRAMP_API_SAML_AUTH_KEY_ALIAS); String keyAliasPassword = SrampUIConfig.config.getString(SrampUIConfig.SRAMP_API_SAML_AUTH_KEY_PASSWORD); try { KeyStore keystore = SAMLBearerTokenUtil.loadKeystore(keystorePath, keystorePassword); KeyPair keyPair = SAMLBearerTokenUtil.getKeyPair(keystore, keyAlias, keyAliasPassword); samlAssertion = SAMLBearerTokenUtil.signSAMLAssertion(samlAssertion, keyPair); } catch (Exception e) { throw new RuntimeException(e); } } return samlAssertion; }
/** * Loads the keystore. * * @throws IOException */ private KeyStore loadKeystore() throws IOException { try { return SAMLBearerTokenUtil.loadKeystore(keystorePath, keystorePassword); } catch (Exception e) { e.printStackTrace(); throw new IOException( Messages.getString("SamlBearerTokenAuthFilter.ErrorLoadingKeystore") + e.getMessage()); // $NON-NLS-1$ } }