0

I am working on SharePoint API, and i have a login method which looks like that :

public void login(String configFileName) {

        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope(AuthScope.ANY),
                new NTCredentials(loginauthent, password, "workstation", urlsite));
        client = HttpClients.custom()
                .setDefaultCredentialsProvider(credsProvider)
                .build();

        try {
            HttpGet httpget = new HttpGet(urlsite);

            System.out.println("Executing request " + httpget.getRequestLine());
            HttpResponse response = client.execute(httpget);
            try {
                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                EntityUtils.consume(response.getEntity());
            } catch (IOException e) {
                logger.error("", e);
            }

        } catch (IOException e) {
            logger.error("", e);
        }
    }

As I am a beginner, and I must admit I found it on internet, it works perfectly.

The problem is that I don't have any ideas how to disconnect Sharepoint based on my login code.

Can someone help me?

Thank you!!

1 Answer 1

0

You're apparently using Basic Authentication. There isn't a way to really "log out" when using basic authentication as what's happening is that browser keeps sending credentials to server, and server is in no position to tell the browser to stop sending them.

As not-so-elegant workaround you could mimic logout scenario by sending out invalid (such as blank) username/password pair when user presses Log Out button or when you want to log out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.