<commit_before>/*
 * oxTrust is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxtrust.action;

import java.io.Serializable;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.gluu.jsf2.service.FacesService;
import org.gluu.oxtrust.security.Identity;
import org.gluu.oxtrust.security.OauthData;
import org.gluu.oxtrust.service.OpenIdService;
import org.gluu.oxtrust.util.OxTrustConstants;
import org.jboss.resteasy.client.ClientRequest;
import org.slf4j.Logger;
import org.xdi.config.oxtrust.AppConfiguration;
import org.xdi.util.StringHelper;

/**
 * Provides OP/RP-initiated logout functionality
 * 
 * @author <NAME> Date: 021/25/2019
 */
@Named("logoutAction")
@RequestScoped
public class LogoutAction implements Serializable {

    private static final long serialVersionUID = -1887682170119210113L;

	@Inject
	private Logger log;

	@Inject
	private Identity identity;

    @Inject
    private FacesService facesService;

    @Inject
    private OpenIdService openIdService;

    @Inject
    private AppConfiguration appConfiguration;

	public void processLogout() throws Exception {
	    opLogout();

        identity.logout();
	}

	public void processSsoLogout() throws Exception {
        identity.logout();
    }

	public String postLogout() {
        identity.logout();

		return OxTrustConstants.RESULT_SUCCESS;
	}

	protected void opLogout() throws Exception {
		boolean requireOpLogout = isRequireOpLogout();
		if (!requireOpLogout) {
		    return;
		}

		OauthData oauthData = identity.getOauthData();

		ClientRequest clientRequest = new ClientRequest(openIdService.getOpenIdConfiguration().getEndSessionEndpoint());

		clientRequest.queryParameter(OxTrustConstants.OXAUTH_SESSION_STATE, oauthData.getSessionState());
		clientRequest.queryParameter(OxTrustConstants.OXAUTH_ID_TOKEN_HINT, oauthData.getIdToken());
		clientRequest.queryParameter(OxTrustConstants.OXAUTH_POST_LOGOUT_REDIRECT_URI,
				appConfiguration.getLogoutRedirectUrl());

		facesService.redirectToExternalURL(clientRequest.getUri());
	}

	private boolean isRequireOpLogout() {
        OauthData oauthData = identity.getOauthData();
		if (StringHelper.isEmpty(oauthData.getUserUid())) {
			return false;
		}

		return true;
    }

}<commit_msg>Allow logout if id_token expired by session is active<commit_after>/*
 * oxTrust is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxtrust.action;

import java.io.Serializable;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.gluu.jsf2.service.FacesService;
import org.gluu.oxtrust.security.Identity;
import org.gluu.oxtrust.security.OauthData;
import org.gluu.oxtrust.service.OpenIdService;
import org.gluu.oxtrust.util.OxTrustConstants;
import org.jboss.resteasy.client.ClientRequest;
import org.slf4j.Logger;
import org.xdi.config.oxtrust.AppConfiguration;
import org.xdi.util.StringHelper;

/**
 * Provides OP/RP-initiated logout functionality
 * 
 * @author <NAME> Date: 021/25/2019
 */
@Named("logoutAction")
@RequestScoped
public class LogoutAction implements Serializable {

    private static final long serialVersionUID = -1887682170119210113L;

	@Inject
	private Logger log;

	@Inject
	private Identity identity;

    @Inject
    private FacesService facesService;

    @Inject
    private OpenIdService openIdService;

    @Inject
    private AppConfiguration appConfiguration;

	public void processLogout() throws Exception {
	    opLogout();

        identity.logout();
	}

	public void processSsoLogout() throws Exception {
        identity.logout();
    }

	public String postLogout() {
        identity.logout();

		return OxTrustConstants.RESULT_SUCCESS;
	}

	protected void opLogout() throws Exception {
		OauthData oauthData = identity.getOauthData();

		ClientRequest clientRequest = new ClientRequest(openIdService.getOpenIdConfiguration().getEndSessionEndpoint());

		if (oauthData.getSessionState() != null) {
		    clientRequest.queryParameter(OxTrustConstants.OXAUTH_SESSION_STATE, oauthData.getSessionState());
		}
        if (oauthData.getIdToken() != null) {
            clientRequest.queryParameter(OxTrustConstants.OXAUTH_ID_TOKEN_HINT, oauthData.getIdToken());
        }
		clientRequest.queryParameter(OxTrustConstants.OXAUTH_POST_LOGOUT_REDIRECT_URI,
				appConfiguration.getLogoutRedirectUrl());

		facesService.redirectToExternalURL(clientRequest.getUri());
	}

}
{'fraction_non_alphanumeric': 0.09688506981740065, 'fraction_numerical': 0.0163265306122449, 'mean_word_length': 4.726937269372693, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3138802', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1415, 'n_words': 282}