<property name="keyring" ref="jcrKeyring" />
</bean>
+ <bean id="removeRemoteRepository" class="org.argeo.jcr.ui.explorer.commands.RemoveRemoteRepository">
+ </bean>
+
<bean id="addFolderNode" class="org.argeo.jcr.ui.explorer.commands.AddFolderNode"
scope="prototype" />
name="Repository URI">
</commandParameter>
</command>
+ <command
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ id="org.argeo.jcr.ui.explorer.removeRemoteRepository"
+ name="Remove remote JCR repository">
+ </command>
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
id="org.argeo.jcr.ui.explorer.addFolderNode"
</iterate>
</visibleWhen>
</command>
+ <command
+ commandId="org.argeo.jcr.ui.explorer.removeRemoteRepository"
+ icon="icons/remove.gif"
+ style="push">
+ <visibleWhen>
+ <iterate>
+ <or>
+ <instanceof
+ value="org.argeo.jcr.ui.explorer.model.RemoteRepositoryNode">
+ </instanceof>
+ </or>
+ </iterate>
+ </visibleWhen>
+ </command>
<command
commandId="org.argeo.jcr.ui.explorer.getNodeSize"
icon="icons/getSize.gif"
private Text uri;
private Text username;
private Text password;
+ private Button saveInKeyring;
public RemoteRepositoryLoginDialog(Shell parentShell) {
super(parentShell);
"http://localhost:7070/org.argeo.jcr.webapp/remoting/node");
username = createLT(composite, "User", "");
password = createLP(composite, "Password");
+
+ saveInKeyring = createLC(composite, "Remember password", false);
parent.pack();
return composite;
}
try {
Session nodeSession = keyring.getSession();
Node home = JcrUtils.getUserHome(nodeSession);
+
+ // FIXME better deal with non existing home dir
+ if (home == null)
+ home = JcrUtils.createUserHomeIfNeeded(nodeSession,
+ nodeSession.getUserID());
+
Node remote = home.hasNode(ARGEO_REMOTE) ? home
.getNode(ARGEO_REMOTE) : home.addNode(ARGEO_REMOTE);
if (remote.hasNode(name.getText()))
remoteRepository.setProperty(ARGEO_URI, uri.getText());
remoteRepository.setProperty(ARGEO_USER_ID, username.getText());
Node pwd = remoteRepository.addNode(ARGEO_PASSWORD);
- keyring.set(pwd.getPath(), password.getText().toCharArray());
- nodeSession.save();
+ pwd.getSession().save();
+ if (saveInKeyring.getSelection())
+ keyring.set(pwd.getPath(), password.getText().toCharArray());
+ keyring.getSession().save();
MessageDialog.openInformation(
getParentShell(),
"Repository Added",
"Remote repository '" + username.getText() + "@"
+ uri.getText() + "' added");
+
super.okPressed();
} catch (Exception e) {
ErrorFeedback.show("Cannot add remote repository", e);
return text;
}
+ /** Creates label and check. */
+ protected Button createLC(Composite parent, String label,
+ Boolean initial) {
+ new Label(parent, SWT.NONE).setText(label);
+ Button check = new Button(parent, SWT.CHECK);
+ check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ check.setSelection(initial);
+ return check;
+ }
+
protected Text createLP(Composite parent, String label) {
new Label(parent, SWT.NONE).setText(label);
Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER
--- /dev/null
+package org.argeo.jcr.ui.explorer.commands;
+
+import org.argeo.jcr.ui.explorer.model.RemoteRepositoryNode;
+import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/** Remove a registered remote repository */
+public class RemoveRemoteRepository extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
+ .getActivePage().getSelection();
+
+ GenericJcrBrowser view = (GenericJcrBrowser) HandlerUtil
+ .getActiveWorkbenchWindow(event).getActivePage()
+ .findView(HandlerUtil.getActivePartId(event));
+
+ if (selection != null && !selection.isEmpty()
+ && selection instanceof IStructuredSelection) {
+ Object obj = ((IStructuredSelection) selection).getFirstElement();
+
+ if (obj instanceof RemoteRepositoryNode) {
+ ((RemoteRepositoryNode) obj).remove();
+ view.refresh(null);
+ }
+ }
+ return null;
+ }
+
+}
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
+import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.jcr.ArgeoNames;
import org.argeo.jcr.security.JcrKeyring;
}
}
+ public void remove() {
+ try {
+ Node remoteNode = jcrKeyring.getSession().getNode(remoteNodePath);
+ remoteNode.remove();
+ remoteNode.getSession().save();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot remove " + remoteNodePath, e);
+ }
+ }
+
}
}
}
- /** The node must already exist at this path */
+ /** The node must already exist at this path. Session is saved. */
@Override
- protected void encrypt(String path, InputStream unencrypted) {
+ protected synchronized void encrypt(String path, InputStream unencrypted) {
// should be called first for lazy initialization
SecretKey secretKey = getSecretKey();
Cipher cipher = createCipher();
if (!session.nodeExists(path))
throw new ArgeoException("No node at " + path);
+ if (session.hasPendingChanges())
+ session.save();
Node node = session.getNode(path);
node.addMixin(ArgeoTypes.ARGEO_ENCRYPTED);
SecureRandom random = new SecureRandom();
in = new CipherInputStream(unencrypted, cipher);
binary = session.getValueFactory().createBinary(in);
node.setProperty(Property.JCR_DATA, binary);
+ session.save();
} catch (Exception e) {
throw new ArgeoException("Cannot encrypt", e);
} finally {
}
@Override
- protected InputStream decrypt(String path) {
+ protected synchronized InputStream decrypt(String path) {
// should be called first for lazy initialization
SecretKey secretKey = getSecretKey();
}
}
- public void changePassword(char[] oldPassword, char[] newPassword) {
- // TODO Auto-generated method stub
-
+ public synchronized void changePassword(char[] oldPassword,
+ char[] newPassword) {
+ // TODO decrypt with old pw / encrypt with new pw all argeo:encrypted
}
- public Session getSession() {
+ public synchronized Session getSession() {
return session;
}
- public void setSession(Session session) {
+ public synchronized void setSession(Session session) {
this.session = session;
}