Author: stillalex
Date: Tue Dec 12 09:33:22 2017
New Revision: 1817897
URL: http://svn.apache.org/viewvc?rev=1817897&view=rev
Log:
OAK-7013 Replace usage in oak-auth-external
Modified:
jackrabbit/oak/trunk/oak-auth-external/pom.xml
jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java
Modified: jackrabbit/oak/trunk/oak-auth-external/pom.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-auth-external/pom.xml?rev=1817897&r1=1817896&r2=1817897&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-auth-external/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-auth-external/pom.xml Tue Dec 12 09:33:22 2017
@@ -171,12 +171,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>${h2.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>test</scope>
Modified:
jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java?rev=1817897&r1=1817896&r2=1817897&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java
(original)
+++
jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java
Tue Dec 12 09:33:22 2017
@@ -17,32 +17,13 @@
package
org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal;
import javax.annotation.Nonnull;
-import javax.jcr.RepositoryException;
-import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
-import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
-import org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider;
-import org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider;
-import org.apache.jackrabbit.oak.plugins.tree.factories.RootFactory;
-import org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider;
-import org.apache.jackrabbit.oak.spi.commit.EditorHook;
import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
import
org.apache.jackrabbit.oak.spi.security.authentication.external.impl.ExternalIdentityConstants;
-import org.apache.jackrabbit.oak.spi.state.ApplyDiff;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.apache.jackrabbit.oak.plugins.tree.TreeUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import static com.google.common.base.Preconditions.checkState;
+import com.google.common.collect.ImmutableList;
/**
* Implementation of the {@code RepositoryInitializer} interface responsible
for
@@ -60,8 +41,6 @@ import static com.google.common.base.Pre
*/
class ExternalIdentityRepositoryInitializer implements RepositoryInitializer {
- private static final Logger log =
LoggerFactory.getLogger(ExternalIdentityRepositoryInitializer.class);
-
private final boolean enforceUniqueIds;
ExternalIdentityRepositoryInitializer(boolean enforceUniqueIds) {
@@ -70,42 +49,20 @@ class ExternalIdentityRepositoryInitiali
@Override
public void initialize(@Nonnull NodeBuilder builder) {
- NodeState base = builder.getNodeState();
- NodeStore store = new MemoryNodeStore(base);
-
- String errorMsg = "Failed to initialize external identity content.";
- try {
- Root root = RootFactory.createSystemRoot(store,
- new EditorHook(new CompositeEditorProvider(new
NamespaceEditorProvider(), new TypeEditorProvider())),
- null, null, null);
-
- // create index definition for "rep:externalId" and
"rep:externalPrincipalNames"
- Tree rootTree = root.getTree(PathUtils.ROOT_PATH);
- checkState(rootTree.exists());
- Tree index = TreeUtil.getOrAddChild(rootTree,
IndexConstants.INDEX_DEFINITIONS_NAME, JcrConstants.NT_UNSTRUCTURED);
-
- if (enforceUniqueIds && !index.hasChild("externalId")) {
- Tree definition = IndexUtils.createIndexDefinition(index,
"externalId", true,
- new
String[]{ExternalIdentityConstants.REP_EXTERNAL_ID});
- definition.setProperty("info", "Oak index assuring uniqueness
of rep:externalId properties.");
- }
-
- if (!index.hasChild("externalPrincipalNames")) {
- Tree definition = IndexUtils.createIndexDefinition(index,
"externalPrincipalNames", false,
- new
String[]{ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES});
- definition.setProperty("info", "Oak index used by the
principal management provided by the external authentication module.");
- }
-
- if (root.hasPendingChanges()) {
- root.commit();
- }
- } catch (RepositoryException | CommitFailedException e) {
- log.error(errorMsg, e);
- throw new RuntimeException(e);
+ // create index definition for "rep:externalId" and
+ // "rep:externalPrincipalNames"
+ NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder);
+ if (enforceUniqueIds && !index.hasChildNode("externalId")) {
+ NodeBuilder definition = IndexUtils.createIndexDefinition(index,
"externalId", true, true,
+
ImmutableList.of(ExternalIdentityConstants.REP_EXTERNAL_ID), null);
+ definition.setProperty("info", "Oak index assuring uniqueness of
rep:externalId properties.");
+ }
+ if (!index.hasChildNode("externalPrincipalNames")) {
+ NodeBuilder definition = IndexUtils.createIndexDefinition(index,
"externalPrincipalNames", true, false,
+
ImmutableList.of(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES), null);
+ definition.setProperty("info",
+ "Oak index used by the principal management provided by
the external authentication module.");
}
-
- NodeState target = store.getRoot();
- target.compareAgainstBaseState(base, new ApplyDiff(builder));
}
}
\ No newline at end of file