提交 8f7cad06 编写于 作者: C Cyrille Le Clerc 提交者: Oleg Nenashev

Better exception message if a SecurityRealm doesn't respect the API contract...

Better exception message if a SecurityRealm doesn't respect the API contract and return null (#2407)

* Getter exception message if the SecurityRealm doesn't respect the API contract and return null.

* Use NullPointerException instead of IllegalStateException to not change the behaviour of the method.
上级 200a0beb
......@@ -1054,7 +1054,12 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
if (!resolving.get()) {
resolving.set(true);
try {
return j.getSecurityRealm().loadUserByUsername(idOrFullName).getUsername();
UserDetails userDetails = j.getSecurityRealm().loadUserByUsername(idOrFullName);
if (userDetails == null) {
throw new NullPointerException("hudson.security.SecurityRealm should never return null. "
+ j.getSecurityRealm() + " returned null for idOrFullName='" + idOrFullName + "'");
}
return userDetails.getUsername();
} catch (UsernameNotFoundException x) {
LOGGER.log(Level.FINE, "not sure whether " + idOrFullName + " is a valid username or not", x);
} catch (DataAccessException x) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册