mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 09:03:21 +00:00 
			
		
		
		
	GUACAMOLE-5: Map sharing profile model objects to database schema.
This commit is contained in:
		| @@ -21,10 +21,10 @@ | ||||
|     under the License. | ||||
| --> | ||||
| 
 | ||||
| <mapper namespace="org.apache.guacamole.auth.jdbc.connection.ParameterMapper"> | ||||
| <mapper namespace="org.apache.guacamole.auth.jdbc.connection.ConnectionParameterMapper"> | ||||
| 
 | ||||
|     <!-- Result mapper for connection parameters --> | ||||
|     <resultMap id="ParameterResultMap" type="org.apache.guacamole.auth.jdbc.connection.ParameterModel"> | ||||
|     <resultMap id="ParameterResultMap" type="org.apache.guacamole.auth.jdbc.connection.ConnectionParameterModel"> | ||||
|         <result column="connection_id"   property="connectionIdentifier" jdbcType="INTEGER"/> | ||||
|         <result column="parameter_name"  property="name"                 jdbcType="VARCHAR"/> | ||||
|         <result column="parameter_value" property="value"                jdbcType="VARCHAR"/> | ||||
| @@ -48,7 +48,7 @@ | ||||
|     </delete> | ||||
| 
 | ||||
|     <!-- Insert all given parameters --> | ||||
|     <insert id="insert" parameterType="org.apache.guacamole.auth.jdbc.connection.ParameterModel"> | ||||
|     <insert id="insert" parameterType="org.apache.guacamole.auth.jdbc.connection.ConnectionParameterModel"> | ||||
| 
 | ||||
