Class ConnectionManager


  • public class ConnectionManager
    extends Object
    Manages a connection to the current Wikibase instance.

    The connection can be either BasicApiConnection or OAuthApiConnection.

    Author:
    Antonin Delpeuch, Lu Liu
    • Field Detail

      • PREFERENCE_STORE_KEY

        public static final String PREFERENCE_STORE_KEY
        We used this key to read/write credentials from/to preferences in the past, which is insecure. Now this key is kept only to delete those credentials in the preferences.
        See Also:
        Constant Field Values
    • Method Detail

      • login

        public boolean login​(String mediaWikiApiEndpoint,
                             String username,
                             String password)
        Logs in to the Wikibase instance, using username/password.

        If failed to login, the connection will be set to null.

        Parameters:
        mediaWikiApiEndpoint - the api endpoint of the target Wikibase instance
        username - the username to log in with
        password - the password to log in with
        Returns:
        true if logged in successfully, false otherwise
      • login

        public boolean login​(String mediaWikiApiEndpoint,
                             String consumerToken,
                             String consumerSecret,
                             String accessToken,
                             String accessSecret)
        Logs in to the Wikibase instance, using owner-only consumer.

        If failed to login, the connection will be set to null.

        Parameters:
        mediaWikiApiEndpoint - the api endpoint of the target Wikibase instance
        consumerToken - consumer token of an owner-only consumer
        consumerSecret - consumer secret of an owner-only consumer
        accessToken - access token of an owner-only consumer
        accessSecret - access secret of an owner-only consumer
        Returns:
        true if logged in successfully, false otherwise
      • login

        public boolean login​(String mediaWikiApiEndpoint,
                             String username,
                             List<javax.servlet.http.Cookie> cookies)
        Logs in to the Wikibase instance, using cookies.

        If failed to login, the connection will be set to null.

        Parameters:
        mediaWikiApiEndpoint - the api endpoint of the target Wikibase instance
        username - the username
        cookies - the cookies used to login
        Returns:
        true if logged in successfully, false otherwise
      • logout

        public void logout​(String mediaWikiApiEndpoint)
      • getConnection

        public org.wikidata.wdtk.wikibaseapi.ApiConnection getConnection​(String mediaWikiApiEndpoint)
      • isLoggedIn

        public boolean isLoggedIn​(String mediaWikiApiEndpoint)
      • getUsername

        public String getUsername​(String mediaWikiApiEndpoint)