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

Can I authenticate a user account in strompath using Stormpath Java SDK?

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

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

下面是使用 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 工作。