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

org.labkey.remoteapi.security.StopImpersonatingCommand Maven / Gradle / Ivy

Go to download

The client-side library for Java developers is a separate JAR from the LabKey Server code base. It can be used by any Java program, including another Java web application.

There is a newer version: 6.2.0
Show newest version
package org.labkey.remoteapi.security;

import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
import org.apache.hc.client5.http.config.RequestConfig;
import org.labkey.remoteapi.CommandResponse;
import org.labkey.remoteapi.PostCommand;

import java.net.URI;

/**
 * Stop impersonating a user.
 */
public class StopImpersonatingCommand extends PostCommand
{
    public StopImpersonatingCommand()
    {
        // TODO: At some point (when we're okay with breaking compatibility with pre-22.10 servers) switch this to
        // stopImpersonatingApi.api, a true API action added 9/22
        super("login", "stopImpersonating.api");
    }

    @Override
    protected HttpUriRequest createRequest(URI uri)
    {
        // Disable redirects just for this request
        HttpPost request = (HttpPost)super.createRequest(uri); // CONSIDER: generify Command with request type?
        RequestConfig oldConfig = request.getConfig();
        RequestConfig.Builder builder = oldConfig != null ? RequestConfig.copy(oldConfig) : RequestConfig.custom();
        builder.setRedirectsEnabled(false);
        request.setConfig(builder.build());

        return request;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy