Created
April 13, 2016 08:57
-
-
Save korteke/f8234c6f1a8b8b4ca41fecc5185d8dc2 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 fi.csc.shibboleth.mobileauth.impl.authn; | |
| import javax.annotation.Nonnull; | |
| import javax.annotation.Nullable; | |
| import org.opensaml.profile.action.EventIds; | |
| import org.opensaml.profile.context.ProfileRequestContext; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| import com.google.common.base.Function; | |
| import net.shibboleth.idp.profile.AbstractProfileAction; | |
| import net.shibboleth.idp.profile.ActionSupport; | |
| import net.shibboleth.idp.session.SessionException; | |
| import net.shibboleth.idp.session.SessionManager; | |
| import net.shibboleth.idp.session.context.SessionContext; | |
| import net.shibboleth.utilities.java.support.component.ComponentInitializationException; | |
| import net.shibboleth.utilities.java.support.component.ComponentSupport; | |
| import net.shibboleth.utilities.java.support.logic.Constraint; | |
| @SuppressWarnings("rawtypes") | |
| public class DestroyAuthResult extends AbstractProfileAction { | |
| /** Class logger. */ | |
| @Nonnull | |
| private final Logger log = LoggerFactory.getLogger(DestroyAuthResult.class); | |
| /** SessionManager. */ | |
| @Nonnull | |
| private SessionManager sessionManager; | |
| /** Lookup function for SessionContext. */ | |
| @Nonnull private Function<ProfileRequestContext,SessionContext> sessionContextLookupStrategy; | |
| /** SessionContext to operate on. */ | |
| @Nullable private SessionContext sessionCtx; | |
| public void setSessionManager(@Nonnull final SessionManager manager) { | |
| ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); | |
| sessionManager = Constraint.isNotNull(manager, "SessionManager cannot be null"); | |
| } | |
| public void setSessionContextLookupStrategy( | |
| @Nonnull final Function<ProfileRequestContext,SessionContext> strategy) { | |
| ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); | |
| sessionContextLookupStrategy = Constraint.isNotNull(strategy, | |
| "SessionContext lookup strategy cannot be null"); | |
| } | |
| /** {@inheritDoc} */ | |
| @Override | |
| protected void doInitialize() throws ComponentInitializationException { | |
| super.doInitialize(); | |
| if (sessionManager == null) { | |
| throw new ComponentInitializationException("SessionManager cannot be null"); | |
| } | |
| } | |
| /** {@inheritDoc} */ | |
| @Override | |
| protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) { | |
| log.debug("Entering DestroyAuthResult doExecute"); | |
| sessionCtx = sessionContextLookupStrategy.apply(profileRequestContext); | |
| try { | |
| sessionManager.destroySession(sessionCtx.getIdPSession().getId(), true); | |
| } catch (SessionException e) { | |
| log.error("{} Error destroying session {}", getLogPrefix(), sessionCtx.getIdPSession().getId(), e); | |
| ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment