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:
parent
7ce3d368cf
commit
170390224c
|
@ -472,6 +472,7 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
|
||||||
{
|
{
|
||||||
DeferredAuthentication deferred= (DeferredAuthentication)authentication;
|
DeferredAuthentication deferred= (DeferredAuthentication)authentication;
|
||||||
deferred.setIdentityService(_identityService);
|
deferred.setIdentityService(_identityService);
|
||||||
|
deferred.setLoginService(_loginService);
|
||||||
baseRequest.setAuthentication(authentication);
|
baseRequest.setAuthentication(authentication);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.eclipse.jetty.security.Authenticator;
|
import org.eclipse.jetty.security.Authenticator;
|
||||||
import org.eclipse.jetty.security.IdentityService;
|
import org.eclipse.jetty.security.IdentityService;
|
||||||
|
import org.eclipse.jetty.security.LoginService;
|
||||||
import org.eclipse.jetty.security.ServerAuthException;
|
import org.eclipse.jetty.security.ServerAuthException;
|
||||||
import org.eclipse.jetty.security.UserAuthentication;
|
import org.eclipse.jetty.security.UserAuthentication;
|
||||||
import org.eclipse.jetty.server.Authentication;
|
import org.eclipse.jetty.server.Authentication;
|
||||||
|
@ -35,11 +36,22 @@ import org.eclipse.jetty.util.log.Log;
|
||||||
|
|
||||||
public class DeferredAuthentication implements Authentication.Deferred
|
public class DeferredAuthentication implements Authentication.Deferred
|
||||||
{
|
{
|
||||||
protected final LoginAuthenticator _authenticator;
|
protected final Authenticator _authenticator;
|
||||||
|
|
||||||
|
private LoginService _loginService;
|
||||||
private IdentityService _identityService;
|
private IdentityService _identityService;
|
||||||
private Object _previousAssociation;
|
private Object _previousAssociation;
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
public DeferredAuthentication(Authenticator authenticator)
|
||||||
|
{
|
||||||
|
if (authenticator == null)
|
||||||
|
throw new NullPointerException("No Authenticator");
|
||||||
|
this._authenticator = authenticator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public DeferredAuthentication(LoginAuthenticator authenticator)
|
public DeferredAuthentication(LoginAuthenticator authenticator)
|
||||||
{
|
{
|
||||||
if (authenticator == null)
|
if (authenticator == null)
|
||||||
|
@ -65,6 +77,18 @@ public class DeferredAuthentication implements Authentication.Deferred
|
||||||
_identityService = identityService;
|
_identityService = identityService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
public LoginService getLoginService()
|
||||||
|
{
|
||||||
|
return _loginService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
public void setLoginService(LoginService loginService)
|
||||||
|
{
|
||||||
|
_loginService = loginService;
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.Authentication.Deferred#authenticate(ServletRequest)
|
* @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)
|
public Authentication login(String username, String password)
|
||||||
{
|
{
|
||||||
UserIdentity user = _authenticator.getLoginService().login(username,password);
|
if (_loginService!=null)
|
||||||
if (user!=null)
|
{
|
||||||
return new UserAuthentication("API",user);
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue