420530 AbstractLoginModule never fails a login

Conflicts:
	jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/AbstractLoginModule.java
	jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModule.java
This commit is contained in:
Jan Bartel 2013-10-29 12:24:03 +11:00
parent 3a10aa4164
commit b6a306a6b8
2 changed files with 26 additions and 11 deletions

View File

@ -31,6 +31,7 @@ import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;
@ -199,9 +200,14 @@ public abstract class AbstractLoginModule implements LoginModule
callbacks[2] = new PasswordCallback("Enter password", false); //only used if framework does not support the ObjectCallback
return callbacks;
}
public boolean isIgnored ()
{
return false;
}
public abstract UserInfo getUserInfo (String username) throws Exception;
@ -214,7 +220,10 @@ public abstract class AbstractLoginModule implements LoginModule
public boolean login() throws LoginException
{
try
{
{
if (isIgnored())
return false;
if (callbackHandler == null)
throw new LoginException ("No callback handler");
@ -231,7 +240,7 @@ public abstract class AbstractLoginModule implements LoginModule
if ((webUserName == null) || (webCredential == null))
{
setAuthenticated(false);
return isAuthenticated();
throw new FailedLoginException();
}
UserInfo userInfo = getUserInfo(webUserName);
@ -239,12 +248,16 @@ public abstract class AbstractLoginModule implements LoginModule
if (userInfo == null)
{
setAuthenticated(false);
return isAuthenticated();
throw new FailedLoginException();
}
currentUser = new JAASUserInfo(userInfo);
setAuthenticated(currentUser.checkCredential(webCredential));
return isAuthenticated();
if (isAuthenticated())
return true;
else
throw new FailedLoginException();
}
catch (IOException e)
{
@ -256,7 +269,8 @@ public abstract class AbstractLoginModule implements LoginModule
}
catch (Exception e)
{
e.printStackTrace();
if (e instanceof LoginException)
throw (LoginException)e;
throw new LoginException (e.toString());
}
}

View File

@ -112,9 +112,10 @@ public class PropertyFileLoginModule extends AbstractLoginModule
PropertyUserStore propertyUserStore = _propertyUserStores.get(_filename);
if (propertyUserStore == null)
throw new IllegalStateException("PropertyUserStore should never be null here!");
LOG.debug("Checking PropertyUserStore "+_filename+" for "+userName);
UserIdentity userIdentity = propertyUserStore.getUserIdentity(userName);
if(userIdentity==null)
if (userIdentity==null)
return null;
Set<Principal> principals = userIdentity.getSubject().getPrincipals();
@ -127,7 +128,7 @@ public class PropertyFileLoginModule extends AbstractLoginModule
}
Credential credential = (Credential)userIdentity.getSubject().getPrivateCredentials().iterator().next();
LOG.debug("Found: " + userName + " in PropertyUserStore");
LOG.debug("Found: " + userName + " in PropertyUserStore "+_filename);
return new UserInfo(userName, credential, roles);
}