]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RemoteRepositoryNode.java
Change JCR url
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / model / RemoteRepositoryNode.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
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.ui.explorer.model;
17
18 import java.util.Arrays;
19
20 import javax.jcr.Node;
21 import javax.jcr.Repository;
22 import javax.jcr.RepositoryException;
23 import javax.jcr.Session;
24 import javax.jcr.SimpleCredentials;
25
26 import org.argeo.ArgeoException;
27 import org.argeo.eclipse.ui.TreeParent;
28 import org.argeo.jcr.ArgeoNames;
29 import org.argeo.util.security.Keyring;
30
31 /** Root of a remote repository */
32 public class RemoteRepositoryNode extends RepositoryNode {
33 private final Keyring keyring;
34 /**
35 * A session of the logged in user on the default workspace of the node
36 * repository.
37 */
38 private final Session userSession;
39 private final String remoteNodePath;
40
41 public RemoteRepositoryNode(String alias, Repository repository,
42 TreeParent parent, Session userSession, Keyring keyring,
43 String remoteNodePath) {
44 super(alias, repository, parent);
45 this.keyring = keyring;
46 this.userSession = userSession;
47 this.remoteNodePath = remoteNodePath;
48 }
49
50 @Override
51 protected Session repositoryLogin(String workspaceName)
52 throws RepositoryException {
53 Node remoteRepository = userSession.getNode(remoteNodePath);
54 String userID = remoteRepository.getProperty(ArgeoNames.ARGEO_USER_ID)
55 .getString();
56 String pwdPath = remoteRepository.getPath() + '/'
57 + ArgeoNames.ARGEO_PASSWORD;
58 char[] password = keyring.getAsChars(pwdPath);
59
60 try {
61 SimpleCredentials credentials = new SimpleCredentials(userID,
62 password);
63 return getRepository().login(credentials, workspaceName);
64 } finally {
65 Arrays.fill(password, 0, password.length, ' ');
66 }
67 }
68
69 public void remove() {
70 try {
71 Node remoteNode = userSession.getNode(remoteNodePath);
72 remoteNode.remove();
73 remoteNode.getSession().save();
74 } catch (RepositoryException e) {
75 throw new ArgeoException("Cannot remove " + remoteNodePath, e);
76 }
77 }
78
79 }