You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by sz...@apache.org on 2010/02/07 15:35:04 UTC
svn commit: r907424 - in
/directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash:
HashTools.java PasswordHashInterceptor.java
Author: szoerner
Date: Sun Feb 7 14:35:03 2010
New Revision: 907424
URL: http://svn.apache.org/viewvc?rev=907424&view=rev
Log:
Improvements by Emmanuel applied
Modified:
directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/HashTools.java
directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/PasswordHashInterceptor.java
Modified: directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/HashTools.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/HashTools.java?rev=907424&r1=907423&r2=907424&view=diff
==============================================================================
--- directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/HashTools.java (original)
+++ directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/HashTools.java Sun Feb 7 14:35:03 2010
@@ -31,7 +31,7 @@
}
private static final String[] hashAlgorithms = { "MD5", "SHA", "SSHA",
- "SMD5" };
+ "SMD5", "SHA-256" };
/**
* Detects whether a value has already been hashed with a known message
Modified: directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/PasswordHashInterceptor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/PasswordHashInterceptor.java?rev=907424&r1=907423&r2=907424&view=diff
==============================================================================
--- directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/PasswordHashInterceptor.java (original)
+++ directory/sandbox/szoerner/passwordHashInterceptor/src/main/java/org/apache/directory/samples/interceptor/pwdhash/PasswordHashInterceptor.java Sun Feb 7 14:35:03 2010
@@ -23,7 +23,6 @@
import static org.apache.directory.samples.interceptor.pwdhash.HashTools.isAlreadyHashed;
import java.util.List;
-import java.util.Set;
import org.apache.directory.server.core.entry.ClonedServerEntry;
import org.apache.directory.server.core.interceptor.BaseInterceptor;
@@ -33,20 +32,36 @@
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
-import org.apache.directory.shared.ldap.schema.AttributeType;
public class PasswordHashInterceptor extends BaseInterceptor {
+ private String hashAlgorithm = "MD5";
+
private String passwordAttributeName = "userPassword";
- private String hashAlgorithm = "MD5";
+ public void setHashAlgorithm(String hashAlgorithm) {
+ this.hashAlgorithm = hashAlgorithm;
+ }
public void setPasswordAttributeName(String passwordAttributeName) {
this.passwordAttributeName = passwordAttributeName;
}
- public void setHashAlgorithm(String hashAlgorithm) {
- this.hashAlgorithm = hashAlgorithm;
+ /**
+ * Intercepts the add operation in order to replace plain password values
+ * with hashed ones.
+ */
+ @Override
+ public void add(NextInterceptor next, AddOperationContext opContext)
+ throws Exception {
+
+ ClonedServerEntry entry = opContext.getEntry();
+ EntryAttribute attribute = entry.get(passwordAttributeName);
+ if (attribute != null) {
+ hashPasswordIfNeccessary(attribute);
+ }
+
+ super.add(next, opContext);
}
/**
@@ -59,8 +74,9 @@
List<Modification> items = opContext.getModItems();
for (Modification modification : items) {
- if (modification.getOperation() == ModificationOperation.ADD_ATTRIBUTE
- || modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE) {
+ ModificationOperation operation = modification.getOperation();
+ if (operation == ModificationOperation.ADD_ATTRIBUTE
+ || operation == ModificationOperation.REPLACE_ATTRIBUTE) {
EntryAttribute attribute = modification.getAttribute();
if (attribute.getId().equalsIgnoreCase(passwordAttributeName)) {
hashPasswordIfNeccessary(attribute);
@@ -70,26 +86,6 @@
super.modify(next, opContext);
}
- /**
- * Intercepts the add operation in order to replace plain password values
- * with hashed ones.
- */
- @Override
- public void add(NextInterceptor next, AddOperationContext opContext)
- throws Exception {
-
- ClonedServerEntry entry = opContext.getEntry();
- Set<AttributeType> attributeTypes = entry.getAttributeTypes();
- for (AttributeType attributeType : attributeTypes) {
- if (attributeType.getName().equalsIgnoreCase(passwordAttributeName)) {
- EntryAttribute attribute = entry.get(attributeType);
- hashPasswordIfNeccessary(attribute);
- }
- }
-
- super.add(next, opContext);
- }
-
protected void hashPasswordIfNeccessary(EntryAttribute attribute) {
try {
byte[] password = attribute.getBytes();