Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2020-10-08 07:38:43 +0000
committerEike Stepper2020-10-08 07:38:43 +0000
commitfcc359ca8c592ad63ee466854f6a7abbc36fe5f8 (patch)
tree892d2b6d84bedfc5ebd1ec0fd3ff1e4d89d28a4e /plugins/org.eclipse.emf.cdo.examples
parentef2b7686fdcfb5a515b16884890c5242a4cfa0bf (diff)
downloadcdo-fcc359ca8c592ad63ee466854f6a7abbc36fe5f8.tar.gz
cdo-fcc359ca8c592ad63ee466854f6a7abbc36fe5f8.tar.xz
cdo-fcc359ca8c592ad63ee466854f6a7abbc36fe5f8.zip
[567696] [DB] Make it easier to customize ITypeMappings
https://bugs.eclipse.org/bugs/show_bug.cgi?id=567696
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.examples')
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF12
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/plugin.xml4
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/pom.xml2
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/EncryptedPasswordFactory.java97
4 files changed, 108 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF
index d98d4e3c39..0adac7a253 100644
--- a/plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.emf.cdo.examples;singleton:=true
-Bundle-Version: 4.1.1.qualifier
+Bundle-Version: 4.1.2.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Activator: org.eclipse.emf.cdo.internal.examples.bundle.OM$Activator
@@ -23,9 +23,9 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)";resoluti
org.eclipse.emf.cdo.security;bundle-version="[4.0.0,5.0.0)",
org.eclipse.emf.cdo.server.security;bundle-version="[4.0.0,5.0.0)"
Import-Package: org.h2.jdbcx;version="[1.0.0,2.0.0)"
-Export-Package: org.eclipse.emf.cdo.examples;version="4.1.1";x-internal:=true,
- org.eclipse.emf.cdo.examples.embedded;version="4.1.1",
- org.eclipse.emf.cdo.examples.server;version="4.1.1";x-internal:=true,
- org.eclipse.emf.cdo.examples.server.offline;version="4.1.1";x-internal:=true,
- org.eclipse.emf.cdo.internal.examples.bundle;version="4.1.1";x-internal:=true
+Export-Package: org.eclipse.emf.cdo.examples;version="4.1.2";x-internal:=true,
+ org.eclipse.emf.cdo.examples.embedded;version="4.1.2",
+ org.eclipse.emf.cdo.examples.server;version="4.1.2";x-internal:=true,
+ org.eclipse.emf.cdo.examples.server.offline;version="4.1.2";x-internal:=true,
+ org.eclipse.emf.cdo.internal.examples.bundle;version="4.1.2";x-internal:=true
Automatic-Module-Name: org.eclipse.emf.cdo.examples
diff --git a/plugins/org.eclipse.emf.cdo.examples/plugin.xml b/plugins/org.eclipse.emf.cdo.examples/plugin.xml
index c2e2275c06..10d772cf35 100644
--- a/plugins/org.eclipse.emf.cdo.examples/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.examples/plugin.xml
@@ -18,6 +18,10 @@
productGroup="org.eclipse.emf.cdo.server.queryHandlerFactories"
type="user_roles"
class="org.eclipse.emf.cdo.examples.server.UserRolesQueryHandlerFactory"/>
+ <factory
+ productGroup="org.eclipse.emf.cdo.server.db.typeMappingProviders"
+ type="encryptedPassword"
+ class="org.eclipse.emf.cdo.examples.server.EncryptedPasswordFactory"/>
</extension>
</plugin>
diff --git a/plugins/org.eclipse.emf.cdo.examples/pom.xml b/plugins/org.eclipse.emf.cdo.examples/pom.xml
index 24654d4b30..cdea9b42d7 100644
--- a/plugins/org.eclipse.emf.cdo.examples/pom.xml
+++ b/plugins/org.eclipse.emf.cdo.examples/pom.xml
@@ -25,7 +25,7 @@
<groupId>org.eclipse.emf.cdo</groupId>
<artifactId>org.eclipse.emf.cdo.examples</artifactId>
- <version>4.1.1-SNAPSHOT</version>
+ <version>4.1.2-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/EncryptedPasswordFactory.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/EncryptedPasswordFactory.java
new file mode 100644
index 0000000000..1a737360cf
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/EncryptedPasswordFactory.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2020 Eike Stepper (Loehne, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.examples.server;
+
+import org.eclipse.emf.cdo.security.SecurityPackage;
+import org.eclipse.emf.cdo.server.db.mapping.AbstractTypeMapping;
+import org.eclipse.emf.cdo.server.db.mapping.DelegatingTypeMapping;
+import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
+import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
+import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping.Provider;
+
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.security.SecurityUtil;
+
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+import javax.crypto.Cipher;
+
+/**
+ * @author Eike Stepper
+ */
+public class EncryptedPasswordFactory extends ITypeMapping.Provider.Factory
+{
+ private static final String TYPE = "encryptedPassword";
+
+ private static final ITypeMapping.Provider PROVIDER = new Provider()
+ {
+ @Override
+ public ITypeMapping createTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature)
+ {
+ ITypeMapping typeMapping = ITypeMapping.Provider.INSTANCE.createTypeMapping(mappingStrategy, feature);
+ if (feature == SecurityPackage.Literals.USER_PASSWORD__ENCRYPTED && typeMapping instanceof AbstractTypeMapping)
+ {
+ return new DelegatingTypeMapping()
+ {
+ @Override
+ public AbstractTypeMapping getDelegate()
+ {
+ return (AbstractTypeMapping)typeMapping;
+ }
+
+ @Override
+ protected Object encode(Object value)
+ {
+ return pbe(value, Cipher.ENCRYPT_MODE);
+ }
+
+ @Override
+ protected Object decode(Object value)
+ {
+ return pbe(value, Cipher.DECRYPT_MODE);
+ }
+
+ private Object pbe(Object value, int mode)
+ {
+ try
+ {
+ byte[] data = ((String)value).getBytes();
+
+ return SecurityUtil.pbe(data, //
+ "mypassword".toCharArray(), //
+ SecurityUtil.PBE_WITH_MD5_AND_DES, //
+ SecurityUtil.DEFAULT_SALT, //
+ SecurityUtil.DEFAULT_ITERATION_COUNT, mode);
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ };
+ }
+
+ return typeMapping;
+ }
+ };
+
+ public EncryptedPasswordFactory()
+ {
+ super(TYPE);
+ }
+
+ @Override
+ public ITypeMapping.Provider create(String description) throws ProductCreationException
+ {
+ return PROVIDER;
+ }
+}

Back to the top