2 * Copyright (C) 2007-2012 Argeo GmbH
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
.RepositoryFactory
;
24 import javax
.jcr
.Session
;
25 import javax
.jcr
.SimpleCredentials
;
27 import org
.argeo
.ArgeoException
;
28 import org
.argeo
.eclipse
.ui
.TreeParent
;
29 import org
.argeo
.jcr
.ArgeoJcrUtils
;
30 import org
.argeo
.jcr
.ArgeoNames
;
31 import org
.argeo
.util
.security
.Keyring
;
33 /** Root of a remote repository */
34 public class RemoteRepositoryElem
extends RepositoryElem
{
35 private final Keyring keyring
;
37 * A session of the logged in user on the default workspace of the node
40 private final Session userSession
;
41 private final String remoteNodePath
;
43 private final RepositoryFactory repositoryFactory
;
44 private final String uri
;
46 public RemoteRepositoryElem(String alias
,
47 RepositoryFactory repositoryFactory
, String uri
, TreeParent parent
,
48 Session userSession
, Keyring keyring
, String remoteNodePath
) {
49 super(alias
, null, parent
);
50 this.repositoryFactory
= repositoryFactory
;
52 this.keyring
= keyring
;
53 this.userSession
= userSession
;
54 this.remoteNodePath
= remoteNodePath
;
58 protected Session
repositoryLogin(String workspaceName
)
59 throws RepositoryException
{
60 Node remoteRepository
= userSession
.getNode(remoteNodePath
);
61 String userID
= remoteRepository
.getProperty(ArgeoNames
.ARGEO_USER_ID
)
63 String pwdPath
= remoteRepository
.getPath() + '/'
64 + ArgeoNames
.ARGEO_PASSWORD
;
65 char[] password
= keyring
.getAsChars(pwdPath
);
68 SimpleCredentials credentials
= new SimpleCredentials(userID
,
70 return getRepository().login(credentials
, workspaceName
);
72 Arrays
.fill(password
, 0, password
.length
, ' ');
77 public Repository
getRepository() {
78 if (repository
== null)
79 repository
= ArgeoJcrUtils
.getRepositoryByUri(repositoryFactory
,
81 return super.getRepository();
84 public void remove() {
86 Node remoteNode
= userSession
.getNode(remoteNodePath
);
88 remoteNode
.getSession().save();
89 } catch (RepositoryException e
) {
90 throw new ArgeoException("Cannot remove " + remoteNodePath
, e
);