2019-12-29 10:47:35 +01:00
|
|
|
package envoy.data;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
2020-07-16 17:04:35 +02:00
|
|
|
import java.time.Instant;
|
2019-12-29 10:47:35 +01:00
|
|
|
|
|
|
|
/**
|
2020-10-19 18:17:51 +02:00
|
|
|
* Contains a {@link User}'s login / registration information as well as the client version.
|
2020-07-08 12:32:24 +02:00
|
|
|
* <p>
|
2020-10-19 18:17:51 +02:00
|
|
|
* If the authentication is performed with a token, the token is stored instead of the password.
|
2019-12-30 18:49:48 +01:00
|
|
|
*
|
2019-12-29 10:47:35 +01:00
|
|
|
* @author Kai S. K. Engelbart
|
|
|
|
* @since Envoy Common v0.2-alpha
|
|
|
|
*/
|
2020-07-08 12:32:24 +02:00
|
|
|
public final class LoginCredentials implements Serializable {
|
2019-12-29 10:47:35 +01:00
|
|
|
|
2020-07-08 12:32:24 +02:00
|
|
|
private final String identifier, password, clientVersion;
|
2020-10-22 23:05:51 +02:00
|
|
|
private final boolean registration, token;
|
2020-07-16 17:04:35 +02:00
|
|
|
private final Instant lastSync;
|
2019-12-29 10:47:35 +01:00
|
|
|
|
2020-09-19 09:13:04 +02:00
|
|
|
private static final long serialVersionUID = 4;
|
2019-12-31 10:16:52 +01:00
|
|
|
|
2020-10-19 18:17:51 +02:00
|
|
|
private LoginCredentials(String identifier, String password, boolean registration,
|
2020-10-22 23:05:51 +02:00
|
|
|
boolean token, String clientVersion,
|
2020-10-19 18:17:51 +02:00
|
|
|
Instant lastSync) {
|
2020-09-18 11:29:05 +02:00
|
|
|
this.identifier = identifier;
|
|
|
|
this.password = password;
|
|
|
|
this.registration = registration;
|
|
|
|
this.token = token;
|
|
|
|
this.clientVersion = clientVersion;
|
|
|
|
this.lastSync = lastSync;
|
|
|
|
}
|
|
|
|
|
2019-12-29 10:47:35 +01:00
|
|
|
/**
|
2020-09-18 11:29:05 +02:00
|
|
|
* Creates login credentials for a regular login.
|
2019-12-30 18:49:48 +01:00
|
|
|
*
|
2020-06-19 15:56:45 +02:00
|
|
|
* @param identifier the identifier of the user
|
2020-07-08 12:32:24 +02:00
|
|
|
* @param password the password of the user
|
2020-06-19 15:56:45 +02:00
|
|
|
* @param clientVersion the version of the client sending these credentials
|
2020-09-18 11:29:05 +02:00
|
|
|
* @param lastSync the timestamp of the last synchronization
|
|
|
|
* @return the created login credentials
|
2020-07-16 17:04:35 +02:00
|
|
|
* @since Envoy Common v0.2-beta
|
2019-12-29 10:47:35 +01:00
|
|
|
*/
|
2020-10-22 23:05:51 +02:00
|
|
|
public static LoginCredentials login(String identifier, String password,
|
2020-10-19 18:17:51 +02:00
|
|
|
String clientVersion, Instant lastSync) {
|
2020-10-22 23:05:51 +02:00
|
|
|
return new LoginCredentials(identifier, password, false, false, clientVersion,
|
2020-10-19 18:17:51 +02:00
|
|
|
lastSync);
|
2020-09-18 11:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates login credentials for a login with an authentication token.
|
|
|
|
*
|
|
|
|
* @param identifier the identifier of the user
|
|
|
|
* @param token the authentication token of the user
|
|
|
|
* @param clientVersion the version of the client sending these credentials
|
|
|
|
* @param lastSync the timestamp of the last synchronization
|
|
|
|
* @return the created login credentials
|
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
2020-10-19 18:17:51 +02:00
|
|
|
public static LoginCredentials loginWithToken(String identifier, String token,
|
|
|
|
String clientVersion, Instant lastSync) {
|
2020-10-22 23:05:51 +02:00
|
|
|
return new LoginCredentials(identifier, token, false, true, clientVersion, lastSync);
|
2020-09-18 11:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates login credentials for a registration.
|
|
|
|
*
|
|
|
|
* @param identifier the identifier of the user
|
|
|
|
* @param password the password of the user
|
|
|
|
* @param clientVersion the version of the client sending these credentials
|
|
|
|
* @param lastSync the timestamp of the last synchronization
|
|
|
|
* @return the created login credentials
|
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
2020-10-19 18:17:51 +02:00
|
|
|
public static LoginCredentials registration(String identifier, String password,
|
2020-10-22 23:05:51 +02:00
|
|
|
String clientVersion, Instant lastSync) {
|
|
|
|
return new LoginCredentials(identifier, password, true, false, clientVersion,
|
2020-10-19 18:17:51 +02:00
|
|
|
lastSync);
|
2019-12-29 10:47:35 +01:00
|
|
|
}
|
|
|
|
|
2019-12-30 18:49:48 +01:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2020-10-19 18:17:51 +02:00
|
|
|
return String.format(
|
2020-10-22 23:05:51 +02:00
|
|
|
"LoginCredentials[identifier=%s,registration=%b,token=%b,clientVersion=%s,lastSync=%s]",
|
2020-10-19 18:17:51 +02:00
|
|
|
identifier,
|
|
|
|
registration,
|
|
|
|
token,
|
|
|
|
clientVersion,
|
|
|
|
lastSync);
|
2019-12-29 10:47:35 +01:00
|
|
|
}
|
2019-12-31 10:20:35 +01:00
|
|
|
|
|
|
|
/**
|
2020-02-07 22:37:48 +01:00
|
|
|
* @return the identifier of the user performing the login
|
2019-12-31 10:20:35 +01:00
|
|
|
* @since Envoy Common v0.2-alpha
|
|
|
|
*/
|
2020-02-07 22:37:48 +01:00
|
|
|
public String getIdentifier() { return identifier; }
|
2019-12-31 10:20:35 +01:00
|
|
|
|
|
|
|
/**
|
2020-07-08 12:32:24 +02:00
|
|
|
* @return the password of the user performing the login
|
|
|
|
* @since Envoy Common v0.1-beta
|
2019-12-31 10:20:35 +01:00
|
|
|
*/
|
2020-07-08 12:32:24 +02:00
|
|
|
public String getPassword() { return password; }
|
2020-01-18 10:27:29 +01:00
|
|
|
|
|
|
|
/**
|
2020-10-19 18:17:51 +02:00
|
|
|
* @return {@code true} if these credentials are used for user registration instead of user
|
|
|
|
* login
|
2020-01-18 10:27:29 +01:00
|
|
|
* @since Envoy Common v0.2-alpha
|
|
|
|
*/
|
|
|
|
public boolean isRegistration() { return registration; }
|
2020-06-19 15:56:45 +02:00
|
|
|
|
2020-09-18 11:29:05 +02:00
|
|
|
/**
|
2020-10-19 18:17:51 +02:00
|
|
|
* @return {@code true} if these credentials use an authentication token instead of a password
|
2020-09-18 11:29:05 +02:00
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
2020-10-19 18:17:51 +02:00
|
|
|
public boolean usesToken() {
|
|
|
|
return token;
|
|
|
|
}
|
2020-09-18 11:29:05 +02:00
|
|
|
|
2020-06-19 15:56:45 +02:00
|
|
|
/**
|
|
|
|
* @return the version of the client sending these credentials
|
|
|
|
* @since Envoy Common v0.1-beta
|
|
|
|
*/
|
|
|
|
public String getClientVersion() { return clientVersion; }
|
2020-07-16 17:04:35 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-19 09:13:04 +02:00
|
|
|
* @return the timestamp of the last synchronization
|
2020-07-16 17:04:35 +02:00
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
|
|
|
public Instant getLastSync() { return lastSync; }
|
2020-03-22 14:52:38 +01:00
|
|
|
}
|