public Client getClient() {

    ApiKey apiKey = ApiKeys.builder().setFileLocation(path).build();
    com.stormpath.sdk.client.Client client = Clients.builder().setApiKey(apiKey).build();
    System.out.println(client.getCurrentTenant().getName());

    return client;
  }
Esempio n. 2
0
  public String CreateAccount(
      String fName, String lName, String uName, String email, String pword) {
    connectToStormpath();

    Account account = client.instantiate(Account.class);

    String output = "";

    account
        .setGivenName(fName)
        .setSurname(lName)
        .setUsername(uName)
        .setEmail(email)
        .setPassword(pword);
    //            .getCustomData().put("favoriteColor", "white");
    try {
      app.createAccount(account);
      output = "Success";
      this.CreateLocalAccount(uName);
      //            createresult.setText("Account '" + uname.getText() + "' Created");
    } catch (Exception e) {
      //            createresult.setText(e.getMessage());
      output = e.getMessage();
    }

    return output;
  }
Esempio n. 3
0
 public void connectToStormpath() {
   if (builder == null) {
     this.builder = Clients.builder();
     Properties properties = new Properties();
     properties.setProperty("apiKey.id", "3OIJT00DLSL8BQ3UCLR5X6C6S");
     properties.setProperty("apiKey.secret", "CGMCI0ul9ZR3hDiDIvcocccav3KOKcpHZ2doeqUm1i8");
     ApiKey apiKey = ApiKeys.builder().setProperties(properties).build();
     this.client = Clients.builder().setApiKey(apiKey).build();
     this.tenant = client.getCurrentTenant();
     this.applications =
         tenant.getApplications(Applications.where(Applications.name().eqIgnoreCase("sQuire")));
     this.app = applications.iterator().next();
   }
 }
  @Override
  protected ViewModel onValidSubmit(HttpServletRequest req, HttpServletResponse resp, Form form)
      throws Exception {

    // Create a new Account instance that will represent the submitted user information:
    Account account = client.instantiate(Account.class);

    String value = form.getFieldValue("email");
    if (value != null) {
      account.setEmail(value);
    }

    value = form.getFieldValue("username");
    if (value != null) {
      account.setUsername(value);
    }

    value = form.getFieldValue("password");
    if (value != null) {
      account.setPassword(value);
    }

    value = form.getFieldValue("givenName");
    account.setGivenName(value != null ? value : "UNKNOWN");

    value = form.getFieldValue("middleName");
    if (value != null) {
      account.setMiddleName(value);
    }

    value = form.getFieldValue("surname");
    account.setSurname(value != null ? value : "UNKNOWN");

    account.getCustomData().putAll(getCustomData(req, form));

    // Get the Stormpath Application instance corresponding to this web app:
    Application app = ApplicationResolver.INSTANCE.getApplication(req);

    if (preRegisterHandler != null) {
      if (!preRegisterHandler.handle(req, resp, account)) {
        return null;
      }
    }

    AccountStore accountStore = accountStoreResolver.getAccountStore(req, resp);

    if (accountStore == null) {
      // now persist the new account, and ensure our account reference points to the newly
      // created/returned instance:
      account = app.createAccount(account);
    } else {
      final Account[] accountHolder = new Account[] {account};

      accountStore.accept(
          new AccountStoreVisitorAdapter() {
            @Override
            public void visit(Directory directory) {
              Account createdAccount = directory.createAccount(accountHolder[0]);
              accountHolder[0] = createdAccount;
            }

            @Override
            public void visit(Organization organization) {
              Account createdAccount = organization.createAccount(accountHolder[0]);
              accountHolder[0] = createdAccount;
            }
          });

      account = accountHolder[0];
    }

    publishRequestEvent(new DefaultRegisteredAccountRequestEvent(req, resp, account));

    if (postRegisterHandler != null) {
      if (!postRegisterHandler.handle(req, resp, account)) {
        return null;
      }
    }

    AccountStatus status = account.getStatus();

    if (isJsonPreferred(req, resp)) {
      //noinspection unchecked
      return new DefaultViewModel(
          STORMPATH_JSON_VIEW_NAME,
          java.util.Collections.singletonMap(
              "account", accountModelFactory.toMap(account, Collections.EMPTY_LIST)));
    }

    if (status == AccountStatus.ENABLED) {
      if (autoLogin) {
        // the user does not need to verify their email address, so just assume they are
        // authenticated
        // (since they specified their password during registration):
        final AuthenticationResult result = new TransientAuthenticationResult(account);
        this.authenticationResultSaver.set(req, resp, result);
      } else {
        return new DefaultViewModel(loginUri + "?status=created").setRedirect(true);
      }
    } else if (status == AccountStatus.UNVERIFIED) {
      return new DefaultViewModel(loginUri + "?status=unverified").setRedirect(true);
    }
    return new DefaultViewModel(nextUri).setRedirect(true);
  }