AuthenticationHandlerpublic class AuthenticationHandler extends Object implements GDataRequestHandler
Fields Summary |
---|
private static final Log | LOG | private final org.apache.lucene.gdata.server.authentication.AuthenticationController | controller | private static final String | errorKey | private static final char | seperatory | private final org.apache.lucene.gdata.server.ServiceFactory | serviceFactory | private final org.apache.lucene.gdata.server.registry.GDataServerRegistry | registry |
Constructors Summary |
---|
public AuthenticationHandler()
this.registry = GDataServerRegistry.getRegistry();
this.controller = this.registry.lookup(AuthenticationController.class, ComponentType.AUTHENTICATIONCONTROLLER);
this.serviceFactory = this.registry.lookup(ServiceFactory.class, ComponentType.SERVICEFACTORY);
|
Methods Summary |
---|
private org.apache.lucene.gdata.data.GDataAccount | getAccount(java.lang.String accountName)
AdminService service = this.serviceFactory.getAdminService();
try{
return service.getAccount(accountName);
}finally{
service.close();
}
| public void | processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
try {
String serviceName = request.getParameter(AuthenticationController.SERVICE_PARAMETER);
if(LOG.isInfoEnabled()){
String application = request.getParameter(AuthenticationController.APPLICATION_PARAMETER);
LOG.info("Authentication request for service: "+serviceName+"; Application name: "+application);
}
if(!this.registry.isServiceRegistered(serviceName))
throw new AuthenticationException("requested Service "+serviceName+"is not registered");
String password = request.getParameter(AuthenticationController.PASSWORD_PARAMETER);
String accountName = request.getParameter(AuthenticationController.ACCOUNT_PARAMETER);
String clientIp = request.getRemoteHost();
GDataAccount account = getAccount(accountName);
if(account == null || !account.getPassword().equals(password))
throw new AuthenticationException("Account is null or password does not match");
String token = this.controller.authenticatAccount(account,clientIp);
sendToken(response,token);
if(LOG.isInfoEnabled()){
LOG.info("Account authenticated -- "+account);
}
} catch (AuthenticationException e){
LOG.error("BadAuthentication -- "+e.getMessage(),e);
sendError(response, GDataResponse.FORBIDDEN,"BadAuthentication");
}catch (Exception e) {
LOG.error("Unexpected Exception -- SERVERERROR -- "+e.getMessage(),e);
sendError(response,GDataResponse.SERVER_ERROR, "Service not available");
}
| private void | sendError(javax.servlet.http.HttpServletResponse response, int code, java.lang.String message)
Writer writer = response.getWriter();
writer.write(errorKey);
writer.write(seperatory);
writer.write(message);
response.sendError(code);
| private void | sendToken(javax.servlet.http.HttpServletResponse response, java.lang.String token)
Writer responseWriter = response.getWriter();
Cookie cookie = new Cookie(AuthenticationController.TOKEN_KEY,token);
response.addCookie(cookie);
responseWriter.write(AuthenticationController.TOKEN_KEY);
responseWriter.write(seperatory);
responseWriter.write(token);
responseWriter.close();
|
|