org.apache.guacamole.net.auth.AbstractUserContext Maven / Gradle / Ivy
/*
* 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.net.auth;
import java.util.Collection;
import java.util.Collections;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.form.Form;
import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet;
import org.apache.guacamole.net.auth.simple.SimpleConnectionGroup;
import org.apache.guacamole.net.auth.simple.SimpleDirectory;
/**
* Base implementation of UserContext which provides default implementations of
* most functions. Implementations must provide their own {@link #self()} and
* {@link #getAuthenticationProvider()}, but otherwise need only override an
* implemented function if they wish to actually implement the functionality
* defined for that function by the UserContext interface.
*/
public abstract class AbstractUserContext implements UserContext {
/**
* The unique identifier that will be used for the root connection group if
* {@link #getRootConnectionGroup()} is not overridden.
*/
protected static final String DEFAULT_ROOT_CONNECTION_GROUP = "ROOT";
/**
* {@inheritDoc}
*
* This implementation simply returns {@code null}. Implementations that
* wish to expose REST resources specific to a user's session should
* override this function.
*/
@Override
public Object getResource() throws GuacamoleException {
return null;
}
/**
* {@inheritDoc}
*
*
This implementation returns a {@link Directory} which contains only
* the {@link User} returned by {@link #self()} (the current user
* associated with this {@link UserContext}. Implementations that wish to
* expose the existence of other users should override this function.
*/
@Override
public Directory getUserDirectory() throws GuacamoleException {
return new SimpleDirectory(self());
}
/**
* {@inheritDoc}
*
* This implementation simply returns an empty {@link Directory}.
* Implementations that wish to expose user groups should override this
* function.
*/
@Override
public Directory getUserGroupDirectory()
throws GuacamoleException {
return new SimpleDirectory();
}
/**
* {@inheritDoc}
*
* This implementation simply returns an empty {@link Directory}.
* Implementations that wish to expose connections should override this
* function.
*/
@Override
public Directory getConnectionDirectory()
throws GuacamoleException {
return new SimpleDirectory();
}
/**
* {@inheritDoc}
*
* This implementation returns a {@link Directory} which contains only
* the root connection group returned by {@link #getRootConnectionGroup()}.
* Implementations that wish to provide a structured connection hierarchy
* should override this function. If only a flat list of connections will
* be used, only {@link #getConnectionDirectory()} needs to be overridden.
*/
@Override
public Directory getConnectionGroupDirectory()
throws GuacamoleException {
return new SimpleDirectory(getRootConnectionGroup());
}
/**
* {@inheritDoc}
*
* This implementation simply returns an empty {@link Directory}.
* Implementations that wish to expose the status of active connections
* should override this function.
*/
@Override
public Directory getActiveConnectionDirectory()
throws GuacamoleException {
return new SimpleDirectory();
}
/**
* {@inheritDoc}
*
* This implementation simply returns an empty {@link Directory}.
* Implementations that wish to provide screen sharing functionality
* through the use of sharing profiles should override this function.
*/
@Override
public Directory getSharingProfileDirectory()
throws GuacamoleException {
return new SimpleDirectory();
}
/**
* {@inheritDoc}
*
* This implementation simply returns an empty {@link ActivityRecordSet}.
* Implementations that wish to expose connection usage history should
* override this function.
*/
@Override
public ActivityRecordSet getConnectionHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet();
}
/**
* {@inheritDoc}
*
* This implementation simply returns an empty {@link ActivityRecordSet}.
* Implementations that wish to expose user login/logout history should
* override this function.
*/
@Override
public ActivityRecordSet getUserHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet();
}
/**
* {@inheritDoc}
*
* This implementation returns a new {@link ConnectionGroup} with the
* identifier defined by {@link #DEFAULT_ROOT_CONNECTION_GROUP} and
* containing all connections exposed by the {@link Directory} returned by
* {@link #getConnectionDirectory()}. Implementations that wish to provide
* a structured connection hierarchy should override this function. If only
* a flat list of connections will be used, only
* {@link #getConnectionDirectory()} needs to be overridden.
*/
@Override
public ConnectionGroup getRootConnectionGroup()
throws GuacamoleException {
return new SimpleConnectionGroup(
DEFAULT_ROOT_CONNECTION_GROUP,
DEFAULT_ROOT_CONNECTION_GROUP,
getConnectionDirectory().getIdentifiers(),
Collections.emptySet()
);
}
/**
* {@inheritDoc}
*
* This implementation simply returns an empty {@link Collection}.
* Implementations that wish to expose custom user attributes as fields
* within user edit screens should override this function.
*/
@Override
public Collection