2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.jcr
.ui
.explorer
.model
;
18 import java
.util
.Arrays
;
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
;
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
;
31 /** Root of a remote repository */
32 public class RemoteRepositoryNode
extends RepositoryNode
{
33 private JcrKeyring jcrKeyring
;
34 private String remoteNodePath
;
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
;
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
)
49 char[] password
= jcrKeyring
.getAsChars(remoteNodePath
+ "/"
50 + ArgeoNames
.ARGEO_PASSWORD
);
52 SimpleCredentials credentials
= new SimpleCredentials(userID
,
54 return getRepository().login(credentials
, workspaceName
);
56 Arrays
.fill(password
, 0, password
.length
, ' ');
60 public void remove() {
62 Node remoteNode
= jcrKeyring
.getSession().getNode(remoteNodePath
);
64 remoteNode
.getSession().save();
65 } catch (RepositoryException e
) {
66 throw new ArgeoException("Cannot remove " + remoteNodePath
, e
);