]> git.argeo.org Git - lgpl/argeo-commons.git/blob - jcr/UserJcrUtils.java
Prepare next development cycle
[lgpl/argeo-commons.git] / jcr / UserJcrUtils.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.jcr;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20 import javax.jcr.Session;
21 import javax.jcr.query.Query;
22 import javax.jcr.query.qom.Constraint;
23 import javax.jcr.query.qom.DynamicOperand;
24 import javax.jcr.query.qom.QueryObjectModelFactory;
25 import javax.jcr.query.qom.Selector;
26 import javax.jcr.query.qom.StaticOperand;
27
28 /**
29 * Utilities related to the user home and properties based on Argeo JCR model.
30 * Do not use anymore. Does not fit with current security model
31 */
32 @Deprecated
33 public class UserJcrUtils {
34 /** The home base path. Not yet configurable */
35 public final static String DEFAULT_HOME_BASE_PATH = "/home";
36
37 /**
38 * Returns the home node of the user or null if none was found.
39 *
40 * @param session
41 * the session to use in order to perform the search, this can be
42 * a session with a different user ID than the one searched,
43 * typically when a system or admin session is used.
44 * @param username
45 * the username of the user
46 */
47 public static Node getUserHome(Session session, String username) {
48 try {
49 // String homePath = UserJcrUtils.getUserHomePath(username);
50 // return session.itemExists(homePath) ? session.getNode(homePath)
51 // : null;
52 // kept for example of QOM queries
53 QueryObjectModelFactory qomf = session.getWorkspace()
54 .getQueryManager().getQOMFactory();
55 Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_HOME,
56 "userHome");
57 DynamicOperand userIdDop = qomf.propertyValue(
58 userHomeSel.getSelectorName(), ArgeoNames.ARGEO_USER_ID);
59 StaticOperand userIdSop = qomf.literal(session.getValueFactory()
60 .createValue(username));
61 Constraint constraint = qomf.comparison(userIdDop,
62 QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop);
63 Query query = qomf.createQuery(userHomeSel, constraint, null, null);
64 return JcrUtils.querySingleNode(query);
65 } catch (RepositoryException e) {
66 throw new ArgeoJcrException("Cannot find home for user " + username, e);
67 }
68 }
69
70 public static Node getUserProfile(Session session, String username) {
71 try {
72 QueryObjectModelFactory qomf = session.getWorkspace()
73 .getQueryManager().getQOMFactory();
74 Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_PROFILE,
75 "userProfile");
76 DynamicOperand userIdDop = qomf.propertyValue(
77 userHomeSel.getSelectorName(), ArgeoNames.ARGEO_USER_ID);
78 StaticOperand userIdSop = qomf.literal(session.getValueFactory()
79 .createValue(username));
80 Constraint constraint = qomf.comparison(userIdDop,
81 QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop);
82 Query query = qomf.createQuery(userHomeSel, constraint, null, null);
83 return JcrUtils.querySingleNode(query);
84 } catch (RepositoryException e) {
85 throw new ArgeoJcrException(
86 "Cannot find profile for user " + username, e);
87 }
88 }
89
90 /** Returns the home node of the session user or null if none was found. */
91 public static Node getUserHome(Session session) {
92 String userID = session.getUserID();
93 return getUserHome(session, userID);
94 }
95
96 private UserJcrUtils() {
97 }
98 }