Remove old license headers
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / security / JcrKeyring.java
index bc233d07d5cc8eadeb451018cfb461f6bf510b4e..2e9295b7279b23006726894beda5da287a6d0cd6 100644 (file)
@@ -1,18 +1,3 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 package org.argeo.cms.security;
 
 import java.io.ByteArrayInputStream;
@@ -41,13 +26,14 @@ import javax.jcr.query.Query;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.argeo.api.NodeConstants;
+import org.argeo.api.NodeUtils;
+import org.argeo.api.security.PBEKeySpecCallback;
 import org.argeo.cms.ArgeoNames;
 import org.argeo.cms.ArgeoTypes;
 import org.argeo.cms.CmsException;
 import org.argeo.jcr.ArgeoJcrException;
 import org.argeo.jcr.JcrUtils;
-import org.argeo.node.NodeUtils;
-import org.argeo.node.security.PBEKeySpecCallback;
 
 /** JCR based implementation of a keyring */
 public class JcrKeyring extends AbstractKeyring implements ArgeoNames {
@@ -108,7 +94,7 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames {
 
        private Session login() {
                try {
-                       return repository.login();
+                       return repository.login(NodeConstants.HOME_WORKSPACE);
                } catch (RepositoryException e) {
                        throw new CmsException("Cannot login key ring session", e);
                }
@@ -193,9 +179,11 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames {
 
        @Override
        protected synchronized void handleKeySpecCallback(PBEKeySpecCallback pbeCallback) {
+               Session session = null;
                try {
-                       session().refresh(true);
-                       Node userHome = NodeUtils.getUserHome(session());
+                       session = session();
+                       session.refresh(true);
+                       Node userHome = NodeUtils.getUserHome(session);
                        Node keyring;
                        if (userHome.hasNode(ARGEO_KEYRING))
                                keyring = userHome.getNode(ARGEO_KEYRING);
@@ -214,6 +202,8 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames {
                        // notYetSavedKeyring.remove();
                } catch (RepositoryException e) {
                        throw new ArgeoJcrException("Cannot handle key spec callback", e);
+               } finally {
+                       JcrUtils.logoutQuietly(session);
                }
        }