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
;
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(
52 Sync4jUser
[] users
= um
.getUsers(id
);
53 if (users
.length
== 1) {
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
);
69 public static Sync4jUser
[] findUsersBeginningWith(String searchName
) throws AdminException
, PersistentStoreException
{
70 Configuration conf
= Configuration
.getConfiguration();
71 UserManager um
= conf
.getUserManager();
73 if (searchName
!= null) {
74 String
[] params
= {searchName
};
75 WhereClause wc
= new WhereClause("username",
77 WhereClause
.OPT_CONTAINS
,
83 return um
.getUsers(c
);