New web administration interface
[bm-groupware-server.git] / bm-webconfig / webconfig-webapp / src / main / java / net / bionicmessage / funambol / configuration / UserUtils.java
blob5c7a160ab2a9eb739ce5b5facc1aad5cdac78206
1 /*
2 * UserUtils.java: Created 3rd December 2008, 9:57AM
3 * WebConfig - a web administration interface for the Funambol DS Server.
4 * Copyright (C) 2008 Mathew McBride
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package net.bionicmessage.funambol.configuration;
21 import com.funambol.framework.filter.AllClause;
22 import com.funambol.framework.filter.Clause;
23 import com.funambol.framework.filter.WhereClause;
24 import com.funambol.framework.server.Sync4jUser;
25 import com.funambol.framework.server.store.PersistentStoreException;
26 import com.funambol.server.admin.AdminException;
27 import com.funambol.server.admin.UserManager;
28 import com.funambol.server.config.Configuration;
30 /**
32 * @author matt
34 public class UserUtils {
36 /** Retrieves a Sync4jUser object for the specified username
38 * @param name Username to retrieve information for
39 * @return Sync4jUser object for user if found, or null
40 * @throws com.funambol.server.admin.AdminException
41 * @throws com.funambol.framework.server.store.PersistentStoreException
43 public static Sync4jUser getUserByUsername(String name) throws AdminException, PersistentStoreException {
44 Configuration c = Configuration.getConfiguration();
45 UserManager um = c.getUserManager();
46 String[] params = {name};
47 WhereClause id = new WhereClause(
48 "username",
49 params,
50 WhereClause.OPT_EQ,
51 false);
52 Sync4jUser[] users = um.getUsers(id);
53 if (users.length == 1) {
54 return users[0];
56 return null;
59 public static void setUser(Sync4jUser user) throws AdminException, PersistentStoreException {
60 Configuration c = Configuration.getConfiguration();
61 UserManager um = c.getUserManager();
62 if (user.getRoles() == null) {
63 String[] defaultRoles = {UserManager.ROLE_USER};
64 user.setRoles(defaultRoles);
66 um.setUser(user);
69 public static Sync4jUser[] findUsersBeginningWith(String searchName) throws AdminException, PersistentStoreException {
70 Configuration conf = Configuration.getConfiguration();
71 UserManager um = conf.getUserManager();
72 Clause c = null;
73 if (searchName != null) {
74 String[] params = {searchName};
75 WhereClause wc = new WhereClause("username",
76 params,
77 WhereClause.OPT_CONTAINS,
78 false);
79 c = wc;
80 } else {
81 c = new AllClause();
83 return um.getUsers(c);