Tool for password cryptography 07/74607/8
authorZlatko Murgoski <zlatko.murgoski@nokia.com>
Thu, 13 Dec 2018 11:23:30 +0000 (12:23 +0100)
committerZlatko Murgoski <zlatko.murgoski@nokia.com>
Thu, 13 Dec 2018 12:29:13 +0000 (13:29 +0100)
Tool for password cryptography

Change-Id: I7713c8568a00409e282c250eefe4047458d3edac
Issue-ID: DCAEGEN2-1020
Signed-off-by: Zlatko Murgoski <zlatko.murgoski@nokia.com>
pom.xml
security/crypt-password/README.md [new file with mode: 0644]
security/crypt-password/pom.xml [new file with mode: 0644]
security/crypt-password/src/main/java/org/onap/dcaegen2/services/sdk/security/CryptPassword.java [new file with mode: 0644]
security/crypt-password/src/main/java/org/onap/dcaegen2/services/sdk/security/DecodePassword.java [new file with mode: 0644]
security/pom.xml [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 1cd81a2..1d08659 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -38,6 +38,7 @@
 
   <modules>
     <module>rest-services</module>
+    <module>security</module>
   </modules>
 
   <build>
diff --git a/security/crypt-password/README.md b/security/crypt-password/README.md
new file mode 100644 (file)
index 0000000..1ce7927
--- /dev/null
@@ -0,0 +1,10 @@
+Crypt Password 
+==================================
+
+Library to generate and match cryptography password using BCrypt algorithm
+
+### Requirements 
+mvn clean install
+
+### How to use
+java -jar crypt-password-<version>.jar password_to_crypt
\ No newline at end of file
diff --git a/security/crypt-password/pom.xml b/security/crypt-password/pom.xml
new file mode 100644 (file)
index 0000000..bdb3bb4
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <parent>
+    <groupId>org.onap.dcaegen2.services.sdk.security</groupId>
+    <artifactId>dcaegen2-services-sdk-security</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.onap.dcaegen2.services.sdk.security.crypt</groupId>
+  <artifactId>crypt-password</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+
+  <name>dcaegen2-services-sdk-security-crypt-password</name>
+  <description>DMaaP Security Module</description>
+  <packaging>jar</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.security</groupId>
+      <artifactId>spring-security-crypto</artifactId>
+      <version>3.1.0.RELEASE</version>
+    </dependency>
+  </dependencies>
+
+    <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-shade-plugin</artifactId>
+            <version>3.2.1</version>
+            <executions>
+              <execution>
+                <phase>package</phase>
+                <goals>
+                  <goal>shade</goal>
+                </goals>
+                <configuration>
+                  <transformers>
+                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                      <mainClass>org.onap.dcaegen2.services.sdk.security.DecodePassword</mainClass>
+                    </transformer>
+                  </transformers>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git a/security/crypt-password/src/main/java/org/onap/dcaegen2/services/sdk/security/CryptPassword.java b/security/crypt-password/src/main/java/org/onap/dcaegen2/services/sdk/security/CryptPassword.java
new file mode 100644 (file)
index 0000000..6ca78a0
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * ============LICENSE_START=======================================================
+ * DCAEGEN2-SERVICES-SDK
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcaegen2.services.sdk.security;
+
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+
+public class CryptPassword {
+
+  private BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
+
+  public String decode(String arg) {
+    return encoder.encode(arg);
+  }
+
+  public boolean matches(String rawPassword, String encodedPassword){
+    return encoder.matches(rawPassword,encodedPassword);
+  }
+}
diff --git a/security/crypt-password/src/main/java/org/onap/dcaegen2/services/sdk/security/DecodePassword.java b/security/crypt-password/src/main/java/org/onap/dcaegen2/services/sdk/security/DecodePassword.java
new file mode 100644 (file)
index 0000000..85412eb
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * ============LICENSE_START=======================================================
+ * DCAEGEN2-SERVICES-SDK
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcaegen2.services.sdk.security;
+
+class DecodePassword {
+
+  private static CryptPassword cryptPassword = new CryptPassword();
+
+  public static void main(String[] args) {
+
+    try {
+      System.out.println(cryptPassword.decode(args[0]));
+    }catch(Exception e){
+      System.out.println("Param to crypt is required !");
+    }
+  }
+}
diff --git a/security/pom.xml b/security/pom.xml
new file mode 100644 (file)
index 0000000..66b7a0f
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.onap.dcaegen2.services</groupId>
+    <artifactId>sdk</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+
+  <groupId>org.onap.dcaegen2.services.sdk.security</groupId>
+  <artifactId>dcaegen2-services-sdk-security</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+
+  <name>dcaegen2-services-sdk-security</name>
+  <description>Common SDK repo for all DCAE Security</description>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>crypt-password</module>
+  </modules>
+
+</project>
\ No newline at end of file