mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
Merge pull request #324 from glyptodon/time-tokens
GUAC-1451: Add support for GUAC_DATE and GUAC_TIME tokens.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Glyptodon LLC
|
* Copyright (C) 2016 Glyptodon LLC
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
package org.glyptodon.guacamole.token;
|
package org.glyptodon.guacamole.token;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import org.glyptodon.guacamole.net.auth.Credentials;
|
import org.glyptodon.guacamole.net.auth.Credentials;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,12 +37,36 @@ public class StandardTokens {
|
|||||||
/**
|
/**
|
||||||
* The name of the username token added via addStandardTokens().
|
* The name of the username token added via addStandardTokens().
|
||||||
*/
|
*/
|
||||||
private static final String USERNAME_TOKEN = "GUAC_USERNAME";
|
public static final String USERNAME_TOKEN = "GUAC_USERNAME";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the password token added via addStandardTokens().
|
* The name of the password token added via addStandardTokens().
|
||||||
*/
|
*/
|
||||||
private static final String PASSWORD_TOKEN = "GUAC_PASSWORD";
|
public static final String PASSWORD_TOKEN = "GUAC_PASSWORD";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the date token (server-local time) added via
|
||||||
|
* addStandardTokens().
|
||||||
|
*/
|
||||||
|
public static final String DATE_TOKEN = "GUAC_DATE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the time token (server-local time) added via
|
||||||
|
* addStandardTokens().
|
||||||
|
*/
|
||||||
|
public static final String TIME_TOKEN = "GUAC_TIME";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date format that should be used for the date token. This format must
|
||||||
|
* be compatible with Java's SimpleDateFormat.
|
||||||
|
*/
|
||||||
|
private static final String DATE_FORMAT = "yyyyMMdd";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date format that should be used for the time token. This format must
|
||||||
|
* be compatible with Java's SimpleDateFormat.
|
||||||
|
*/
|
||||||
|
private static final String TIME_FORMAT = "HHmmss";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This utility class should not be instantiated.
|
* This utility class should not be instantiated.
|
||||||
@@ -48,18 +74,37 @@ public class StandardTokens {
|
|||||||
private StandardTokens() {}
|
private StandardTokens() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the standard username (GUAC_USERNAME) and password (GUAC_PASSWORD)
|
* Adds tokens which are standardized by guacamole-ext to the given
|
||||||
* tokens to the given TokenFilter using the values from the given
|
* TokenFilter and which do not require a corresponding Credentials object.
|
||||||
* Credentials object. If either the username or password are not set
|
* These the server date and time (GUAC_DATE and GUAC_TIME respectively).
|
||||||
|
*
|
||||||
|
* @param filter
|
||||||
|
* The TokenFilter to add standard tokens to.
|
||||||
|
*/
|
||||||
|
public static void addStandardTokens(TokenFilter filter) {
|
||||||
|
|
||||||
|
// Add date/time tokens (server-local time)
|
||||||
|
Date currentTime = new Date();
|
||||||
|
filter.setToken(DATE_TOKEN, new SimpleDateFormat(DATE_FORMAT).format(currentTime));
|
||||||
|
filter.setToken(TIME_TOKEN, new SimpleDateFormat(TIME_FORMAT).format(currentTime));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds tokens which are standardized by guacamole-ext to the given
|
||||||
|
* TokenFilter using the values from the given Credentials object. These
|
||||||
|
* standardized tokens include the current username (GUAC_USERNAME),
|
||||||
|
* password (GUAC_PASSWORD), and the server date and time (GUAC_DATE and
|
||||||
|
* GUAC_TIME respectively). If either the username or password are not set
|
||||||
* within the given credentials, the corresponding token(s) will remain
|
* within the given credentials, the corresponding token(s) will remain
|
||||||
* unset.
|
* unset.
|
||||||
*
|
*
|
||||||
* @param filter
|
* @param filter
|
||||||
* The TokenFilter to add standard username/password tokens to.
|
* The TokenFilter to add standard tokens to.
|
||||||
*
|
*
|
||||||
* @param credentials
|
* @param credentials
|
||||||
* The Credentials containing the username/password to add.
|
* The Credentials to use when populating the GUAC_USERNAME and
|
||||||
*
|
* GUAC_PASSWORD tokens.
|
||||||
*/
|
*/
|
||||||
public static void addStandardTokens(TokenFilter filter, Credentials credentials) {
|
public static void addStandardTokens(TokenFilter filter, Credentials credentials) {
|
||||||
|
|
||||||
@@ -73,7 +118,9 @@ public class StandardTokens {
|
|||||||
if (password != null)
|
if (password != null)
|
||||||
filter.setToken(PASSWORD_TOKEN, password);
|
filter.setToken(PASSWORD_TOKEN, password);
|
||||||
|
|
||||||
|
// Add any tokens which do not require credentials
|
||||||
|
addStandardTokens(filter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user