स्प्रिंग 3.1 बिलाव 6. *स्प्रिंग 3.1 LDAP प्रमाणीकरण प्रक्रिया: "बैड साख" संदेश जब साख अच्छा
मैं एक स्प्रिंग 3.1 webapp बनाने एलडीएपी से प्रमाणीकृत करने पर काम कर रहा हूँ कर रहे हैं।
मैंने एलडीएपी क्रेडेंशियल्स (उपयोगकर्ता नाम, पासवर्ड, एलडीएपी यूआरएल, सर्च पैटर्न) का परीक्षण किया जो मैंने लिखा एक जेएनडीआई स्टाइल जावा प्रोग्राम (नीचे उद्धृत) के साथ किया। उस कार्यक्रम ने काम किया, पासवर्ड सहित सभी उपयोगकर्ता विशेषताओं को छोड़ दिया, जो एलडीएपी सर्वर पर एन्क्रिप्ट किया गया प्रतीत होता है।
जब मैं वसंत 3.1 में समान प्रमाण-पत्रों के साथ लॉगिन करने का प्रयास करता हूं तो मुझे त्रुटि संदेश "खराब प्रमाण पत्र" मिलता है।
मैं लॉग में यह संदेश मिला:
DEBUG [org.springframework.security.authentication.ProviderManager:authenticate] (ProviderManager.java:152) - Authentication attempt using org.springframework.security.ldap.authentication.LdapAuthenticationProvider
DEBUG [org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider:authenticate] (AbstractLdapAuthenticationProvider.java:51) - Processing authentication request for user: John.A.Smith
DEBUG [org.springframework.security.ldap.authentication.BindAuthenticator:bindWithDn] (BindAuthenticator.java:108) - Attempting to bind as uid=John.A.Smith,ou=People,o=acme.com,o=acme.com
DEBUG [org.springframework.security.ldap.DefaultSpringSecurityContextSource$1:setupEnvironment] (DefaultSpringSecurityContextSource.java:76) - Removing pooling flag for user uid=John.A.Smith,ou=People,o=acme.com,o=acme.com
DEBUG [org.springframework.security.ldap.authentication.BindAuthenticator:handleBindException] (BindAuthenticator.java:152) - Failed to bind as uid=John.A.Smith,ou=People,o=acme.gov: org.springframework.ldap.AuthenticationException: [LDAP: error code 32 - No Such Object]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 32 - No Such Object]
DEBUG [org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter:unsuccessfulAuthentication] (AbstractAuthenticationProcessingFilter.java:340) - Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
मेरी * -security.xml मैं एक पासवर्ड तुलना और एन्कोडिंग ऐसा करने के लिए टैग का उपयोग करने की कोशिश की है, लेकिन यह मदद नहीं की। मैंने md4, md5, plaintext, sha, sha-256, {ssha}, {sha} का उपयोग करने का प्रयास करने का प्रयास नहीं किया।
<s:authentication-manager>
<s:ldap-authentication-provider user-dn-pattern="uid={0},ou=People,o=noaa.gov" >
<s:password-compare hash="md5">
<s:password-encoder hash="md5"/>
</s:password-compare>
</s:ldap-authentication-provider>
</s:authentication-manager>
मेरा नेटवर्किंग समूह एक बड़ा, धीमा, नौकरशाही संगठन है। क्या कोई तरीका है कि मैं बता सकता हूं कि वे किस एन्कोडिंग का उपयोग करते हैं, अगर कोई है, तो उनसे संपर्क किए बिना?
चीजों के बारे में कोई भी विचार जो मैं देख सकता हूं?
यह मेरा आखिरी प्रयास और जावा LDAP डेमो मैं साथ
धन्यवाद कनेक्ट कर सकता था की के रूप में मेरे * -security.xml है।
मेरे * -security.xml फ़ाइल:
import javax.naming.*;
import javax.naming.directory.*;
import java.util.*;
import java.sql.*;
public class LDAPDEMO {
public static void main(String args[]) {
String lcf = "com.sun.jndi.ldap.LdapCtxFactory";
String ldapurl = "ldap://ldap-itc.sam.acme.com:636/o=acme.com";
String loginid = "John.A.Smith";
String password = "passowordforjohn";
DirContext ctx = null;
Hashtable env = new Hashtable();
Attributes attr = null;
Attributes resultsAttrs = null;
SearchResult result = null;
NamingEnumeration results = null;
int iResults = 0;
env.put(Context.INITIAL_CONTEXT_FACTORY, lcf);
env.put(Context.PROVIDER_URL, ldapurl);
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid=" + loginid + ",ou=People,o=acme.com");
env.put(Context.SECURITY_CREDENTIALS, password);
try {
ctx = new InitialDirContext(env);
attr = new BasicAttributes(true);
attr.put(new BasicAttribute("uid",loginid));
results = ctx.search("ou=People",attr);
while (results.hasMore()) {
result = (SearchResult)results.next();
resultsAttrs = result.getAttributes();
for (NamingEnumeration enumAttributes = resultsAttrs.getAll(); enumAttributes.hasMore();) {
Attribute a = (Attribute)enumAttributes.next();
System.out.println("attribute: " + a.getID() + " : " + a.get().toString());
}// end for loop
iResults++;
}// end while loop
System.out.println("iResults == " + iResults);
}// end try
catch (Exception e) {
e.printStackTrace();
}
}// end function main()
}// end class LDAPDEMO
समाधान:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:s="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<s:http auto-config="true" use-expressions="true">
**<s:intercept-url pattern="/welcome*" access="isAuthenticated()" />**
<s:form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<s:logout logout-success-url="/logout" />
</s:http>
<s:ldap-server url = "ldap://ldap-itc.sam.acme.com:636/o=acme.com"/>
<s:authentication-manager>
<s:ldap-authentication-provider user-dn-pattern="uid={0},ou=People,o=noaa.gov" />
</s:authentication-manager>
</beans>
यहाँ JNDI शैली LDAP जावा प्रोग्राम है कि एक ही पहचान के साथ काम करता है
ल्यूक टेलर से यह टिप्पणी मुझे मेरे विन्यास काम करने में मदद मिली:
आपका विन्यास कि में गलत है तुम हो "ओ = acme.com" LDAP सर्वर URL में और भी प्रयोग कर रहे हैं " ओ = acme.com "उपयोगकर्ता डीएन पैटर्न में।
मैंने डीएन पैटर्न से बाहर "ओ = acme.com" लिया और एलडीएपी ने काम किया। मैंने मूल रूप से एलडीएपी यूआरएल और डीएन पैटर्न दोनों में "ओ = acme.com" रखा था क्योंकि मैं स्प्रिंग 3.1 और एलडीएपी के लिए नया हूं, और यह एलडीएपी के जावा जेएनडीआई संस्करण में कैसे किया गया है/जैसा किया गया है डेमो मैंने लीगेसी कोड के आधार पर लिखा है जिसे मैं बदल रहा हूं।
यहां मेरे * -सुरिटी का अंतिम, कामकाजी संस्करण है।एक्सएमएल
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:s="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<s:http auto-config="true" use-expressions="true">
**<s:intercept-url pattern="/welcome*" access="isAuthenticated()" />**
<s:form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<s:logout logout-success-url="/logout" />
</s:http>
<s:ldap-server url = "ldap://ldap-itc.sam.acme.com:636/o=acme.com"/>
<s:authentication-manager>
<s:ldap-authentication-provider user-dn-pattern="uid={0},ou=People" />
</s:authentication-manager>
</beans>
मैं अपने अन्य टिप्पणी का पता लगाने और देखें कि क्या मैं में या अगर मैं करने की जरूरत है वापस पासवर्ड एन्कोडिंग रख सकते हैं करने के लिए जा रहा हूँ।
एक और नोट। आप पासवर्ड एन्कोडिंग को वापस नहीं डाल सकते हैं, क्योंकि आप नहीं जानते कि सर्वर किस एल्गोरिदम का उपयोग कर रहा है और व्यवहार में यह एक से अधिक का उपयोग कर सकता है। हैशिंग पासवर्ड पासवर्ड डेटाबेस को सुरक्षित करना इसे कठिन बनाकर सुरक्षित करना है। यह क्लाइंट प्रमाणीकरण को और अधिक सुरक्षित बनाने के बारे में नहीं है (आपको इस पर कई चर्चाएं मिलेंगी)। यदि आप अपने ऐप से एलडीएपी सर्वर पर नेटवर्क पर ईव्सड्रॉपिंग को रोकना चाहते हैं, तो एसएसएल कनेक्शन का उपयोग करना शायद सबसे आसान विकल्प है। –