Author: angela
Date: Mon Apr 3 08:27:37 2017
New Revision: 1789925
URL: http://svn.apache.org/viewvc?rev=1789925&view=rev
Log:
OAK-6018 : UserImporter: session field can avoided by passing to init method
OAK-5882 : Improve coverage for oak.security code in oak-core (wip)
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterSessionAutosaveTest.java
(with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterTest.java
(with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterWorkspaceTest.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java?rev=1789925&r1=1789924&r2=1789925&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
Mon Apr 3 08:27:37 2017
@@ -132,7 +132,6 @@ class UserImporter implements ProtectedP
private final int importBehavior;
- private JackrabbitSession session;
private Root root;
private NamePathMapper namePathMapper;
private ReferenceChangeTracker referenceTracker;
@@ -179,7 +178,6 @@ class UserImporter implements ProtectedP
return false;
}
- this.session = (JackrabbitSession) session;
this.root = root;
this.namePathMapper = namePathMapper;
this.referenceTracker = referenceTracker;
@@ -192,7 +190,7 @@ class UserImporter implements ProtectedP
return false;
}
- if (!initUserManager(isWorkspaceImport, securityProvider)) {
+ if (!initUserManager((JackrabbitSession) session, isWorkspaceImport,
securityProvider)) {
return false;
}
@@ -202,7 +200,7 @@ class UserImporter implements ProtectedP
return initialized;
}
- private boolean initUserManager(boolean isWorkspaceImport,
SecurityProvider securityProvider) {
+ private boolean initUserManager(@Nonnull JackrabbitSession session,
boolean isWorkspaceImport, @Nonnull SecurityProvider securityProvider) {
try {
if (!isWorkspaceImport && session.getUserManager().isAutoSave()) {
log.warn("Session import cannot handle user content:
UserManager is in autosave mode.");
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterSessionAutosaveTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterSessionAutosaveTest.java?rev=1789925&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterSessionAutosaveTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterSessionAutosaveTest.java
Mon Apr 3 08:27:37 2017
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.jackrabbit.oak.security.user;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
+import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.oak.spi.xml.ReferenceChangeTracker;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+public class UserImporterSessionAutosaveTest extends UserImporterTest {
+
+ @Override
+ public void before() throws Exception {
+ super.before();
+
+ getUserManager(root).autoSave(true);
+
+ }
+
+ @Override
+ protected ConfigurationParameters getSecurityConfigParameters() {
+ ConfigurationParameters userConfig = ConfigurationParameters.of(
+ UserConstants.PARAM_SUPPORT_AUTOSAVE, Boolean.TRUE);
+ return ConfigurationParameters.of(UserConfiguration.NAME, userConfig);
+ }
+
+ @Override
+ public void after() throws Exception {
+ try {
+ UserManager uMgr = getUserManager(root);
+ if (uMgr.isAutoSave()) {
+ getUserManager(root).autoSave(false);
+ }
+ } finally {
+ super.after();
+ }
+ }
+
+ @Override
+ boolean init() throws Exception {
+ getUserManager(root).autoSave(false);
+ boolean b = super.init();
+ getUserManager(root).autoSave(true);
+ return b;
+ }
+
+ @Test
+ public void testInitImportUUIDBehaviorRemove() throws Exception {
+ assertFalse(importer.init(mockJackrabbitSession(), root,
getNamePathMapper(), isWorkspaceImport(),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING, new
ReferenceChangeTracker(), getSecurityProvider()));
+ }
+
+ @Test
+ public void testInitImportUUIDBehaviorReplace() throws Exception {
+ assertFalse(importer.init(mockJackrabbitSession(), root,
getNamePathMapper(), isWorkspaceImport(),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING, new
ReferenceChangeTracker(), getSecurityProvider()));
+ }
+
+ @Test
+ public void testInitImportUUIDBehaviorThrow() throws Exception {
+ assertFalse(importer.init(mockJackrabbitSession(), root,
getNamePathMapper(), isWorkspaceImport(),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new ReferenceChangeTracker(),
getSecurityProvider()));
+ }
+
+ @Test
+ public void testInitImportUUIDBehaviourCreateNew() throws Exception {
+ assertFalse(importer.init(mockJackrabbitSession(), root,
getNamePathMapper(), isWorkspaceImport(),
ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, new ReferenceChangeTracker(),
getSecurityProvider()));
+ }
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterSessionAutosaveTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterTest.java?rev=1789925&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterTest.java
Mon Apr 3 08:27:37 2017
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.jackrabbit.oak.security.user;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
+import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.oak.spi.xml.ReferenceChangeTracker;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+public class UserImporterTest extends AbstractSecurityTest {
+
+ UserImporter importer;
+
+ @Override
+ public void before() throws Exception {
+ super.before();
+
+ importer = new UserImporter(getImportConfig());
+ }
+
+ ConfigurationParameters getImportConfig() {
+ return ConfigurationParameters.EMPTY;
+ }
+
+ Session mockJackrabbitSession() throws Exception {
+ JackrabbitSession s = Mockito.mock(JackrabbitSession.class);
+ when(s.getUserManager()).thenReturn(getUserManager(root));
+ return s;
+ }
+
+ boolean isWorkspaceImport() {
+ return false;
+ }
+
+ boolean init() throws Exception {
+ return importer.init(mockJackrabbitSession(), root,
getNamePathMapper(), isWorkspaceImport(),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING, new
ReferenceChangeTracker(), getSecurityProvider());
+ }
+
+ @Test
+ public void testInitNoJackrabbitSession() throws Exception {
+ Session s = Mockito.mock(Session.class);
+ assertFalse(importer.init(s, root, getNamePathMapper(), false,
ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new ReferenceChangeTracker(),
getSecurityProvider()));
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testInitAlreadyInitialized() throws Exception {
+ init();
+ importer.init(mockJackrabbitSession(), root, getNamePathMapper(),
isWorkspaceImport(), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING,
new ReferenceChangeTracker(), getSecurityProvider());
+ }
+
+ @Test
+ public void testInitImportUUIDBehaviorRemove() throws Exception {
+ assertTrue(importer.init(mockJackrabbitSession(), root,
getNamePathMapper(), isWorkspaceImport(),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING, new
ReferenceChangeTracker(), getSecurityProvider()));
+ }
+
+
+ @Test
+ public void testInitImportUUIDBehaviorReplace() throws Exception {
+ assertTrue(importer.init(mockJackrabbitSession(), root,
getNamePathMapper(), isWorkspaceImport(),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING, new
ReferenceChangeTracker(), getSecurityProvider()));
+ }
+
+ @Test
+ public void testInitImportUUIDBehaviorThrow() throws Exception {
+ assertTrue(importer.init(mockJackrabbitSession(), root,
getNamePathMapper(), isWorkspaceImport(),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new ReferenceChangeTracker(),
getSecurityProvider()));
+ }
+
+ @Test
+ public void testInitImportUUIDBehaviourCreateNew() throws Exception {
+ assertFalse(importer.init(mockJackrabbitSession(), root,
getNamePathMapper(), isWorkspaceImport(),
ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, new ReferenceChangeTracker(),
getSecurityProvider()));
+ }
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterWorkspaceTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterWorkspaceTest.java?rev=1789925&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterWorkspaceTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterWorkspaceTest.java
Mon Apr 3 08:27:37 2017
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.jackrabbit.oak.security.user;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
+import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.oak.spi.xml.ReferenceChangeTracker;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+public class UserImporterWorkspaceTest extends UserImporterTest {
+
+ @Override
+ boolean isWorkspaceImport() {
+ return true;
+ }
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterWorkspaceTest.java
------------------------------------------------------------------------------
svn:eol-style = native