|         INSERT INTO guacamole_connection_parameter ( | ||||
|             connection_id, | ||||
| @@ -0,0 +1,117 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" ?> | ||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||||
|     "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||||
|  | ||||
| <!-- | ||||
|     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. | ||||
| --> | ||||
|  | ||||
| <mapper namespace="org.apache.guacamole.auth.jdbc.permission.SharingProfilePermissionMapper"> | ||||
|  | ||||
|     <!-- Result mapper for sharig profile permissions --> | ||||
|     <resultMap id="SharingProfilePermissionResultMap" type="org.apache.guacamole.auth.jdbc.permission.ObjectPermissionModel"> | ||||
|         <result column="user_id"            property="userID"           jdbcType="INTEGER"/> | ||||
|         <result column="username"           property="username"         jdbcType="VARCHAR"/> | ||||
|         <result column="permission"         property="type"             jdbcType="VARCHAR" | ||||
|                 javaType="org.apache.guacamole.net.auth.permission.ObjectPermission$Type"/> | ||||
|         <result column="sharing_profile_id" property="objectIdentifier" jdbcType="INTEGER"/> | ||||
|     </resultMap> | ||||
|  | ||||
|     <!-- Select all permissions for a given user --> | ||||
|     <select id="select" resultMap="SharingProfilePermissionResultMap"> | ||||
|  | ||||
|         SELECT | ||||
|             guacamole_sharing_profile_permission.user_id, | ||||
|             username, | ||||
|             permission, | ||||
|             sharing_profile_id | ||||
|         FROM guacamole_sharing_profile_permission | ||||
|         JOIN guacamole_user ON guacamole_sharing_profile_permission.user_id = guacamole_user.user_id | ||||
|         WHERE guacamole_sharing_profile_permission.user_id = #{user.objectID,jdbcType=INTEGER} | ||||
|  | ||||
|     </select> | ||||
|  | ||||
|     <!-- Select the single permission matching the given criteria --> | ||||
|     <select id="selectOne" resultMap="SharingProfilePermissionResultMap"> | ||||
|  | ||||
|         SELECT | ||||
|             guacamole_sharing_profile_permission.user_id, | ||||
|             username, | ||||
|             permission, | ||||
|             sharing_profile_id | ||||
|         FROM guacamole_sharing_profile_permission | ||||
|         JOIN guacamole_user ON guacamole_sharing_profile_permission.user_id = guacamole_user.user_id | ||||
|         WHERE | ||||
|             guacamole_sharing_profile_permission.user_id = #{user.objectID,jdbcType=INTEGER} | ||||
|             AND permission = #{type,jdbcType=VARCHAR} | ||||
|             AND sharing_profile_id = #{identifier,jdbcType=VARCHAR} | ||||
|  | ||||
|     </select> | ||||
|  | ||||
|     <!-- Select identifiers accessible by the given user for the given permissions --> | ||||
|     <select id="selectAccessibleIdentifiers" resultType="string"> | ||||
|  | ||||
|         SELECT DISTINCT sharing_profile_id | ||||
|         FROM guacamole_sharing_profile_permission | ||||
|         WHERE | ||||
|             user_id = #{user.objectID,jdbcType=INTEGER} | ||||
|             AND sharing_profile_id IN | ||||
|                 <foreach collection="identifiers" item="identifier" | ||||
|                          open="(" separator="," close=")"> | ||||
|                     #{identifier,jdbcType=VARCHAR} | ||||
|                 </foreach> | ||||
|             AND permission IN | ||||
|                 <foreach collection="permissions" item="permission" | ||||
|                          open="(" separator="," close=")"> | ||||
|                     #{permission,jdbcType=VARCHAR} | ||||
|                 </foreach> | ||||
|  | ||||
|     </select> | ||||
|  | ||||
|     <!-- Delete all given permissions --> | ||||
|     <delete id="delete" parameterType="org.apache.guacamole.auth.jdbc.permission.ObjectPermissionModel"> | ||||
|  | ||||
|         DELETE FROM guacamole_sharing_profile_permission | ||||
|         WHERE (user_id, permission, sharing_profile_id) IN | ||||
|             <foreach collection="permissions" item="permission" | ||||
|                      open="(" separator="," close=")"> | ||||
|                 (#{permission.userID,jdbcType=INTEGER}, | ||||
|                  #{permission.type,jdbcType=VARCHAR}, | ||||
|                  #{permission.objectIdentifier,jdbcType=VARCHAR}) | ||||
|             </foreach> | ||||
|  | ||||
|     </delete> | ||||
|  | ||||
|     <!-- Insert all given permissions --> | ||||
|     <insert id="insert" parameterType="org.apache.guacamole.auth.jdbc.permission.ObjectPermissionModel"> | ||||
|  | ||||
|         INSERT IGNORE INTO guacamole_sharing_profile_permission ( | ||||
|             user_id, | ||||
|             permission, | ||||
|             sharing_profile_id | ||||
|         ) | ||||
|         VALUES | ||||
|             <foreach collection="permissions" item="permission" separator=","> | ||||
|                 (#{permission.userID,jdbcType=INTEGER}, | ||||
|                  #{permission.type,jdbcType=VARCHAR}, | ||||
|                  #{permission.objectIdentifier,jdbcType=VARCHAR}) | ||||
|             </foreach> | ||||
|  | ||||
|     </insert> | ||||
|  | ||||
| </mapper> | ||||
| @@ -0,0 +1,145 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" ?> | ||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||||
|     "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||||
|  | ||||
| <!-- | ||||
|     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. | ||||
| --> | ||||
|  | ||||
| <mapper namespace="org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileMapper"> | ||||
|  | ||||
|     <!-- Result mapper for sharing profile objects --> | ||||
|     <resultMap id="SharingProfileResultMap" type="org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileModel"> | ||||
|         <id     column="sharing_profile_id"    property="objectID"                    jdbcType="INTEGER"/> | ||||
|         <result column="sharing_profile_name"  property="name"                        jdbcType="VARCHAR"/> | ||||
|         <result column="primary_connection_id" property="primaryConnectionIdentifier" jdbcType="INTEGER"/> | ||||
|     </resultMap> | ||||
|  | ||||
|     <!-- Select all sharing profile identifiers --> | ||||
|     <select id="selectIdentifiers" resultType="string"> | ||||
|         SELECT sharing_profile_id | ||||
|         FROM guacamole_sharing_profile | ||||
|     </select> | ||||
|  | ||||
|     <!-- Select identifiers of all readable sharing profiles --> | ||||
|     <select id="selectReadableIdentifiers" resultType="string"> | ||||
|         SELECT sharing_profile_id | ||||
|         FROM guacamole_sharing_profile_permission | ||||
|         WHERE | ||||
|             user_id = #{user.objectID,jdbcType=INTEGER} | ||||
|             AND permission = 'READ' | ||||
|     </select> | ||||
|  | ||||
|     <!-- Select all sharing profiles identifiers associated with a particular connection --> | ||||
|     <select id="selectIdentifiersWithin" resultType="string"> | ||||
|         SELECT sharing_profile_id | ||||
|         FROM guacamole_sharing_profile | ||||
|         WHERE | ||||
|             primary_connection_id = #{primaryConnectionIdentifier,jdbcType=VARCHAR} | ||||
|     </select> | ||||
|  | ||||
|     <!-- Select identifiers of all readable sharing profiles associated with a particular connection --> | ||||
|     <select id="selectReadableIdentifiersWithin" resultType="string"> | ||||
|         SELECT sharing_profile_id | ||||
|         FROM guacamole_sharing_profile | ||||
|         JOIN guacamole_sharing_profile_permission ON guacamole_sharing_profile_permission.sharing_profile_id = guacamole_sharing_profile.sharing_profile_id | ||||
|         WHERE | ||||
|             primary_connection_id = #{primaryConnectionIdentifier,jdbcType=VARCHAR} | ||||
|             AND user_id = #{user.objectID,jdbcType=INTEGER} | ||||
|             AND permission = 'READ' | ||||
|     </select> | ||||
|  | ||||
|     <!-- Select multiple sharing profiles by identifier --> | ||||
|     <select id="select" resultMap="SharingProfileResultMap"> | ||||
|  | ||||
|         SELECT | ||||
|             sharing_profile_id, | ||||
|             sharing_profile_name, | ||||
|             primary_connection_id | ||||
|         FROM guacamole_sharing_profile | ||||
|         WHERE sharing_profile_id IN | ||||
|             <foreach collection="identifiers" item="identifier" | ||||
|                      open="(" separator="," close=")"> | ||||
|                 #{identifier,jdbcType=VARCHAR} | ||||
|             </foreach> | ||||
|  | ||||
|     </select> | ||||
|  | ||||
|     <!-- Select multiple sharing profiles by identifier only if readable --> | ||||
|     <select id="selectReadable" resultMap="SharingProfileResultMap"> | ||||
|  | ||||
|         SELECT | ||||
|             guacamole_sharing_profile.sharing_profile_id, | ||||
|             guacamole_sharing_profile.sharing_profile_name, | ||||
|             primary_connection_id | ||||
|         FROM guacamole_sharing_profile | ||||
|         JOIN guacamole_sharing_profile_permission ON guacamole_sharing_profile_permission.sharing_profile_id = guacamole_sharing_profile.sharing_profile_id | ||||
|         WHERE guacamole_sharing_profile.sharing_profile_id IN | ||||
|             <foreach collection="identifiers" item="identifier" | ||||
|                      open="(" separator="," close=")"> | ||||
|                 #{identifier,jdbcType=VARCHAR} | ||||
|             </foreach> | ||||
|             AND user_id = #{user.objectID,jdbcType=INTEGER} | ||||
|             AND permission = 'READ' | ||||
|  | ||||
|     </select> | ||||
|  | ||||
|     <!-- Select single sharing profile by name --> | ||||
|     <select id="selectOneByName" resultMap="SharingProfileResultMap"> | ||||
|  | ||||
|         SELECT | ||||
|             sharing_profile_id, | ||||
|             sharing_profile_name, | ||||
|             primary_connection_id | ||||
|         FROM guacamole_sharing_profile | ||||
|         WHERE  | ||||
|             primary_connection_id = #{primaryConnectionIdentifier,jdbcType=VARCHAR} | ||||
|             AND sharing_profile_name = #{name,jdbcType=VARCHAR} | ||||
|  | ||||
|     </select> | ||||
|  | ||||
|     <!-- Delete single sharing profile by identifier --> | ||||
|     <delete id="delete"> | ||||
|         DELETE FROM guacamole_sharing_profile | ||||
|         WHERE sharing_profile_id = #{identifier,jdbcType=VARCHAR} | ||||
|     </delete> | ||||
|  | ||||
|     <!-- Insert single sharing profile --> | ||||
|     <insert id="insert" useGeneratedKeys="true" keyProperty="object.objectID" | ||||
|             parameterType="org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileModel"> | ||||
|  | ||||
|         INSERT INTO guacamole_sharing_profile ( | ||||
|             sharing_profile_name, | ||||
|             primary_connection_id | ||||
|         ) | ||||
|         VALUES ( | ||||
|             #{object.name,jdbcType=VARCHAR}, | ||||
|             #{object.primaryConnectionIdentifier,jdbcType=VARCHAR}, | ||||
|         ) | ||||
|  | ||||
|     </insert> | ||||
|  | ||||
|     <!-- Update single sharing profile --> | ||||
|     <update id="update" parameterType="org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileModel"> | ||||
|         UPDATE guacamole_sharing_profile | ||||
|         SET sharing_profile_name  = #{object.name,jdbcType=VARCHAR}, | ||||
|             primary_connection_id = #{object.primaryConnectionIdentifier,jdbcType=VARCHAR} | ||||
|         WHERE sharing_profile_id = #{object.objectID,jdbcType=INTEGER} | ||||
|     </update> | ||||
|  | ||||
| </mapper> | ||||
| @@ -0,0 +1,68 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" ?> | ||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||||
|     "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||||
|  | ||||
| <!-- | ||||
|     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. | ||||
| --> | ||||
|  | ||||
| <mapper namespace="org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileParameterMapper"> | ||||
|  | ||||
|     <!-- Result mapper for sharing profile parameters --> | ||||
|     <resultMap id="ParameterResultMap" type="org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileParameterModel"> | ||||
|         <result column="sharing_profile_id" property="sharingProfileIdentifier" jdbcType="INTEGER"/> | ||||
|         <result column="parameter_name"     property="name"                     jdbcType="VARCHAR"/> | ||||
|         <result column="parameter_value"    property="value"                    jdbcType="VARCHAR"/> | ||||
|     </resultMap> | ||||
|  | ||||
|     <!-- Select all parameters of a given sharing profile --> | ||||
|     <select id="select" resultMap="ParameterResultMap"> | ||||
|         SELECT | ||||
|             sharing_profile_id, | ||||
|             parameter_name, | ||||
|             parameter_value | ||||
|         FROM guacamole_sharing_profile_parameter | ||||
|         WHERE | ||||
|             sharing_profile_id = #{identifier,jdbcType=VARCHAR} | ||||
|     </select> | ||||
|  | ||||
|     <!-- Delete all parameters of a given sharing profile --> | ||||
|     <delete id="delete"> | ||||
|         DELETE FROM guacamole_sharing_profile_parameter | ||||
|         WHERE sharing_profile_id = #{identifier,jdbcType=VARCHAR} | ||||
|     </delete> | ||||
|  | ||||
|     <!-- Insert all given parameters --> | ||||
|     <insert id="insert" parameterType="org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileParameterModel"> | ||||
|  | ||||
|         INSERT INTO guacamole_sharing_profile_parameter ( | ||||
|             sharing_profile_id, | ||||
|             parameter_name, | ||||
|             parameter_value | ||||
|         ) | ||||
|         VALUES  | ||||
|             <foreach collection="parameters" item="parameter" separator=","> | ||||
|                 (#{parameter.sharingProfileIdentifier,jdbcType=VARCHAR}, | ||||
|                  #{parameter.name,jdbcType=VARCHAR}, | ||||
|                  #{parameter.value,jdbcType=VARCHAR}) | ||||
|             </foreach> | ||||
|  | ||||
|     </insert> | ||||
|  | ||||
|  | ||||
| </mapper> | ||||
		Reference in New Issue
	
	Block a user