SAMLEntryPoint extends GenericFilterBean implements AuthenticationEntryPoint { protected void initializeDiscovery(SAMLMessageContext context) throws ServletException, IOException, MetadataProviderException { String discoveryURL = context.getLocalExtendedMetadata().getIdpDiscoveryURL(); if (discoveryURL != null) { URLBuilder urlBuilder = new URLBuilder(discoveryURL); List<Pair<String, String>> queryParams = urlBuilder.getQueryParams(); queryParams.add(new Pair<String, String>(SAMLDiscovery.ENTITY_ID_PARAM, context.getLocalEntityId())); queryParams.add(new Pair<String, String>(SAMLDiscovery.RETURN_ID_PARAM, IDP_PARAMETER)); discoveryURL = urlBuilder.buildURL(); log.debug("Using discovery URL from extended metadata"); } else { String discoveryUrl = SAMLDiscovery.FILTER_URL; if (samlDiscovery != null) { discoveryUrl = samlDiscovery.getFilterProcessesUrl(); } String contextPath = (String) context.getInboundMessageTransport().getAttribute(SAMLConstants.LOCAL_CONTEXT_PATH); discoveryURL = contextPath + discoveryUrl + "?" + SAMLDiscovery.RETURN_ID_PARAM + "=" + IDP_PARAMETER + "&" + SAMLDiscovery.ENTITY_ID_PARAM + "=" + context.getLocalEntityId(); log.debug("Using local discovery URL"); } log.debug("Redirecting to discovery URL {}", discoveryURL); HTTPOutTransport response = (HTTPOutTransport) context.getOutboundMessageTransport(); response.sendRedirect(discoveryURL); }  void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e); void setDefaultProfileOptions(WebSSOProfileOptions defaultOptions); @Autowired @Qualifier("webSSOprofile") void setWebSSOprofile(WebSSOProfile webSSOprofile); @Autowired(required = false) @Qualifier("ecpprofile") void setWebSSOprofileECP(WebSSOProfile webSSOprofileECP); @Autowired(required = false) @Qualifier("hokWebSSOProfile") void setWebSSOprofileHoK(WebSSOProfile webSSOprofileHoK); @Autowired void setSamlLogger(SAMLLogger samlLogger); @Autowired(required = false) void setSamlDiscovery(SAMLDiscovery samlDiscovery); @Autowired void setContextProvider(SAMLContextProvider contextProvider); @Autowired void setMetadata(MetadataManager metadata); String getFilterProcessesUrl(); void setFilterProcessesUrl(String filterProcessesUrl); @Override void afterPropertiesSet(); static final String FILTER_URL; static final String IDP_PARAMETER; static final String DISCOVERY_RESPONSE_PARAMETER; }
@Test public void testIDPSelection_metadataURL() throws Exception { SAMLMessageContext context = new SAMLMessageContext(); ExtendedMetadata metadata = new ExtendedMetadata(); metadata.setIdpDiscoveryEnabled(true); metadata.setIdpDiscoveryURL("http: context.setLocalExtendedMetadata(metadata); context.setLocalEntityId("localId"); context.setInboundMessageTransport(new HttpServletRequestAdapter(request)); context.setOutboundMessageTransport(new HttpServletResponseAdapter(response, false)); response.sendRedirect("http: replayMock(); entryPoint.initializeDiscovery(context); verifyMock(); }
@Test(expected = IllegalArgumentException.class) public void testIDPSelection_invalidDiscoURL() throws Exception { SAMLMessageContext context = new SAMLMessageContext(); ExtendedMetadata metadata = new ExtendedMetadata(); metadata.setIdpDiscoveryEnabled(true); metadata.setIdpDiscoveryURL("test.fi/idpDisco/"); context.setLocalExtendedMetadata(metadata); context.setLocalEntityId("localId"); context.setInboundMessageTransport(new HttpServletRequestAdapter(request)); context.setOutboundMessageTransport(new HttpServletResponseAdapter(response, false)); replayMock(); entryPoint.initializeDiscovery(context); verifyMock(); }