All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.antelopeframework.httpinvoker.server.HessianServiceExporter Maven / Gradle / Ivy

package com.github.antelopeframework.httpinvoker.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;

import lombok.Setter;

@Setter
public class HessianServiceExporter extends org.springframework.remoting.caucho.HessianServiceExporter {
	public final static String HTTPINVOKER_PARAM_APP = "_httpinvoker_app";
	public final static String HTTPINVOKER_PARAM_USER = "_httpinvoker_user";
	public final static String HTTPINVOKER_PARAM_PASSWORD = "_httpinvoker_password";
	public final static String HTTPINVOKER_PARAM_TIMESTAMP = "_httpinvoker_timestamp";
	
	private AuthObtainer authObtainer;
	
	@Override
	public void handleRequest(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String _app = request.getHeader(HTTPINVOKER_PARAM_APP); 
		String _username = request.getHeader(HTTPINVOKER_PARAM_USER);  
        String _password = request.getHeader(HTTPINVOKER_PARAM_PASSWORD); 
        
        if (StringUtils.isAnyBlank(_app, _username, _password)) {
        	throw new ServletException("Unknow app/user/password.");  
        }
        
        UserPasswodPair pair = authObtainer.get(_app);
        
        if (!StringUtils.equals(pair.getUser(), _username) || !StringUtils.equals(pair.getPassword(), _password)) {
        	throw new ServletException("Authorization failed.");  
        }
        
		super.handleRequest(request, response);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy