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