Note that there are some explanatory texts on larger screens.

plurals
  1. POLdap configuration in Spring Security - own class
    primarykey
    data
    text
    <p>I want to write my own LDAP authentication provider. I am extending <code>AbstractUserDetailsAuthenticationProvider</code>, which has a method <code>retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)</code>. </p> <p>I want to override this method and write my own data retrieving method. How to do that in Java? How to make an LDAP query and how connect to the LDAP server? I was searching in Internet but I didn't find anything that helped.</p> <p>EDIT: 22.01.2013</p> <pre><code>@Override protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException { LdapUser userDetail = null; log.entry("retrieveUser", authentication.getPrincipal()); UsernamePasswordAuthenticationToken userToken = authentication; String userName = userToken.getName(); userName = userName != null ? userName.toLowerCase() : userName; String password = userToken.getCredentials().toString(); try { if (password == null || "".equals(password)) { log.debug("retrieveUser", "no password provided"); throw new AuthenticationCredentialsNotFoundException( "Invalid login or password"); } } catch (AuthenticationCredentialsNotFoundException e) { log.debug("retrieveUser", "no password provided"); } // connection with ldap and check retrieved username and password connect = connection(userName, password); if (connect) { log.debug("retrieve user", "correct connection with ldap"); userDetail = new LdapUser(); setUserDetails(userDetail, ctx, username); } else { log.error("retrieve user", "Failed connection"); } log.exit("retrieveUser", "user logged: " + userDetail); return userDetail; } </code></pre> <p>My security.xml file</p> <pre><code>&lt;http auto-config='true'&gt; &lt;intercept-url pattern="/**/*.ico" filters="none" /&gt; &lt;intercept-url pattern="/**/*.gif" filters="none" /&gt; &lt;intercept-url pattern="/**/*.jpg" filters="none" /&gt; &lt;intercept-url pattern="/**/*.css" filters="none" /&gt; &lt;intercept-url pattern="/**/*.js" filters="none" /&gt; &lt;intercept-url pattern="/**/*.png" filters="none" /&gt; &lt;intercept-url pattern="/logout.jsp*" filters="none" /&gt; &lt;intercept-url pattern="/index.jsp*" filters="none" /&gt; &lt;intercept-url pattern="/**" access="ROLE_USER,ROLE_ADMIN" /&gt; &lt;logout logout-success-url="/index.jsp"/&gt; &lt;form-login login-page="/index.jsp" authentication-failure-url="/error_ldap.jsp" default-target-url="/main_ldap.jsp" always-use-default-target="true" /&gt; &lt;/http&gt; &lt;authentication-manager&gt; &lt;authentication-provider ref="ldapAuthenticationProvider"&gt; &lt;password-encoder hash="sha" /&gt; &lt;/authentication-provider&gt; &lt;/authentication-manager&gt; </code></pre> <p>When login is suceed I got redirect to main_ldap.jsp, but if authentication fail, I got this error. I tried to throw exception UsernameNotFoundException instead returning null in retrieveUser method (which is not allowed) but anything happend (only i got this exception).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload