/** * Creates a SAML Assertion that can be used as a bearer token when invoking REST services. The * REST service must be configured to accept SAML Assertion bearer tokens. * * <p>In JBoss this means protecting the REST services with {@link SAMLBearerTokenLoginModule}. In * Tomcat7 this means protecting the REST services with {@link SAMLBearerTokenAuthenticator}. * * @param issuerName the issuer name (typically the context of the calling web app) * @param forService the web context of the REST service being invoked */ public static String createSAMLAssertion(String issuerName, String forService) { if (isJBoss7()) { return Jboss7SAMLBearerTokenUtil.createSAMLAssertion(issuerName, forService); } if (isTomcat()) { return TomcatSAMLBearerTokenUtil.createSAMLAssertion( HttpRequestThreadLocalValve.TL_request.get(), issuerName, forService); } throw new RuntimeException("Unsupported/undetected platform."); }
/** Determines if we're running in tomcat. */ private static boolean isTomcat() { if (HttpRequestThreadLocalValve.TL_request.get() != null) { return true; } return false; }