/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.guacamole.auth.quickconnect;

import java.util.Collections;
import java.util.Map;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.AuthenticatedUser;
import org.apache.guacamole.net.auth.Credentials;
import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
import org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
import org.apache.guacamole.net.auth.simple.SimpleAuthenticationProvider;
import org.apache.guacamole.net.auth.UserContext;
import org.apache.guacamole.protocol.GuacamoleConfiguration;

/**
 * Class providing the necessary hooks into the Guacamole Client authentication
 * process so that the QuickConnect functionality can be initialized and be used
 * throughout the web client.
 */
public class QuickConnectAuthenticationProvider extends SimpleAuthenticationProvider {

    /**
     * userContext for this authentication provider.
     */
    private UserContext userContext;

    @Override
    public String getIdentifier() {
        return "quickconnect";
    }

    /**
     * For QuickConnect, authenticateUser simply returns null because this
     * extension is designed to provide only a connection directory to users
     * that are already authenticated and not any actual authentication.
     *
     * @param credentials
     *     Credentials object passed in from Guacamole login.
     *
     * @return
     *     Returns null, which causes the client to move on to the next
     *     module.
     */
    @Override
    public AuthenticatedUser authenticateUser(Credentials credentials)
        throws GuacamoleException {

        return null;

    }

    @Override
    public Map<String, GuacamoleConfiguration>
        getAuthorizedConfigurations(Credentials credentials)
        throws GuacamoleException {

        return Collections.<String, GuacamoleConfiguration>emptyMap();

    }

    @Override
    public UserContext getUserContext(AuthenticatedUser authenticatedUser)
            throws GuacamoleException {

        return new QuickConnectUserContext(this, authenticatedUser.getIdentifier());

    }

}

@@ -1003,24 +1003,85 @@
 icatedUser;%0A
+import org.apache.guacamole.net.auth.AuthenticationProvider;%0A
 import org.a
@@ -1275,82 +1275,8 @@
 on;%0A
-import org.apache.guacamole.net.auth.simple.SimpleAuthenticationProvider;%0A
 impo
@@ -1634,22 +1634,19 @@
 der 
-extend
+implement
 s 
-Simple
 Auth
@@ -1858,24 +1858,126 @@
 ct%22;%0A    %7D%0A%0A
+    @Override%0A    public Object getResource() throws GuacamoleException %7B%0A        return null;%0A    %7D%0A%0A
     /**%0A    
@@ -2593,43 +2593,433 @@
 lic 
-Map%3CString, GuacamoleConfiguration%3E
+UserContext getUserContext(AuthenticatedUser authenticatedUser)%0A            throws GuacamoleException %7B%0A%0A        return new QuickConnectUserContext(this, authenticatedUser.getIdentifier());%0A%0A    %7D%0A%0A    @Override%0A    public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser,%0A            Credentials credentials) throws GuacamoleException %7B%0A%0A        // Simply return the given user, updating nothing
 %0A   
@@ -3027,36 +3027,160 @@
     
-getAuthorizedConfigurations(
+return authenticatedUser;%0A%0A    %7D%0A%0A    @Override%0A    public UserContext updateUserContext(UserContext context,%0A        AuthenticatedUser authorizedUser, 
 Cred
@@ -3192,32 +3192,36 @@
 ls credentials)%0A
+    
         throws G
@@ -3253,69 +3253,83 @@
     
-return Collections.%3CString, GuacamoleConfiguration%3EemptyMap()
+// Simply return the given context, updating nothing%0A        return context
 ;%0A%0A 
@@ -3363,35 +3363,41 @@
 lic UserContext 
-get
+decorate(
 UserContext(Auth
@@ -3383,33 +3383,54 @@
 rate(UserContext
-(
+ context,%0A            
 AuthenticatedUse
@@ -3440,32 +3440,57 @@
 uthenticatedUser
+, Credentials credentials
 )%0A            th
@@ -3528,85 +3528,448 @@
     
-return new QuickConnectUserContext(this, authenticatedUser.getIdentifier());%0A
+// Simply return the given context, decorating nothing%0A        return context;%0A%0A    %7D%0A%0A    @Override%0A    public UserContext redecorate(UserContext decorated, UserContext context,%0A            AuthenticatedUser authenticatedUser, Credentials credentials)%0A            throws GuacamoleException %7B%0A        return decorate(context, authenticatedUser, credentials);%0A    %7D%0A%0A    @Override%0A    public void shutdown() %7B%0A        // Nothing to do, here.
 %0A   

Implement the AuthenticationProvider instead of extending another.