Created
July 21, 2020 13:50
-
-
Save fabian-bouche-liferay/8f79b823c5ac6cd2e2bb7865a648647c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package com.liferay.samples.fbo.coe.samlmapper; | |
| import javax.servlet.http.Cookie; | |
| import org.osgi.service.component.annotations.Activate; | |
| import org.osgi.service.component.annotations.Component; | |
| import org.osgi.service.component.annotations.Deactivate; | |
| import org.osgi.service.component.annotations.Reference; | |
| import com.liferay.portal.kernel.cache.MultiVMPool; | |
| import com.liferay.portal.kernel.cache.PortalCache; | |
| import com.liferay.portal.kernel.events.ActionException; | |
| import com.liferay.portal.kernel.events.LifecycleAction; | |
| import com.liferay.portal.kernel.events.LifecycleEvent; | |
| import com.liferay.portal.kernel.log.Log; | |
| import com.liferay.portal.kernel.log.LogFactoryUtil; | |
| @Component( | |
| immediate = true, | |
| property = { "key=login.events.post" }, | |
| service = LifecycleAction.class | |
| ) | |
| public class SAMLAction implements LifecycleAction { | |
| private static Log _log = LogFactoryUtil.getLog(SAMLAction.class); | |
| @Override | |
| public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException { | |
| String key = ""; | |
| Cookie[] cookies = lifecycleEvent.getRequest().getCookies(); | |
| for(int i = 0; i < cookies.length; i++) { | |
| if("SAML_SP_KEY".equals(cookies[i].getName())) { | |
| key = cookies[i].getValue(); | |
| break; | |
| } | |
| } | |
| _log.info("SAML Response: " + _portalCache.get(key)); | |
| } | |
| @Activate | |
| protected void activate() { | |
| _portalCache = (PortalCache<String, String>) _multiVMPool.getPortalCache(CACHE_NAME); | |
| } | |
| @Deactivate | |
| public void deactivate() { | |
| _multiVMPool.removePortalCache(CACHE_NAME); | |
| } | |
| private static PortalCache<String, String> _portalCache; | |
| protected static final String CACHE_NAME = "SAMLResponse"; | |
| @Reference | |
| private MultiVMPool _multiVMPool; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment