71 lines
1.8 KiB
Java
71 lines
1.8 KiB
Java
package envoy.data;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* Wraps any request sent to the server in the authentication details of a user.
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @param <T> the type of object to be sent
|
|
* @since Envoy Common v0.3-beta
|
|
*/
|
|
public final class AuthenticatedRequest<T extends Serializable> implements Serializable {
|
|
|
|
private final T request;
|
|
private final String authentication;
|
|
private final long userID;
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
/**
|
|
* @param request the actual object that should be sent
|
|
* @param userID the ID of the currently logged in user
|
|
* @param authentication the authentication of the currently logged in user
|
|
* @since Envoy Common v0.3-beta
|
|
*/
|
|
public AuthenticatedRequest(T request, long userID, String authentication) {
|
|
this.request = Objects.requireNonNull(request);
|
|
this.userID = userID;
|
|
this.authentication = authentication == null ? "" : authentication;
|
|
}
|
|
|
|
/**
|
|
* @return the authentication token of the currently logged in user
|
|
* @since Envoy Common v0.3-beta
|
|
*/
|
|
public String getAuthentication() { return authentication; }
|
|
|
|
/**
|
|
* @return the request
|
|
* @since Envoy Common v0.3-beta
|
|
*/
|
|
public T getRequest() { return request; }
|
|
|
|
/**
|
|
* @return the userID
|
|
* @since Envoy Common v0.3-beta
|
|
*/
|
|
public long getUserID() { return userID; }
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(request, userID);
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (this == obj)
|
|
return true;
|
|
if (!(obj instanceof AuthenticatedRequest))
|
|
return false;
|
|
AuthenticatedRequest<?> other = (AuthenticatedRequest<?>) obj;
|
|
return userID == other.userID;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "AuthenticatedRequest [request=" + request + ", userID=" + userID + "]";
|
|
}
|
|
}
|