Enabling SAML-based SSO with Remote EJB through Picketlink

综合编程 2018-01-03 阅读原文

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.

    Configure:

    `SAML2SignatureGenerationHandler` like the following in picketlink.xml of IDP application.

    
         
     
  • Set picketlink to store SAML assertion in http-session in SP application.

    Configure:

    `SAML2AuthenticationHandler` like the following in picketlink.xml of SP application.

    
         
     
  • 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.
      
         
            
            
                 
                 
                 
            
          
       
  • 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);
             System.out.println(stringSignedAssertion);
             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("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "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("remote.connection.default.host", "10.10.10.10");
         System.out.println("Connecting...");
         props.put("remote.connection.default.username", username);
         props.put("remote.connection.default.password", assertion);
         props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");
         props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS","false");
         Context context = new InitialContext(props);
         RemoteCounter aa = (RemoteCounter) context.lookup("ejb:/jboss-ejb-remote-server-side//CounterBean!org.jboss.as.quickstarts.ejb.remote.stateful.RemoteCounter?stateful");
         System.out.println(aa.getCount());
         aa.increment();
         System.out.println(aa.getCount());
         System.out.println("EJB Executed... using SAML assertion");
     }

You can get the IDP and SP sample of Picketlink at [2] below:

  1. https://github.com/jboss-developer/jboss-eap-quickstarts/tree/6.4.x/ejb-remote
  2. https://github.com/jboss-developer/jboss-picketlink-quickstarts

That’s it for today!

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

Red Hat Developer Blog

责编内容by:Red Hat Developer Blog阅读原文】。感谢您的支持!

您可能感兴趣的

EJB系列(三)——EJB事务管理  首先EJB Session Bean从功能大可分为两类: 1、 Dao:用于封装底层的实体和JPA,访问实体,可称为EAO对象(Entity Access Object) ,本质上就是三层中Dao层。 ...
Why can not state horns be exposed as web services... I have been reading about Stateful and Stateless session beans and came across a sentence that states that: Stateful session beans cannot be exposed...
一天一个注解-@PostConstruct 简介 Java EE5 引入了@PostConstruct和@PreDestroy这两个作用于Servlet生命周期的注解,实现Bean初始化之前和销毁之前的自定义操作。此文主要说明@PostConstruct。 API使用说明 以下为@PostConstruct的API使用说明: ...
BEA-010213, Message-Driven EJB: MyProcessMDB’s tra... I encountered this error last week and it was quite a headache to find out what the source of the problem was. Short summary:I thought the ...
Load balancing problem on cluster EJB calls in Web... Our Application has 2 Clusters running in Weblogic 12 C. Each Cluster 4 Managed Servers. Cluster B is making EJB Call to Cluster A through Foreign J...