directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1703873 - in /directory/sandbox/kayyagari/passwd-reset: ./ pom.xml src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/PasswordResetter.java
Date Fri, 18 Sep 2015 14:46:33 GMT
Author: kayyagari
Date: Fri Sep 18 14:46:31 2015
New Revision: 1703873

URL: http://svn.apache.org/viewvc?rev=1703873&view=rev
Log:
a tool to change the password

Added:
    directory/sandbox/kayyagari/passwd-reset/
    directory/sandbox/kayyagari/passwd-reset/pom.xml
    directory/sandbox/kayyagari/passwd-reset/src/
    directory/sandbox/kayyagari/passwd-reset/src/main/
    directory/sandbox/kayyagari/passwd-reset/src/main/java/
    directory/sandbox/kayyagari/passwd-reset/src/main/java/org/
    directory/sandbox/kayyagari/passwd-reset/src/main/java/org/apache/
    directory/sandbox/kayyagari/passwd-reset/src/main/java/org/apache/directory/
    directory/sandbox/kayyagari/passwd-reset/src/main/java/org/apache/directory/PasswordResetter.java

Added: directory/sandbox/kayyagari/passwd-reset/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/passwd-reset/pom.xml?rev=1703873&view=auto
==============================================================================
--- directory/sandbox/kayyagari/passwd-reset/pom.xml (added)
+++ directory/sandbox/kayyagari/passwd-reset/pom.xml Fri Sep 18 14:46:31 2015
@@ -0,0 +1,58 @@
+<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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.directory</groupId>
+  <artifactId>ads-passwd-reset</artifactId>
+  <packaging>jar</packaging>
+  <version>2.0.0-M20</version>
+  <name>ApacheDS Password Reset Tool</name>
+
+  <dependencies>
+     <!--dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-all</artifactId>
+      <version>${project.version}</version>
+    </dependency-->
+    
+     <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-service</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.7.5</version>
+    </dependency>
+  </dependencies>
+  
+    <build>
+        <finalName>ads-passwd-reset</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>1.5</version>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <transformers>
+                                <transformer
+                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                                    <mainClass>org.apache.directory.PasswordResetter</mainClass>
+                                </transformer>
+                            </transformers>
+                            <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+  
+</project>

Added: directory/sandbox/kayyagari/passwd-reset/src/main/java/org/apache/directory/PasswordResetter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/passwd-reset/src/main/java/org/apache/directory/PasswordResetter.java?rev=1703873&view=auto
==============================================================================
--- directory/sandbox/kayyagari/passwd-reset/src/main/java/org/apache/directory/PasswordResetter.java
(added)
+++ directory/sandbox/kayyagari/passwd-reset/src/main/java/org/apache/directory/PasswordResetter.java
Fri Sep 18 14:46:31 2015
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2006-2015 Mirth Corporation.
+ * All rights reserved.
+ *
+ * NOTICE:  All information contained herein is, and remains, the
+ * property of Mirth Corporation. The intellectual and technical
+ * concepts contained herein are proprietary and confidential to
+ * Mirth Corporation and may be covered by U.S. and Foreign
+ * Patents, patents in process, and are protected by trade secret
+ * and/or copyright law. Dissemination of this information or reproduction
+ * of this material is strictly forbidden unless prior written permission
+ * is obtained from Mirth Corporation.
+ */
+package org.apache.directory;
+
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.api.ldap.model.entry.Attribute;
+import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.api.ldap.model.entry.DefaultModification;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.entry.Modification;
+import org.apache.directory.api.ldap.model.entry.ModificationOperation;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.schema.AttributeType;
+import org.apache.directory.api.util.Strings;
+import org.apache.directory.server.ApacheDsService;
+import org.apache.directory.server.core.api.CoreSession;
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.InstanceLayout;
+import org.apache.directory.server.core.api.InterceptorEnum;
+import org.apache.directory.server.core.authn.AuthenticationInterceptor;
+
+/**
+ * A tool to change the password of an entry
+ * 
+ * @author Kiran Ayyagari
+ */
+public class PasswordResetter {
+    
+    public static void main(String[] args) throws Exception {
+        if(args.length !=3 ) {
+            System.out.println("Usage\n java -jar passwd-reset.jar <instance-dir> <user-dn>
<password>");
+            System.out.println("instance-dir the root directory of the installed instance");
+            System.out.println("user-dn the DN of the user entry");
+            System.out.println("password new password of the user");
+            System.exit(0);
+        }
+        
+        String instanceDir = args[0];
+        String userDn = args[1];
+        String password = args[2];
+        
+        InstanceLayout layout = new InstanceLayout(instanceDir);
+        ApacheDsService ads = new ApacheDsService();
+        ads.start(layout);
+        DirectoryService ds = ads.getDirectoryService();
+        AuthenticationInterceptor authInterceptor = (AuthenticationInterceptor)ds.getInterceptor(InterceptorEnum.AUTHENTICATION_INTERCEPTOR.getName());
+        // disable ppolicy
+        authInterceptor.setPwdPolicyContainer(null);
+        
+        CoreSession session = ds.getAdminSession();
+
+        try {
+            Dn dn = new Dn(ds.getSchemaManager(), userDn);
+            Entry entry = session.lookup(dn, SchemaConstants.ALL_USER_ATTRIBUTES);
+            if(entry == null) {
+                System.out.println( "No such user exists" );
+            }
+            else {
+                AttributeType atTpe = ds.getSchemaManager().lookupAttributeTypeRegistry(SchemaConstants.USER_PASSWORD_AT);
+                Attribute pwdAt = new DefaultAttribute(atTpe);
+                pwdAt.add(Strings.getBytesUtf8(password));
+                
+                Modification mod = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE,
pwdAt);
+                
+                session.modify(dn, mod);
+                
+                System.out.println("Successfully modified password");
+            }
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            System.out.println("Failed to update password");
+        }
+        
+        ads.stop();
+    }
+}



Mime
View raw message