All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.enonic.xp.lib.portal.url.LogoutUrlHandler Maven / Gradle / Ivy

There is a newer version: 7.14.4
Show newest version
package com.enonic.xp.lib.portal.url;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import com.google.common.collect.Multimap;

import com.enonic.xp.context.Context;
import com.enonic.xp.portal.url.IdentityUrlParams;
import com.enonic.xp.script.bean.BeanContext;
import com.enonic.xp.security.IdProviderKey;
import com.enonic.xp.security.auth.AuthenticationInfo;

public final class LogoutUrlHandler
    extends AbstractUrlHandler
{
    private static final Set VALID_URL_PROPERTY_KEYS =
        new HashSet<>( Arrays.asList( "redirect", "contextPath", "type", "params" ) );

    private Context context;

    @Override
    protected String buildUrl( final Multimap map )
    {
        final IdentityUrlParams params = new IdentityUrlParams().
            portalRequest( request ).
            idProviderFunction( "logout" ).
            idProviderKey( retrieveIdProviderKey() ).
            setAsMap( map );

        return this.urlService.identityUrl( params );
    }

    private IdProviderKey retrieveIdProviderKey()
    {
        final AuthenticationInfo authInfo = this.context.getAuthInfo();
        if ( authInfo.isAuthenticated() )
        {
            return authInfo.getUser().
                getKey().
                getIdProviderKey();
        }
        return null;
    }

    @Override
    protected boolean isValidParam( final String param )
    {
        return VALID_URL_PROPERTY_KEYS.contains( param );
    }

    @Override
    public void initialize( final BeanContext context )
    {
        super.initialize( context );
        this.context = context.getBinding( Context.class ).get();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy