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.auth.jdbc.connectiongroup;
21 
22 
23 import com.google.inject.Inject;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.Set;
27 import org.apache.guacamole.GuacamoleException;
28 import org.apache.guacamole.auth.jdbc.base.RestrictedObject;
29 import org.apache.guacamole.net.auth.ConnectionGroup;
30 import org.apache.guacamole.net.auth.Directory;
31 import org.mybatis.guice.transactional.Transactional;
32 
33 /**
34  * Implementation of the ConnectionGroup Directory which is driven by an
35  * underlying, arbitrary database.
36  */
37 public class ConnectionGroupDirectory extends RestrictedObject
38     implements Directory<ConnectionGroup> {
39 
40     /**
41      * Service for managing connection group objects.
42      */
43     @Inject
44     private ConnectionGroupService connectionGroupService;
45 
46     @Override
get(String identifier)47     public ConnectionGroup get(String identifier) throws GuacamoleException {
48         return connectionGroupService.retrieveObject(getCurrentUser(), identifier);
49     }
50 
51     @Override
52     @Transactional
getAll(Collection<String> identifiers)53     public Collection<ConnectionGroup> getAll(Collection<String> identifiers) throws GuacamoleException {
54         Collection<ModeledConnectionGroup> objects = connectionGroupService.retrieveObjects(getCurrentUser(), identifiers);
55         return Collections.<ConnectionGroup>unmodifiableCollection(objects);
56     }
57 
58     @Override
59     @Transactional
getIdentifiers()60     public Set<String> getIdentifiers() throws GuacamoleException {
61         return connectionGroupService.getIdentifiers(getCurrentUser());
62     }
63 
64     @Override
65     @Transactional
add(ConnectionGroup object)66     public void add(ConnectionGroup object) throws GuacamoleException {
67         connectionGroupService.createObject(getCurrentUser(), object);
68     }
69 
70     @Override
71     @Transactional
update(ConnectionGroup object)72     public void update(ConnectionGroup object) throws GuacamoleException {
73         ModeledConnectionGroup connectionGroup = (ModeledConnectionGroup) object;
74         connectionGroupService.updateObject(getCurrentUser(), connectionGroup);
75     }
76 
77     @Override
78     @Transactional
remove(String identifier)79     public void remove(String identifier) throws GuacamoleException {
80         connectionGroupService.deleteObject(getCurrentUser(), identifier);
81     }
82 
83 }
84