1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package org.apache.guacamole.net.auth; 21 22 import org.apache.guacamole.GuacamoleException; 23 24 /** 25 * Base implementation of AuthenticationProvider which provides default 26 * implementations of most functions. Implementations must provide their 27 * own {@link #getIdentifier()}, but otherwise need only override an implemented 28 * function if they wish to actually implement the functionality defined for 29 * that function by the AuthenticationProvider interface. 30 */ 31 public abstract class AbstractAuthenticationProvider implements AuthenticationProvider { 32 33 /** 34 * {@inheritDoc} 35 * 36 * <p>This implementation simply returns {@code null}. Implementations that 37 * wish to expose REST resources which are not specific to a user's session 38 * should override this function. 39 */ 40 @Override getResource()41 public Object getResource() throws GuacamoleException { 42 return null; 43 } 44 45 /** 46 * {@inheritDoc} 47 * 48 * <p>This implementation performs no authentication whatsoever, ignoring 49 * the provided {@code credentials} and simply returning {@code null}. Any 50 * authentication attempt will thus fall through to other 51 * {@link AuthenticationProvider} implementations, perhaps within other 52 * installed extensions, with this {@code AuthenticationProvider} making no 53 * claim regarding the user's identity nor whether the user should be 54 * allowed or disallowed from accessing Guacamole. Implementations that wish 55 * to authenticate users should override this function. 56 */ 57 @Override authenticateUser(Credentials credentials)58 public AuthenticatedUser authenticateUser(Credentials credentials) 59 throws GuacamoleException { 60 return null; 61 } 62 63 /** 64 * {@inheritDoc} 65 * 66 * <p>This implementation simply returns the provided 67 * {@code authenticatedUser} without modification. Implementations that 68 * wish to update a user's {@link AuthenticatedUser} object with respect to 69 * new {@link Credentials} received in requests which follow the initial, 70 * successful authentication attempt should override this function. 71 */ 72 @Override updateAuthenticatedUser(AuthenticatedUser authenticatedUser, Credentials credentials)73 public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser, 74 Credentials credentials) throws GuacamoleException { 75 return authenticatedUser; 76 } 77 78 /** 79 * {@inheritDoc} 80 * 81 * <p>This implementation simply returns {@code null}, effectively allowing 82 * authentication to continue but refusing to provide data for the given 83 * user. Implementations that wish to veto the authentication results of 84 * other {@link AuthenticationProvider} implementations or provide data for 85 * authenticated users should override this function. 86 */ 87 @Override getUserContext(AuthenticatedUser authenticatedUser)88 public UserContext getUserContext(AuthenticatedUser authenticatedUser) 89 throws GuacamoleException { 90 return null; 91 } 92 93 /** 94 * {@inheritDoc} 95 * 96 * <p>This implementation simply returns the provided {@code context} 97 * without modification. Implementations that wish to update a user's 98 * {@link UserContext} object with respect to newly-updated 99 * {@link AuthenticatedUser} or {@link Credentials} (such as those received 100 * in requests which follow the initial, successful authentication attempt) 101 * should override this function. 102 */ 103 @Override updateUserContext(UserContext context, AuthenticatedUser authenticatedUser, Credentials credentials)104 public UserContext updateUserContext(UserContext context, 105 AuthenticatedUser authenticatedUser, 106 Credentials credentials) throws GuacamoleException { 107 return context; 108 } 109 110 /** 111 * {@inheritDoc} 112 * 113 * <p>This implementation simply returns the provided {@code context} 114 * without performing any decoration. Implementations that wish to augment 115 * the functionality or data provided by other 116 * {@link AuthenticationProvider} implementations should override this 117 * function. 118 */ 119 @Override decorate(UserContext context, AuthenticatedUser authenticatedUser, Credentials credentials)120 public UserContext decorate(UserContext context, 121 AuthenticatedUser authenticatedUser, 122 Credentials credentials) throws GuacamoleException { 123 return context; 124 } 125 126 /** 127 * {@inheritDoc} 128 * 129 * <p>This implementation simply invokes 130 * {@link #decorate(UserContext,AuthenticatedUser,Credentials)} with the 131 * provided {@code context}, {@code authenticatedUser}, and 132 * {@code credentials}. Implementations which override 133 * {@link #decorate(UserContext,AuthenticatedUser,Credentials)} and which 134 * need to update their existing decorated object following possible 135 * updates to the {@link UserContext} or {@link AuthenticatedUser} (rather 136 * than generate an entirely new decorated object) should override this 137 * function. 138 */ 139 @Override redecorate(UserContext decorated, UserContext context, AuthenticatedUser authenticatedUser, Credentials credentials)140 public UserContext redecorate(UserContext decorated, UserContext context, 141 AuthenticatedUser authenticatedUser, 142 Credentials credentials) throws GuacamoleException { 143 return decorate(context, authenticatedUser, credentials); 144 } 145 146 /** 147 * {@inheritDoc} 148 * 149 * <p>This implementation does nothing. Implementations that wish to perform 150 * cleanup tasks when the {@link AuthenticationProvider} is being unloaded 151 * should override this function. 152 */ 153 @Override shutdown()154 public void shutdown() { 155 } 156 157 } 158