<%@ page import="sun.misc.BASE64Decoder,java.util.Properties,java.io.*" %>
<%@ page import="org.opengion.hayabusa.resource.*,org.opengion.hayabusa.common.*" %>

<%
	String authorization = request.getHeader("Authorization");
	if( authorization == null ) {
		response.setStatus( response.SC_UNAUTHORIZED );
		response.setHeader( "WWW-Authenticate",
							"BASIC realm=\"Web App\"" );
		out.println( "<h1> Error No authorization </h1>" );
		return ;
	}
	else {
		String authName = authorization.substring( 6 ).trim();
		BASE64Decoder decoder = new BASE64Decoder();
		String nameAndPasswd = new String( decoder.decodeBuffer( authName ) );
		int index = nameAndPasswd.indexOf( ":" );
		String userID = nameAndPasswd.substring( 0,index );
		String passwd = nameAndPasswd.substring( index+1 );

		UserInfo userInfo = (UserInfo)session.getAttribute( HybsSystem.USERINFO_KEY );
		String userID2 = null;
		if( userInfo != null ) {
			userID2 = userInfo.getUserID();
			if( !userID2.equals( userID ) ) {
	//			out.println( "<h1> Error No Match UserID [" + userID + "]</h1>" );

				return ;
			}
		}
		response.setStatus( response.SC_UNAUTHORIZED );
		response.setHeader( "WWW-Authenticate",
							"BASIC realm=\"Web App\"" );
		out.println( "<h1> Error No authorization </h1>" );
		out.println( "<h1> Authorization   UserID  [" + userID + "]</h1>" );
		out.println( "<h1> Sesion USERINFO userID2 [" + userID2 + "]</h1>" );
	}

%>

