Skip to content

Instantly share code, notes, and snippets.

@eldermoraes
Created December 13, 2018 15:19
Show Gist options
  • Save eldermoraes/07450835f628142e99bb427139c584a4 to your computer and use it in GitHub Desktop.
Save eldermoraes/07450835f628142e99bb427139c584a4 to your computer and use it in GitHub Desktop.
@Stateless
public class AuthImpl implements Auth {
private String URL = "http://localhost:8080/javaEE8ExampleSSOAppService/resources/auth";
@Override
public boolean isLogged(String token) {
return prepareWebTarget().path("/" + token)
.request()
.head().getStatus() == 200;
}
@Override
public String login(String login, String password) {
return prepareWebTarget()
.request()
.post(Entity.form(new Form("login", login)
.param("password", password)),
String.class);
}
@Override
public String logout(String token) {
return prepareWebTarget().path("/" + token)
.request()
.delete(String.class);
}
protected WebTarget prepareWebTarget() {
return ClientBuilder.newClient().target(URL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment