protected boolean login() throws Exception {
   synchronized (getClass()) {
     final ForSharedServiceImpl service = (ForSharedServiceImpl) getPluginService();
     PremiumAccount pa = service.getConfig();
     if (!pa.isSet()) {
       pa = service.showConfigDialog();
       if (pa == null || !pa.isSet()) {
         LOGIN_CACHE.remove(getClass());
         throw new BadLoginException("No 4Shared account login information!");
       }
     }
     final LoginData loginData = LOGIN_CACHE.get(getClass());
     if (loginData == null || !pa.equals(loginData.getPa()) || loginData.isStale()) {
       logger.info("Logging in");
       doLogin(pa);
       final Cookie[] cookies = new Cookie[2];
       final Cookie loginCookie = getCookieByName("Login");
       final Cookie passwdCookie = getCookieByName("Password");
       if ((loginCookie == null) || (passwdCookie == null)) {
         throw new PluginImplementationException("Login cookies not found");
       }
       cookies[0] = loginCookie;
       cookies[1] = passwdCookie;
       LOGIN_CACHE.put(getClass(), new LoginData(pa, cookies));
     } else {
       logger.info("Login data cache hit");
       client.getHTTPClient().getState().addCookies(loginData.getCookies());
     }
     return true;
   }
 }
Esempio n. 2
0
  /**
   * Constructor.
   *
   * @param c the OpenOffice component context
   */
  public SettingsDialog(XComponentContext c) {
    super(c, Constants.SETTINGS_DIALOG);
    LoginData loginData = new LoginData();
    XWikiExtension xWikiExtension = XWikiExtension.getInstance();

    if (loginData.canAutoLogin()) {
      credentials = loginData.getCredentials();
      ConnectionSettings set = xWikiExtension.getSettings();

      set.setServerURL(credentials[0]);
      set.setPassword(credentials[1]);
      set.setPassword(credentials[2]);
      set.setWikiURL(credentials[3]);
      set.setXmlRpcURL(credentials[4]);

      try {
        getPropSet("txtServerURL").setPropertyValue("Text", credentials[0]);
        getPropSet("txtUsername").setPropertyValue("Text", credentials[1]);
        // TODO secure store for the password
        getPropSet("txtPassword").setPropertyValue("Text", credentials[2]);

      } catch (UnknownPropertyException e) {
        e.printStackTrace();
      } catch (PropertyVetoException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (WrappedTargetException e) {
        e.printStackTrace();
      }
    }

    String urlOkButton = xWikiExtension.getImagesDirUrl() + "/" + Constants.IMG_OK_BUTTON;
    String urlCancelButton = xWikiExtension.getImagesDirUrl() + "/" + Constants.IMG_CANCEL_BUTTON;
    String urlCustomButton = xWikiExtension.getImagesDirUrl() + "/" + Constants.IMG_CONN_SETTINGS;

    try {

      getPropSet("btnOK").setPropertyValue("ImageURL", urlOkButton);
      getPropSet("btnCancel").setPropertyValue("ImageURL", urlCancelButton);
      getPropSet("cmdCustom").setPropertyValue("ImageURL", urlCustomButton);

    } catch (UnknownPropertyException e) {
      e.printStackTrace();
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (WrappedTargetException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 3
0
    private ToStateTransitions load(
        LoginData loginData, ProjectGroupConfig boardConfig, Issue issue, String toState)
        throws IOException {
      final UriBuilder builder =
          UriBuilder.fromUri(boardConfig.getJiraUrl())
              .path("rest")
              .path("api")
              .path("2")
              .path("issue")
              .path(issue.getKey())
              .path("transitions")
              .queryParam("issueIdOrKey", issue.getKey());
      final WebTarget target = loginData.getClient().target(builder);
      final Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get();

      if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
        throw new IOException(
            "Error looking up the transitions for issue "
                + issue.getKey()
                + ": "
                + response.readEntity(String.class));
      }
      Map<String, Transition> states = new HashMap<>();
      ModelNode modelNode = ModelNode.fromJSONString(response.readEntity(String.class));
      for (ModelNode transitionNode : modelNode.get("transitions").asList()) {
        Transition transition =
            new Transition(transitionNode.get("id").asInt(), transitionNode.get("name").asString());
        states.put(transition.toState, transition);
      }
      ToStateTransitions toStateTransitions = new ToStateTransitions(issue.getState(), states);
      return toStateTransitions;
    }
  @Override
  public ContentValues getContentValues() {
    ContentValues values = new ContentValues();
    if (loginResponse.getErrors().size() > 0) {
      StringBuilder errorMessage = new StringBuilder();
      for (String[] error : loginResponse.getErrors()) {
        errorMessage.append(error[1] + " ");
      }

      values.put(RedditContract.Login.SUCCESS, 0);
      values.put(RedditContract.Login.ERROR_MESSAGE, errorMessage.toString());
    } else {
      LoginData data = loginResponse.getData();
      values.put(RedditContract.Login.USERNAME, data.getUsername());
      values.put(RedditContract.Login.COOKIE, data.getCookie());
      values.put(RedditContract.Login.MODHASH, data.getModhash());
      values.put(RedditContract.Login.SUCCESS, 1);
    }

    return values;
  }
Esempio n. 5
0
  /** The handler for the clicked event of the OK button. */
  private void btnOK_Clicked() {

    boolean bResult = false;

    try {
      String sServerURL = (String) getPropSet("txtServerURL").getPropertyValue("Text");
      String sUserName = (String) getPropSet("txtUsername").getPropertyValue("Text");
      String sPassword = (String) getPropSet("txtPassword").getPropertyValue("Text");
      Short nState = (Short) getPropSet("chkRemember").getPropertyValue("State");

      if (sServerURL.endsWith("/")) sServerURL = sServerURL.substring(0, sServerURL.length() - 1);

      XWikiExtension xWikiExtension = XWikiExtension.getInstance();
      ConnectionSettings set = xWikiExtension.getSettings();
      set.setServerURL(sServerURL);
      xWikiExtension.resetClient();
      set.setUsername(sUserName);
      set.setPassword(sPassword);

      if (nState == 0) {
        LoginData loginData = new LoginData();
        loginData.clearCredentials();
      } else if (nState == 1) {
        String new_credentials[] = {
          sServerURL,
          sUserName,
          sPassword,
          xWikiExtension.getSettings().getWikiURL(),
          xWikiExtension.getSettings().getXmlRpcURL()
        };
        LoginData loginData = new LoginData();
        loginData.writeCredentials(new_credentials);
      }

      XWikiXmlRpcClient client = xWikiExtension.getClient();
      if (client != null) {
        bResult = xWikiExtension.doLogin();
      }
      if (bResult) {
        m_xDialog.endExecute();
        xWikiExtension.getExtensionStatus().setLoginStatus(true);
        Utils.ShowMessage(
            m_xContext,
            m_xDialog,
            Constants.TITLE_XWIKI,
            Constants.MESS_LOGINSUCC,
            Constants.TYPE_INFO,
            false);
      } else {
        Utils.ShowMessage(
            m_xContext,
            m_xDialog,
            Constants.TITLE_ERROR,
            Constants.ERROR_LOGINFAILED,
            Constants.TYPE_ERROR,
            false);
      }
    } catch (UnknownPropertyException e) {
      e.printStackTrace();
    } catch (WrappedTargetException e) {
      e.printStackTrace();
    }
  }