GUACAMOLE-1643: Validate/translate KSM configs and one-time tokens on connection group save.

This commit is contained in:
James Muehlner
2022-07-20 00:18:26 +00:00
parent 8772207a75
commit b8058e7561
5 changed files with 454 additions and 1 deletions

View File

@@ -0,0 +1,140 @@
/*
* 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.vault.user;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.ActiveConnection;
import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.SharingProfile;
import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.UserGroup;
/**
* A service that allows a vault implementation to override the directory
* for any entity that a user context may return.
*/
public abstract class VaultDirectoryService {
/**
* Given an existing User Directory, return a new Directory for
* this vault implementation.
*
* @return
* A new User Directory based on the provided Directory.
*
* @throws GuacamoleException
* If an error occurs while creating the Directory.
*/
public Directory<User> getUserDirectory(
Directory<User> underlyingDirectory) throws GuacamoleException {
// By default, the provided directly will be returned unchanged
return underlyingDirectory;
}
/**
* Given an existing UserGroup Directory, return a new Directory for
* this vault implementation.
*
* @return
* A new UserGroup Directory based on the provided Directory.
*
* @throws GuacamoleException
* If an error occurs while creating the Directory.
*/
public Directory<UserGroup> getUserGroupDirectory(
Directory<UserGroup> underlyingDirectory) throws GuacamoleException {
// Unless overriden in the vault implementation, the underlying directory
// will be returned directly
return underlyingDirectory;
}
/**
* Given an existing Connection Directory, return a new Directory for
* this vault implementation.
*
* @return
* A new Connection Directory based on the provided Directory.
*
* @throws GuacamoleException
* If an error occurs while creating the Directory.
*/
public Directory<Connection> getConnectionDirectory(
Directory<Connection> underlyingDirectory) throws GuacamoleException {
// By default, the provided directly will be returned unchanged
return underlyingDirectory;
}
/**
* Given an existing ConnectionGroup Directory, return a new Directory for
* this vault implementation.
*
* @return
* A new ConnectionGroup Directory based on the provided Directory.
*
* @throws GuacamoleException
* If an error occurs while creating the Directory.
*/
public Directory<ConnectionGroup> getConnectionGroupDirectory(
Directory<ConnectionGroup> underlyingDirectory) throws GuacamoleException {
// By default, the provided directly will be returned unchanged
return underlyingDirectory;
}
/**
* Given an existing ActiveConnection Directory, return a new Directory for
* this vault implementation.
*
* @return
* A new ActiveConnection Directory based on the provided Directory.
*
* @throws GuacamoleException
* If an error occurs while creating the Directory.
*/
public Directory<ActiveConnection> getActiveConnectionDirectory(
Directory<ActiveConnection> underlyingDirectory) throws GuacamoleException {
// By default, the provided directly will be returned unchanged
return underlyingDirectory;
}
/**
* Given an existing SharingProfile Directory, return a new Directory for
* this vault implementation.
*
* @return
* A new SharingProfile Directory based on the provided Directory.
*
* @throws GuacamoleException
* If an error occurs while creating the Directory.
*/
public Directory<SharingProfile> getSharingProfileDirectory(
Directory<SharingProfile> underlyingDirectory) throws GuacamoleException {
// By default, the provided directly will be returned unchanged
return underlyingDirectory;
}
}

View File

@@ -35,11 +35,16 @@ import java.util.stream.Stream;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.form.Form;
import org.apache.guacamole.net.auth.ActiveConnection;
import org.apache.guacamole.net.auth.Connectable;
import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.SharingProfile;
import org.apache.guacamole.net.auth.TokenInjectingUserContext;
import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.UserContext;
import org.apache.guacamole.net.auth.UserGroup;
import org.apache.guacamole.protocol.GuacamoleConfiguration;
import org.apache.guacamole.token.GuacamoleTokenUndefinedException;
import org.apache.guacamole.token.TokenFilter;
@@ -137,6 +142,13 @@ public class VaultUserContext extends TokenInjectingUserContext {
@Inject
private VaultAttributeService attributeService;
/**
* Service for modifying any underlying directories for the current
* vault implementation.
*/
@Inject
private VaultDirectoryService directoryService;
/**
* Creates a new VaultUserContext which automatically injects tokens
* containing values of secrets retrieved from a vault. The given
@@ -438,4 +450,46 @@ public class VaultUserContext extends TokenInjectingUserContext {
}
@Override
public Directory<User> getUserDirectory() throws GuacamoleException {
// Defer to the vault-specific directory service
return directoryService.getUserDirectory(super.getUserDirectory());
}
@Override
public Directory<UserGroup> getUserGroupDirectory() throws GuacamoleException {
// Defer to the vault-specific directory service
return directoryService.getUserGroupDirectory(super.getUserGroupDirectory());
}
@Override
public Directory<Connection> getConnectionDirectory() throws GuacamoleException {
// Defer to the vault-specific directory service
return directoryService.getConnectionDirectory(super.getConnectionDirectory());
}
@Override
public Directory<ConnectionGroup> getConnectionGroupDirectory() throws GuacamoleException {
// Defer to the vault-specific directory service
return directoryService.getConnectionGroupDirectory(super.getConnectionGroupDirectory());
}
@Override
public Directory<ActiveConnection> getActiveConnectionDirectory() throws GuacamoleException {
// Defer to the vault-specific directory service
return directoryService.getActiveConnectionDirectory(super.getActiveConnectionDirectory());
}
@Override
public Directory<SharingProfile> getSharingProfileDirectory() throws GuacamoleException {
// Defer to the vault-specific directory service
return directoryService.getSharingProfileDirectory(super.getSharingProfileDirectory());
}
}