GUACAMOLE-5: Map sharing profile model objects to database schema.

This commit is contained in:
Michael Jumper
2016-07-19 13:59:47 -07:00
parent 21f5aba548
commit cfac865807
18 changed files with 1101 additions and 24 deletions

View File

@@ -32,7 +32,6 @@ import org.apache.guacamole.auth.jdbc.user.UserDirectory;
import org.apache.guacamole.auth.jdbc.connectiongroup.ConnectionGroupMapper;
import org.apache.guacamole.auth.jdbc.connection.ConnectionMapper;
import org.apache.guacamole.auth.jdbc.connection.ConnectionRecordMapper;
import org.apache.guacamole.auth.jdbc.connection.ParameterMapper;
import org.apache.guacamole.auth.jdbc.permission.SystemPermissionMapper;
import org.apache.guacamole.auth.jdbc.user.UserMapper;
import org.apache.guacamole.auth.jdbc.connectiongroup.ConnectionGroupService;
@@ -59,6 +58,10 @@ import org.apache.guacamole.auth.jdbc.activeconnection.ActiveConnectionPermissio
import org.apache.guacamole.auth.jdbc.activeconnection.ActiveConnectionPermissionSet;
import org.apache.guacamole.auth.jdbc.activeconnection.ActiveConnectionService;
import org.apache.guacamole.auth.jdbc.activeconnection.TrackedActiveConnection;
import org.apache.guacamole.auth.jdbc.connection.ConnectionParameterMapper;
import org.apache.guacamole.auth.jdbc.permission.SharingProfilePermissionMapper;
import org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileMapper;
import org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileParameterMapper;
import org.apache.guacamole.auth.jdbc.tunnel.RestrictedGuacamoleTunnelService;
import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.mybatis.guice.MyBatisModule;
@@ -118,8 +121,11 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
addMapperClass(ConnectionGroupPermissionMapper.class);
addMapperClass(ConnectionPermissionMapper.class);
addMapperClass(ConnectionRecordMapper.class);
addMapperClass(ParameterMapper.class);
addMapperClass(ConnectionParameterMapper.class);
addMapperClass(SystemPermissionMapper.class);
addMapperClass(SharingProfileMapper.class);
addMapperClass(SharingProfileParameterMapper.class);
addMapperClass(SharingProfilePermissionMapper.class);
addMapperClass(UserMapper.class);
addMapperClass(UserPermissionMapper.class);

View File

