-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add custom handler for IDP initiated authentication
see: https://medium.com/@usamashaikh47/enable-sso-in-sap-commerce-cloud-backoffice-with-okta-48f17fc69ff1
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...s/sapcxsinglesignon/resources/sapcxsinglesignon/web/spring/idp-initiated-login-spring.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
|
||
<bean id="cxIdpInitiatedSamlAuthenticationSuccessHandler" class="tools.sapcx.commerce.sso.saml.IdpInitiatedSamlAuthenticationSuccessHandler"> | ||
<property name="defaultTargetUrl" value="${sapcxsinglesignon.backoffice.defaulturl}"/> | ||
</bean> | ||
</beans> |
31 changes: 31 additions & 0 deletions
31
...ignon/src/tools/sapcx/commerce/sso/saml/IdpInitiatedSamlAuthenticationSuccessHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package tools.sapcx.commerce.sso.saml; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.saml2.provider.service.authentication.Saml2Authentication; | ||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; | ||
|
||
public class IdpInitiatedSamlAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { | ||
private static final Logger LOG = LoggerFactory.getLogger(IdpInitiatedSamlAuthenticationSuccessHandler.class); | ||
|
||
@Override | ||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { | ||
if (authentication instanceof Saml2Authentication) { | ||
String relayStateURL = request.getParameter("RelayState"); | ||
if (StringUtils.isNotBlank(relayStateURL)) { | ||
LOG.debug("Redirecting to RelayState Url: " + relayStateURL); | ||
getRedirectStrategy().sendRedirect(request, response, relayStateURL); | ||
return; | ||
} | ||
} | ||
super.onAuthenticationSuccess(request, response, authentication); | ||
} | ||
} |