RedHat Shadowman Logo

Lets suppose that you have a remote Enterprise JavaBeans (EJB) application where the EJB client is a service pack (SP) application in a Security Assertion Markup Language (SAML) architecture. You would like your remote EJB to be authenticated using same assertion which was used for SP.

Before proceeding with this tutorial, you should have a basic understanding of EJB and Picketlink.

I have developed a POC based on Picketlink. Below are the things I have done to achieve it.
  •  Set Picketlink to sign response and assertion in identity provider (IDP) application.
    `SAML2SignatureGenerationHandler` like the following in picketlink.xml of IDP application.
    <Handler class="org.picketlink.identity.federation.web.handlers.saml2.SAML2SignatureGenerationHandler">
         <Option Key="SIGN_RESPONSE_AND_ASSERTION" Value="true"/>
  • Set picketlink to store SAML assertion in http-session in SP application.
    `SAML2AuthenticationHandler`  like the following in picketlink.xml of SP application.
    <Handler class="org.picketlink.identity.federation.web.handlers.saml2.SAML2AuthenticationHandler">
         <Option Key="ASSERTION_SESSION_ATTRIBUTE_NAME" Value="org.picketlink.sp.assertion"/>
  •  Configure the sp security-domain something like below setting flag "sufficient" for both the login module and for the IDP application. You can configure your customized login module or you can use any login module available in picketbox.
      <security-domain name="sp" cache-type="default">
            <login-module code="org.picketlink.identity.federation.bindings.jboss.auth.SAML2LoginModule" flag="sufficient" />
            <login-module code="org.picketlink.identity.federation.bindings.jboss.auth.SAML2STSLoginModule" flag="sufficient">
                 <module-option name="roleKey" value="Role"/>
                 <module-option name="localValidation" value="true"/>
                 <module-option name="localValidationSecurityDomain" value="sp"/>
  •  In your servlet (EJB client/SP application) you need to get the signed assertion and send it along with the EJB invocation for verification like below. Here, I have used ejb-remote application which is available in quickstart [1].
//Getting Signed SAML Assertion
public String getSignedAssertion(HttpServletRequest httpRequest) throws Exception {
         HttpSession session = httpRequest.getSession();
         String cachedSignedAssertion = (String) session.getAttribute("org.picketlink.sp.assertion.signed");
         if (cachedSignedAssertion == null) {
             Document assertion = (Document) session.getAttribute("org.picketlink.sp.assertion");
             String stringSignedAssertion = DocumentUtil.asString(assertion);
             return stringSignedAssertion;
         } else {
             System.out.println("...cached assertion...");
             return cachedSignedAssertion;
//EJB invocation
public void getInitialContext(String assertion, String username) throws Exception, NamingException {
         Properties props = new Properties();
         props.put("", "false");
         props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
         props.put("remote.connections", "default");
         props.put("remote.connection.default.port", "4447");
         props.put("", "");
         props.put("remote.connection.default.username", username);
         props.put("remote.connection.default.password", assertion);
         Context context = new InitialContext(props);
         RemoteCounter aa = (RemoteCounter) context.lookup("ejb:/jboss-ejb-remote-server-side//CounterBean!");
         System.out.println("EJB Executed... using SAML assertion");
You can get the IDP and SP sample of Picketlink at [2] below:

That's it for today!

Take advantage of your Red Hat Developers membership and download RHEL today at no cost.

Last updated: March 23, 2023