]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.server.jcr/src/org/argeo/jcr/UserJcrUtils.java
Remove DocBook from defaults CNDs
[lgpl/argeo-commons.git] / org.argeo.server.jcr / src / org / argeo / 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 import org.argeo.ArgeoException;
29
30 /**
31 * Utilities related to the user home and properties based on Argeo JCR model.
32 * Do not use anymore. Does not fit with current security model
33 */
34 @Deprecated
35 public class UserJcrUtils {
36 /** The home base path. Not yet configurable */
37 public final static String DEFAULT_HOME_BASE_PATH = "/home";
38
39 /**
40 * Returns the home node of the user or null if none was found.
41 *
42 * @param session
43 * the session to use in order to perform the search, this can be
44 * a session with a different user ID than the one searched,
45 * typically when a system or admin session is used.
46 * @param username
47 * the username of the user
48 */
49 public static Node getUserHome(Session session, String username) {
50 try {
51 // String homePath = UserJcrUtils.getUserHomePath(username);
52 // return session.itemExists(homePath) ? session.getNode(homePath)
53 // : null;
54 // kept for example of QOM queries
55 QueryObjectModelFactory qomf = session.getWorkspace()
56 .getQueryManager().getQOMFactory();
57 Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_HOME,
58 "userHome");
59 DynamicOperand userIdDop = qomf.propertyValue(
60 userHomeSel.getSelectorName(), ArgeoNames.ARGEO_USER_ID);
61 StaticOperand userIdSop = qomf.literal(session.getValueFactory()
62 .createValue(username));
63 Constraint constraint = qomf.comparison(userIdDop,
64 QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop);
65 Query query = qomf.createQuery(userHomeSel, constraint, null, null);
66 return JcrUtils.querySingleNode(query);
67 } catch (RepositoryException e) {
68 throw new ArgeoException("Cannot find home for user " + username, e);
69 }
70 }
71
72 public static Node getUserProfile(Session session, String username) {
73 try {
74 QueryObjectModelFactory qomf = session.getWorkspace()
75 .getQueryManager().getQOMFactory();
76 Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_PROFILE,
77 "userProfile");
78 DynamicOperand userIdDop = qomf.propertyValue(
79 userHomeSel.getSelectorName(), ArgeoNames.ARGEO_USER_ID);
80 StaticOperand userIdSop = qomf.literal(session.getValueFactory()
81 .createValue(username));
82 Constraint constraint = qomf.comparison(userIdDop,
83 QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop);
84 Query query = qomf.createQuery(userHomeSel, constraint, null, null);
85 return JcrUtils.querySingleNode(query);
86 } catch (RepositoryException e) {
87 throw new ArgeoException(
88 "Cannot find profile for user " + username, e);
89 }
90 }
91
92 /** Returns the home node of the session user or null if none was found. */
93 public static Node getUserHome(Session session) {
94 String userID = session.getUserID();
95 return getUserHome(session, userID);
96 }
97
98 private UserJcrUtils() {
99 }
100 }