-
Notifications
You must be signed in to change notification settings - Fork 2
user authentication
Previous examples - in this wiki - assumed a webPDF server, that allowed anonymous user logins (AnonymousAuthProvider) - meaning the server grants access to unauthenticated (unknown) users. Depending on you server configuration anonymous logins may be disallowed.
Should the server require a login via username and password, you should provide a "UserAuthProvider" to your session.
The usage is identical for REST and SOAP - hence only a REST usage example shall be provided:
// ...
AuthProvider authProvider = new UserAuthProvider("User123", "password");
try (RestSession<RestDocument> session = SessionFactory.createInstance(sessionContext, authProvider)) {
// ...
} catch (ResultException ex) {
// ...
}A UserAuthProvider will automatically use the provided authentication data, to login to the server. It will store the session access token - that the server provides for a valid authentication. It will also automatically refresh such a token should it expire.
You might also want to set a skew time for the token refreshing, to avoid expiry issues caused by transfer delays.
// Set the token refresh skew time in seconds.
SessionContext sessionContext = new SessionContext(WebServiceProtocol.REST,new URL("http://localhost:8080/webPDF/"))
.setSkewTime(5);