我可以使用Stormpath Java SDK在strompath中验证用户帐户吗?

时间:2015-12-10 07:15:58

标签: java sdk stormpath

我想验证已经从网络管理控制台创建的用户帐户,以便我可以检索用户帐户的数据。

我已经看过有关身份验证方案的文档,但没有找到任何代码段。

1 个答案:

答案 0 :(得分:4)

以下是使用Stormpath验证现有用户的示例:

// Instantiate a builder for your client and set required properties
ClientBuilder builder = Clients.builder();    

// Build the client instance that you will use throughout your application code
Client client = builder.build();

Tenant tenant = client.getCurrentTenant();
ApplicationList applications = tenant.getApplications(
        Applications.where(Applications.name().eqIgnoreCase("My Application"))
);

Application application = applications.iterator().next();


//Capture the username and password, such as via an SSL-encrypted web HTML form. 
//We'll just simulate a form lookup and use the values we used above:
String usernameOrEmail = "tk421@stormpath.com";
String rawPassword = "Changeme1";

//Create an authentication request using the credentials
AuthenticationRequest request = new UsernamePasswordRequest(usernameOrEmail, rawPassword);

//Now let's authenticate the account with the application:
try {
    AuthenticationResult result = application.authenticateAccount(request);
    Account account = result.getAccount();
} catch (ResourceException ex) {
    System.out.println(ex.getStatus() + " " + ex.getMessage());
}

您可以看到有关Stormpath Java SDK here

的更多信息

完全披露:我为Stormpath工作。

相关问题