@@ -27,7 +27,7 @@ import org.apache.ibatis.annotations.Param;
*
* @author Michael Jumper
*/
public interface ParameterMapper {
public interface ConnectionParameterMapper {
/**
* Returns a collection of all parameters associated with the connection
@@ -42,7 +42,7 @@ public interface ParameterMapper {
* having the given identifier. This collection will be empty if no
* such connection exists.
*/
Collection<ParameterModel> select(@Param("identifier") String identifier);
Collection<ConnectionParameterModel> select(@Param("identifier") String identifier);
/**
* Inserts each of the parameter model objects in the given collection as
@@ -54,7 +54,7 @@ public interface ParameterMapper {
* @return
* The number of rows inserted.
*/
int insert(@Param("parameters") Collection<ParameterModel> parameters);
int insert(@Param("parameters") Collection<ConnectionParameterModel> parameters);
/**
* Deletes all parameters associated with the connection having the given

View File

@@ -24,7 +24,7 @@ package org.apache.guacamole.auth.jdbc.connection;
*
* @author Michael Jumper
*/
public class ParameterModel {
public class ConnectionParameterModel {
/**
* The identifier of the connection associated with this parameter.

View File

@@ -70,7 +70,7 @@ public class ConnectionService extends ModeledGroupedDirectoryObjectService<Mode
* Mapper for accessing connection parameters.
*/
@Inject
private ParameterMapper parameterMapper;
private ConnectionParameterMapper parameterMapper;
/**
* Mapper for accessing connection history.
@@ -197,12 +197,12 @@ public class ConnectionService extends ModeledGroupedDirectoryObjectService<Mode
* A collection of parameter models containing the name/value pairs
* of the given connection's parameters.
*/
private Collection<ParameterModel> getParameterModels(ModeledConnection connection) {
private Collection<ConnectionParameterModel> getParameterModels(ModeledConnection connection) {
Map<String, String> parameters = connection.getConfiguration().getParameters();
// Convert parameters to model objects
Collection<ParameterModel> parameterModels = new ArrayList<ParameterModel>(parameters.size());
Collection<ConnectionParameterModel> parameterModels = new ArrayList<ConnectionParameterModel>(parameters.size());
for (Map.Entry<String, String> parameterEntry : parameters.entrySet()) {
// Get parameter name and value
@@ -214,7 +214,7 @@ public class ConnectionService extends ModeledGroupedDirectoryObjectService<Mode
continue;
// Produce model object from parameter
ParameterModel model = new ParameterModel();
ConnectionParameterModel model = new ConnectionParameterModel();
model.setConnectionIdentifier(connection.getIdentifier());
model.setName(name);
model.setValue(value);
@@ -237,7 +237,7 @@ public class ConnectionService extends ModeledGroupedDirectoryObjectService<Mode
connection.setConfiguration(object.getConfiguration());
// Insert new parameters, if any
Collection<ParameterModel> parameterModels = getParameterModels(connection);
Collection<ConnectionParameterModel> parameterModels = getParameterModels(connection);
if (!parameterModels.isEmpty())
parameterMapper.insert(parameterModels);
@@ -253,7 +253,7 @@ public class ConnectionService extends ModeledGroupedDirectoryObjectService<Mode
super.updateObject(user, object);
// Replace existing parameters with new parameters, if any
Collection<ParameterModel> parameterModels = getParameterModels(object);
Collection<ConnectionParameterModel> parameterModels = getParameterModels(object);
parameterMapper.delete(object.getIdentifier());
if (!parameterModels.isEmpty())
parameterMapper.insert(parameterModels);
@@ -332,7 +332,7 @@ public class ConnectionService extends ModeledGroupedDirectoryObjectService<Mode
// Populate parameter map if we have permission to do so
if (canRetrieveParameters) {
for (ParameterModel parameter : parameterMapper.select(identifier))
for (ConnectionParameterModel parameter : parameterMapper.select(identifier))
parameterMap.put(parameter.getName(), parameter.getValue());
}

View File

@@ -0,0 +1,28 @@
/*
* 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.jdbc.permission;
/**
* Mapper for sharing profile permissions.
*
* @author Michael Jumper
*/
public interface SharingProfilePermissionMapper
extends ObjectPermissionMapper {}

View File

@@ -0,0 +1,91 @@
/*
* 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.jdbc.sharingprofile;
import java.util.Set;
import org.apache.guacamole.auth.jdbc.base.ModeledDirectoryObjectMapper;
import org.apache.guacamole.auth.jdbc.user.UserModel;
import org.apache.ibatis.annotations.Param;
/**
* Mapper for sharing profile objects.
*
* @author Michael Jumper
*/
public interface SharingProfileMapper
extends ModeledDirectoryObjectMapper<SharingProfileModel> {
/**
* Selects the identifiers of all sharing profiles associated with the given
* primary connection, regardless of whether they are readable by any
* particular user. This should only be called on behalf of a system
* administrator. If identifiers are needed by a non-administrative user who
* must have explicit read rights, use selectReadableIdentifiersWithin()
* instead.
*
* @param primaryConnectionIdentifier
* The identifier of the primary connection.
*
* @return
* A Set containing all identifiers of all objects.
*/
Set<String> selectIdentifiersWithin(
@Param("primaryConnectionIdentifier") String primaryConnectionIdentifier);
/**
* Selects the identifiers of all sharing profiles associated with the given
* primary connection that are explicitly readable by the given user. If
* identifiers are needed by a system administrator (who, by definition,
* does not need explicit read rights), use selectIdentifiersWithin()
* instead.
*
* @param user
* The user whose permissions should determine whether an identifier
* is returned.
*
* @param primaryConnectionIdentifier
* The identifier of the primary connection.
*
* @return
* A Set containing all identifiers of all readable objects.
*/
Set<String> selectReadableIdentifiersWithin(@Param("user") UserModel user,
@Param("primaryConnectionIdentifier") String primaryConnectionIdentifier);
/**
* Selects the sharing profile associated with the given primary connection
* and having the given name. If no such sharing profile exists, null is
* returned.
*
* @param primaryConnectionIdentifier
* The identifier of the primary connection to search against.
*
* @param name
* The name of the sharing profile to find.
*
* @return
* The sharing profile having the given name and associated with the
* given primary connection, or null if no such sharing profile exists.
*/
SharingProfileModel selectOneByName(
@Param("primaryConnectionIdentifier") String primaryConnectionIdentifier,
@Param("name") String name);
}

View File

@@ -0,0 +1,112 @@
/*
* 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.jdbc.sharingprofile;
import org.apache.guacamole.auth.jdbc.base.ObjectModel;
/**
* Object representation of a Guacamole sharing profile, as represented in the
* database.
*
* @author Michael Jumper
*/
public class SharingProfileModel extends ObjectModel {
/**
* The human-readable name associated with this sharing profile.
*/
private String name;
/**
* The identifier of the primary connection associated with this
* sharing profile.
*/
private String primaryConnectionIdentifier;
/**
* Creates a new, empty sharing profile.
*/
public SharingProfileModel() {
}
/**
* Returns the name associated with this sharing profile.
*
* @return
* The name associated with this sharing profile.
*/
public String getName() {
return name;
}
/**
* Sets the name associated with this sharing profile.
*
* @param name
* The name to associate with this sharing profile.
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the identifier of the primary connection associated with this
* sharing profile.
*
* @return
* The identifier of the primary connection associated with this
* sharing profile.
*/
public String getPrimaryConnectionIdentifier() {
return primaryConnectionIdentifier;
}
/**
* Sets the identifier of the primary connection associated with this
* sharing profile.
*
* @param primaryConnectionIdentifier
* The identifier of the primary connection associated with this
* sharing profile.
*/
public void setPrimaryConnectionIdentifier(String primaryConnectionIdentifier) {
this.primaryConnectionIdentifier = primaryConnectionIdentifier;
}
@Override
public String getIdentifier() {
// If no associated ID, then no associated identifier
Integer id = getObjectID();
if (id == null)
return null;
// Otherwise, the identifier is the ID as a string
return id.toString();
}
@Override
public void setIdentifier(String identifier) {
throw new UnsupportedOperationException("Sharing profile identifiers "
+ "are derived from IDs. They cannot be set.");
}
}

View File

@@ -0,0 +1,72 @@
/*
* 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.jdbc.sharingprofile;
import java.util.Collection;
import org.apache.ibatis.annotations.Param;
/**
* Mapper for sharing profile parameter objects.
*
* @author Michael Jumper
*/
public interface SharingProfileParameterMapper {
/**
* Returns a collection of all parameters associated with the sharing
* profile having the given identifier.
*
* @param identifier
* The identifier of the sharing profile whose parameters are to be
* retrieved.
*
* @return
* A collection of all parameters associated with the sharing profile
* having the given identifier. This collection will be empty if no
* such sharing profile exists.
*/
Collection<SharingProfileParameterModel> select(@Param("identifier") String identifier);
/**
* Inserts each of the parameter model objects in the given collection as
* new sharing profile parameters.
*
* @param parameters
* The sharing profile parameters to insert.
*
* @return
* The number of rows inserted.
*/
int insert(@Param("parameters") Collection<SharingProfileParameterModel> parameters);
/**
* Deletes all parameters associated with the sharing profile having the
* given identifier.
*
* @param identifier
* The identifier of the sharing profile whose parameters should be
* deleted.
*
* @return
* The number of rows deleted.
*/
int delete(@Param("identifier") String identifier);
}

View File

@@ -0,0 +1,108 @@
/*
* 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.jdbc.sharingprofile;
/**
* A single parameter name/value pair belonging to a sharing profile.
*
* @author Michael Jumper
*/
public class SharingProfileParameterModel {
/**
* The identifier of the sharing profile associated with this parameter.
*/
private String sharingProfileIdentifier;
/**
* The name of the parameter.
*/
private String name;
/**
* The value the parameter is set to.
*/
private String value;
/**
* Returns the identifier of the sharing profile associated with this
* parameter.
*
* @return
* The identifier of the sharing profile associated with this
* parameter.
*/
public String getSharingProfileIdentifier() {
return sharingProfileIdentifier;
}
/**
* Sets the identifier of the sharing profile associated with this
* parameter.
*
* @param sharingProfileIdentifier
* The identifier of the sharing profile to associate with this
* parameter.
*/
public void setSharingProfileIdentifier(String sharingProfileIdentifier) {
this.sharingProfileIdentifier = sharingProfileIdentifier;
}
/**
* Returns the name of this parameter.
*
* @return
* The name of this parameter.
*/
public String getName() {
return name;
}
/**
* Sets the name of this parameter.
*
* @param name
* The name of this parameter.
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the value of this parameter.
*
* @return
* The value of this parameter.
*/
public String getValue() {
return value;
}
/**
* Sets the value of this parameter.
*
* @param value
* The value of this parameter.
*/
public void setValue(String value) {
this.value = value;
}
}

View File

@@ -35,10 +35,9 @@ import org.apache.guacamole.auth.jdbc.user.AuthenticatedUser;
import org.apache.guacamole.auth.jdbc.connection.ModeledConnection;
import org.apache.guacamole.auth.jdbc.connectiongroup.ModeledConnectionGroup;
import org.apache.guacamole.auth.jdbc.connection.ConnectionRecordMapper;
import org.apache.guacamole.auth.jdbc.connection.ParameterMapper;
import org.apache.guacamole.auth.jdbc.connection.ConnectionModel;
import org.apache.guacamole.auth.jdbc.connection.ConnectionRecordModel;
import org.apache.guacamole.auth.jdbc.connection.ParameterModel;
import org.apache.guacamole.auth.jdbc.connection.ConnectionParameterModel;
import org.apache.guacamole.auth.jdbc.user.UserModel;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleSecurityException;
@@ -55,6 +54,7 @@ import org.apache.guacamole.protocol.GuacamoleConfiguration;
import org.apache.guacamole.token.StandardTokens;
import org.apache.guacamole.token.TokenFilter;
import org.mybatis.guice.transactional.Transactional;
import org.apache.guacamole.auth.jdbc.connection.ConnectionParameterMapper;
/**
@@ -88,7 +88,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
* Mapper for accessing connection parameters.
*/
@Inject
private ParameterMapper parameterMapper;
private ConnectionParameterMapper parameterMapper;
/**
* Mapper for accessing connection history.
@@ -217,8 +217,8 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
config.setProtocol(model.getProtocol());
// Set parameters from associated data
Collection<ParameterModel> parameters = parameterMapper.select(connection.getIdentifier());
for (ParameterModel parameter : parameters)
Collection<ConnectionParameterModel> parameters = parameterMapper.select(connection.getIdentifier());
for (ConnectionParameterModel parameter : parameters)
config.setParameter(parameter.getName(), parameter.getValue());
// Build token filter containing credential tokens