improved fix for 324505 Implement API login

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2640 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2011-01-10 15:13:24 +00:00
parent 7ce3d368cf
commit 170390224c
2 changed files with 37 additions and 4 deletions

View File

@ -472,6 +472,7 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
{
DeferredAuthentication deferred= (DeferredAuthentication)authentication;
deferred.setIdentityService(_identityService);
deferred.setLoginService(_loginService);
baseRequest.setAuthentication(authentication);
try

View File

@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.security.Authenticator;
import org.eclipse.jetty.security.IdentityService;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.security.ServerAuthException;
import org.eclipse.jetty.security.UserAuthentication;
import org.eclipse.jetty.server.Authentication;
@ -35,11 +36,22 @@ import org.eclipse.jetty.util.log.Log;
public class DeferredAuthentication implements Authentication.Deferred
{
protected final LoginAuthenticator _authenticator;
protected final Authenticator _authenticator;
private LoginService _loginService;
private IdentityService _identityService;
private Object _previousAssociation;
/* ------------------------------------------------------------ */
public DeferredAuthentication(Authenticator authenticator)
{
if (authenticator == null)
throw new NullPointerException("No Authenticator");
this._authenticator = authenticator;
}
/* ------------------------------------------------------------ */
public DeferredAuthentication(LoginAuthenticator authenticator)
{
if (authenticator == null)
@ -65,6 +77,18 @@ public class DeferredAuthentication implements Authentication.Deferred
_identityService = identityService;
}
/* ------------------------------------------------------------ */
public LoginService getLoginService()
{
return _loginService;
}
/* ------------------------------------------------------------ */
public void setLoginService(LoginService loginService)
{
_loginService = loginService;
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.server.Authentication.Deferred#authenticate(ServletRequest)
@ -115,9 +139,17 @@ public class DeferredAuthentication implements Authentication.Deferred
*/
public Authentication login(String username, String password)
{
UserIdentity user = _authenticator.getLoginService().login(username,password);
if (user!=null)
return new UserAuthentication("API",user);
if (_loginService!=null)
{
UserIdentity user = _loginService.login(username,password);
if (user!=null)
{
UserAuthentication authentication = new UserAuthentication("API",user);
if (_identityService!=null)
_previousAssociation=_identityService.associate(user);
return authentication;
}
}
return null;
}