Search in sources :

Example 1 with Security

use of com.canoo.platform.client.security.Security in project dolphin-platform-examples by canoo.

the class LoginDialog method login.

private void login(final Button button) {
    button.setDisable(true);
    final Security security = PlatformClient.getService(Security.class);
    final String user = userField.getText();
    final String password = passwordField.getText();
    final ExecutorService executor = PlatformClient.getClientConfiguration().getBackgroundExecutor();
    executor.execute(() -> {
        try {
            security.login(user, password).get();
            Platform.runLater(() -> {
                setResult(true);
                hide();
            });
        } catch (Exception e) {
            Platform.runLater(() -> {
                setResult(false);
            });
        } finally {
            Platform.runLater(() -> {
                button.setDisable(false);
            });
        }
    });
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) Security(com.canoo.platform.client.security.Security)

Example 2 with Security

use of com.canoo.platform.client.security.Security in project dolphin-platform-examples by canoo.

the class Client method main.

public static void main(String[] args) throws Exception {
    final HttpClient client = PlatformClient.getService(HttpClient.class);
    final String message = client.get("http://localhost:8080/api/message").withoutContent().readString().execute().get().getContent();
    System.out.println(message);
    final Security security = PlatformClient.getService(Security.class);
    security.login("admin", "admin").get();
    final String message2 = client.get("http://localhost:8080/api/secure/message").withoutContent().readString().execute().get().getContent();
    System.out.println(message2);
}
Also used : HttpClient(com.canoo.platform.core.http.HttpClient) Security(com.canoo.platform.client.security.Security)

Aggregations

Security (com.canoo.platform.client.security.Security)2 HttpClient (com.canoo.platform.core.http.HttpClient)1 ExecutorService (java.util.concurrent.ExecutorService)1