/*
 * Copyright (C) 2015 Glyptodon LLC
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package org.glyptodon.guacamole.token;

import org.glyptodon.guacamole.net.auth.Credentials;

/**
 * Utility class which provides access to standardized token names, as well as
 * facilities for generating those tokens from common objects.
 *
 * @author Michael Jumper
 */
public class StandardTokens {

    /**
     * The name of the username token added via addStandardTokens().
     */
    private static final String USERNAME_TOKEN = "GUAC_USERNAME";

    /**
     * The name of the password token added via addStandardTokens().
     */
    private static final String PASSWORD_TOKEN = "GUAC_PASSWORD";

    /**
     * This utility class should not be instantiated.
     */
    private StandardTokens() {}

    /**
     * Adds the standard username (GUAC_USERNAME) and password (GUAC_PASSWORD)
     * tokens to the given TokenFilter using the values from the given
     * Credentials object. If either the username or password are not set
     * within the given credentials, the corresponding token(s) will remain
     * unset.
     *
     * @param filter
     *     The TokenFilter to add standard username/password tokens to.
     *
     * @param credentials
     *     The Credentials containing the username/password to add.
     *
     */
    public static void addStandardTokens(TokenFilter filter, Credentials credentials) {

        // Add username token
        String username = credentials.getUsername();
        if (username != null)
            filter.setToken(USERNAME_TOKEN, username);
        
        // Add password token
        String password = credentials.getPassword();
        if (password != null)
            filter.setToken(PASSWORD_TOKEN, password);
        
    }
    

}

@@ -20,9 +20,9 @@
  201
-5
+6
  Gly
@@ -34,17 +34,16 @@
 n LLC%0A *
- 
 %0A * Perm
@@ -488,17 +488,16 @@
 ions:%0A *
- 
 %0A * The 
@@ -624,17 +624,16 @@
 ware.%0A *
- 
 %0A * THE 
@@ -1152,16 +1152,74 @@
 token;%0A%0A
+import java.text.SimpleDateFormat;%0Aimport java.util.Date;%0A
 import o
@@ -1795,16 +1795,760 @@
     * Th
+e name of the date token (server-local time) added via%0A     * addStandardTokens().%0A     */%0A    private static final String DATE_TOKEN = %22GUAC_DATE%22;%0A%0A    /**%0A     * The name of the time token (server-local time) added via%0A     * addStandardTokens().%0A     */%0A    private static final String TIME_TOKEN = %22GUAC_TIME%22;%0A%0A    /**%0A     * The date format that should be used for the date token. This format must%0A     * be compatible with Java's SimpleDateFormat.%0A     */%0A    private static final String DATE_FORMAT = %22yyyyMMdd%22;%0A%0A    /**%0A     * The date format that should be used for the time token. This format must%0A     * be compatible with Java's SimpleDateFormat.%0A     */%0A    private static final String TIME_FORMAT = %22HHmmss%22;%0A%0A    /**%0A     * Th
 is utili
@@ -2636,102 +2636,28 @@
  /**
-%0A     * Adds the standard username (GUAC_USERNAME) and password (GUAC_PASSWORD)
 %0A     *
+ Adds
  tokens 
 to t
@@ -2652,16 +2652,56 @@
  tokens 
+which are standardized by guacamole-ext 
 to the g
@@ -2704,16 +2704,23 @@
 he given
+%0A     *
  TokenFi
@@ -2755,23 +2755,16 @@
 he given
-%0A     *
  Credent
@@ -2774,16 +2774,204 @@
 s object
+. These%0A     * standardized tokens include the current username (GUAC_USERNAME),%0A     * password (GUAC_PASSWORD), and the server date and time (GUAC_DATE and%0A     * GUAC_TIME respectively)
 . If eit
@@ -3302,23 +3302,16 @@
 to add.%0A
-     *%0A
      */%0A
@@ -3567,24 +3567,16 @@
 rname);%0A
-        
 %0A       
@@ -3736,24 +3736,25 @@
 sword);%0A
+%0A
         
 %0A    %7D%0A 
@@ -3749,19 +3749,281 @@
     
+// Add date/time tokens (server-local time)%0A        Date currentTime = new Date();%0A        filter.setToken(DATE_TOKEN, new SimpleDateFormat(DATE_FORMAT).format(currentTime));%0A        filter.setToken(TIME_TOKEN, new SimpleDateFormat(TIME_FORMAT).format(currentTime));%0A
 %0A    %7D
-%0A    
 %0A%0A%7D%0A

Add standard GUAC_DATE and GUAC_TIME parameter tokens.