@Override
  public User provideUserByEmailAddress(
      String firstName, String lastName, String emailAddress, String portalOrganizationName)
      throws Exception {
    Organization org = provideOrganization(portalOrganizationName);
    User user = provideUserByEmailAddress(firstName, lastName, emailAddress);
    user.setTenant(org);
    updateDefaultOrganizationId(user, Long.toString(org.getOrganizationId()));

    // addOrganizationUserIds(org.getName(), new String[]{Long.toString(user.getUserId())});
    return user;
  }
  private void updateDefaultOrganizationId(User user, String portalOrganizationId)
      throws Exception {
    BasicHttpContext ctx = new BasicHttpContext();
    ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);

    HttpPost post = new HttpPost("/user/update-organizations");
    List<NameValuePair> params = new ArrayList<NameValuePair>();

    JSONSerializer serializer = new JSONSerializer();
    String orgIds = serializer.serialize(new String[] {portalOrganizationId});

    params.add(new BasicNameValuePair("userId", Long.toString(user.getUserId())));
    params.add(new BasicNameValuePair("organizationIds", orgIds));
    params.add(new BasicNameValuePair("serviceContext", null));

    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
    post.setEntity(entity);

    HttpResponse resp = httpclient.execute(targetHost, post, ctx);
    System.out.println("updateDefaultOrganizationId Status:[" + resp.getStatusLine() + "]");

    String response = null;
    if (resp.getEntity() != null) {
      response = EntityUtils.toString(resp.getEntity());
    }
    System.out.println("getOrganizationByName Resp:[" + response + "]");

    EntityUtils.consume(resp.getEntity());
  }
 @Override
 public boolean userHasRoleByEmailAddress(String emailAddress, String roleName) throws Exception {
   User user = provideUserByEmailAddress(emailAddress, null, null);
   Boolean hasRole = userHasRole(Long.toString(user.getUserId()), roleName);
   return hasRole;
 }