Announcement Announcement Module
Collapse
No announcement yet.
Profile-specific code in index.jsp for LDAP and SAML AuthenticationProviders Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Profile-specific code in index.jsp for LDAP and SAML AuthenticationProviders

    My webapp uses spring-security, spring-ldap and spring-security-saml for supporting both LDAP and SAML SSO based authentication.

    In some deployment scenarios only the LDAPAuthenticationProvider is used while in other deployment scenarios only the SAMLAuthenticationProvider is used. These deployment scenarios are configured using profiles named "ldap" and "saml" respectively.

    I am trying to write a single index.jsp that can use conditional logic to display username and the links to login / logout pages etc. taking into account the deployment profile of "ldap" or "saml".

    What is the best way to detect which profile ("ldap" or "saml") is active within index.jsp when processing a request?

  • #2
    I have found a solution to the problem... It is to use the WebApplicationContext to lookup the SAMLAuthenticationProvider bean. If it exists then assume saml profile otherwise assume ldap profile.

    Is there a better way?

    Code:
                    <%
                        Object samlAuthenticationProvider = null;
                        
                        WebApplicationContext context = 
                            WebApplicationContextUtils.getWebApplicationContext(application);
                        try {
                            samlAuthenticationProvider = context.getBean("samlAuthenticationProvider");
                        } catch (NoSuchBeanDefinitionException e) {
                           //Expected if saml profile is not active 
                        }                    
    
                        pageContext.setAttribute("samlAuthenticationProvider", samlAuthenticationProvider);
                    %>
    
                    ....
    
                    <% if (samlAuthenticationProvider != null) { %>
                    ...
                    <% } else { %>
                    ...
                    <% } %>

    Comment

    Working...
    X