提交 23bafefc 编写于 作者: K kohsuke

made it possible to distinguish "no such user" from "I don't know if there's...

made it possible to distinguish "no such user" from "I don't know if there's such an user", so that the UI can use this to improve error diagnostics.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14871 71c3de6d-444a-0410-be80-ed276b4c234a
上级 6d15fb33
......@@ -187,7 +187,7 @@ public class LDAPSecurityRealm extends SecurityRealm {
return ldapSerach.searchForUser(username);
} catch (LdapDataAccessException e) {
LOGGER.log(Level.WARNING, "Failed to search LDAP for username="+username,e);
throw new UsernameNotFoundException(e.getMessage(),e);
throw new UserMayOrMayNotExistException(e.getMessage(),e);
}
}
});
......
......@@ -15,11 +15,14 @@ import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.ui.rememberme.RememberMeServices;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.dao.DataAccessException;
import javax.imageio.ImageIO;
import javax.servlet.Filter;
......@@ -156,6 +159,18 @@ public abstract class SecurityRealm implements Describable<SecurityRealm>, Exten
return clz.getClassLoader().getResource(clz.getName().replace('.','/')+"/signup.jelly")!=null;
}
/**
* Shortcut for {@link UserDetailsService#loadUserByUsername(String)}.
*
* @throws UserMayOrMayNotExistException
* If the security realm cannot even tell if the user exists or not.
* @return
* never null.
*/
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
return getSecurityComponents().userDetails.loadUserByUsername(username);
}
/**
* {@link DefaultManageableImageCaptchaService} holder to defer initialization.
*/
......
......@@ -17,7 +17,7 @@ public class UserDetailsServiceProxy implements UserDetailsService {
UserDetailsService uds = delegate; // fix the reference for concurrency support
if(uds ==null)
throw new UsernameNotFoundException(Messages.UserDetailsServiceProxy_UnableToQuery(username));
throw new UserMayOrMayNotExistException(Messages.UserDetailsServiceProxy_UnableToQuery(username));
return uds.loadUserByUsername(username);
}
......
package hudson.security;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.acegisecurity.userdetails.UserDetailsService;
/**
* Thrown from {@link UserDetailsService#loadUserByUsername(String)}
* to indicate that the underlying {@link SecurityRealm} is incapable
* of retrieving the information, and furthermore, the system cannot
* tell if such an user exists or not.
*
* <p>
* This happens, for example, when the security realm is on top of the servlet implementation,
* there's no way of even knowing if an user of a given name exists or not.
*
* @author Kohsuke Kawaguchi
* @since 1.280
*/
public class UserMayOrMayNotExistException extends UsernameNotFoundException {
public UserMayOrMayNotExistException(String msg) {
super(msg);
}
public UserMayOrMayNotExistException(String msg, Object extraInformation) {
super(msg, extraInformation);
}
public UserMayOrMayNotExistException(String msg, Throwable t) {
super(msg, t);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册