Package eirb.pub.app.server
Class ServerAuthentication
java.lang.Object
eirb.pub.app.server.ServerAuthentication
Provide an authentication service to the server API After user authentication, provide a header
to be added to every authenticated request
-
Constructor Summary
ConstructorsConstructorDescriptionServerAuthentication(String login, String password) Create an Authentication service for the server Use the login and the password to get an authentication token to the serverServerAuthentication(String login, String password, URL hostname) -
Method Summary
Modifier and TypeMethodDescriptionvoidauthenticate(String login, String password) Authenticate the user to get an authentication token.Get the authenticate userorg.apache.hc.core5.http.HeaderGet Authorization header used for authenticationGet authenticate user KeyPair (used for encryption and decryption purposes)static ServerAuthenticationregister(String mail, String password, String nickname, javafx.util.Callback<String, Integer> getCode) static ServerAuthenticationregister(String mail, String password, String nickname, javafx.util.Callback<String, Integer> retrieveCode, URL hostname) Register a new user on the servervoidsetHostname(URL url)
-
Constructor Details
-
ServerAuthentication
public ServerAuthentication(String login, String password, URL hostname) throws AuthenticationException, IOException, TimeoutException -
ServerAuthentication
public ServerAuthentication(String login, String password) throws IOException, AuthenticationException, TimeoutException Create an Authentication service for the server Use the login and the password to get an authentication token to the server- Parameters:
login- User loginpassword- User password- Throws:
IOException- if the connection with the server failed:AuthenticationException- If the authentication failedTimeoutException
-
-
Method Details
-
setHostname
-
authenticate
public void authenticate(String login, String password) throws IOException, AuthenticationException, TimeoutException Authenticate the user to get an authentication token. Use this method if the token expired and you get AuthenticationErrors- Parameters:
login- User loginpassword- User password- Throws:
IOException- if the request failed or the connection was interruptedAuthenticationException- if the authentication failed (wrong user/login)TimeoutException- if the request took too much time to complete
-
getHeader
public org.apache.hc.core5.http.Header getHeader()Get Authorization header used for authentication- Returns:
- Header with the right token
-
getHostname
-
getUserKeyPair
Get authenticate user KeyPair (used for encryption and decryption purposes)- Returns:
- KeyPair of the authenticated user
-
getAuthenticatedUser
Get the authenticate user- Returns:
- Authenticated user
-
register
public static ServerAuthentication register(String mail, String password, String nickname, javafx.util.Callback<String, Integer> retrieveCode, URL hostname) throws ServerException, IOException, TimeoutExceptionRegister a new user on the server- Parameters:
mail- user mailpassword- user passwordnickname- user nicknameretrieveCode- function to get the verification code received by mail. Can be called multiple times if the verification failed, make it return -1 to stop the verification code loophostname- server hostname- Returns:
- a ServerAuth with the newly created user
- Throws:
VerificationCodeException- if the code provided failedServerException- if the field provided are incorrectTimeoutException- if the request took too much time to completeIOException- If the connection with the server breaks
-
register
public static ServerAuthentication register(String mail, String password, String nickname, javafx.util.Callback<String, Integer> getCode) throws ServerException, IOException, TimeoutException- Throws:
ServerExceptionIOExceptionTimeoutException- See Also:
-