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
.util
.security
.Keyring
;
31 /** Root of a remote repository */
32 public class RemoteRepositoryNode
extends RepositoryNode
{
33 private final Keyring keyring
;
35 * A session of the logged in user on the default workspace of the node
38 private final Session userSession
;
39 private final String remoteNodePath
;
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
;
51 protected Session
repositoryLogin(String workspaceName
)
52 throws RepositoryException
{
53 Node remoteRepository
= userSession
.getNode(remoteNodePath
);
54 String userID
= remoteRepository
.getProperty(ArgeoNames
.ARGEO_USER_ID
)
56 String pwdPath
= remoteRepository
.getPath() + '/'
57 + ArgeoNames
.ARGEO_PASSWORD
;
58 char[] password
= keyring
.getAsChars(pwdPath
);
61 SimpleCredentials credentials
= new SimpleCredentials(userID
,
63 return getRepository().login(credentials
, workspaceName
);
65 Arrays
.fill(password
, 0, password
.length
, ' ');
69 public void remove() {
71 Node remoteNode
= userSession
.getNode(remoteNodePath
);
73 remoteNode
.getSession().save();
74 } catch (RepositoryException e
) {
75 throw new ArgeoException("Cannot remove " + remoteNodePath
, e
);