]> 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
8f71ace0a51b6f002b057c7c82552b3a84425200
[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.jcr.security.JcrKeyring;
30
31 /** Root of a remote repository */
32 public class RemoteRepositoryNode extends RepositoryNode {
33 private JcrKeyring jcrKeyring;
34 private String remoteNodePath;
35
36 public RemoteRepositoryNode(String alias, Repository repository,
37 TreeParent parent, JcrKeyring jcrKeyring, String remoteNodePath) {
38 super(alias, repository, parent);
39 this.jcrKeyring = jcrKeyring;
40 this.remoteNodePath = remoteNodePath;
41 }
42
43 @Override
44 protected Session repositoryLogin(String workspaceName)
45 throws RepositoryException {
46 Node remoteNode = jcrKeyring.getSession().getNode(remoteNodePath);
47 String userID = remoteNode.getProperty(ArgeoNames.ARGEO_USER_ID)
48 .getString();
49 char[] password = jcrKeyring.getAsChars(remoteNodePath + "/"
50 + ArgeoNames.ARGEO_PASSWORD);
51 try {
52 SimpleCredentials credentials = new SimpleCredentials(userID,
53 password);
54 return getRepository().login(credentials, workspaceName);
55 } finally {
56 Arrays.fill(password, 0, password.length, ' ');
57 }
58 }
59
60 public void remove() {
61 try {
62 Node remoteNode = jcrKeyring.getSession().getNode(remoteNodePath);
63 remoteNode.remove();
64 remoteNode.getSession().save();
65 } catch (RepositoryException e) {
66 throw new ArgeoException("Cannot remove " + remoteNodePath, e);
67 }
68 }
69
70 }