Package com.draagon.wii.servlet.jaas

Source Code of com.draagon.wii.servlet.jaas.JaasWIIServlet

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.draagon.wii.servlet.jaas;

import com.draagon.util.Configuration;
import com.draagon.wii.config.PropertyConfiguration;
import com.draagon.wii.servlet.WIIServlet;
import com.draagon.wii.servlet.WIIServletRequest;
import com.draagon.wii.servlet.WIIServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.security.Principal;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

/**
*
* @author dmealing
*/
public class JaasWIIServlet extends WIIServlet {

    private Configuration mWIIProps = null;
   
    @Override
    public void init(ServletConfig config) throws ServletException
    {
        super.init(config);

        mServletName = "Draagon Web ii adapter for the Draagon Framework";

        // Get the name of the Bean holding the properties
        String propsName = config.getServletContext().getInitParameter( "wiiProperties" );
        if ( propsName == null ) propsName = "wii.properties";
       
        mWIIProps = new Configuration();
        try
        {
          InputStream fis = ClassLoader.getSystemResourceAsStream( propsName );
          mWIIProps.load( fis );
          fis.close();
        }
        catch( IOException e ) {
          throw new ServletException( "Could not load Webii properties file [" + propsName + "]: " + e.getMessage() );
        }

        initialize( config, new PropertyConfiguration( mWIIProps ));
    }

    @Override
    protected boolean loadUser(WIIServletRequest request, WIIServletResponse response) throws IOException {

        String user = request.getServletRequest().getRemoteUser();       
        Principal p = request.getServletRequest().getUserPrincipal();
        if ( p != null ) user = p.getName();
       
        JAASUser u = new JAASUser( user, request.getServletRequest().getSession() );
        request.setUser(u);
       
        return true;
    }
   
}
TOP

Related Classes of com.draagon.wii.servlet.jaas.JaasWIIServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.