Package org.apache.ws.util.jndi

Source Code of org.apache.ws.util.jndi.BeanFactory$GetInstanceAction

/*
* This file or a portion of this file is licensed under the terms of the
* Globus Toolkit Public License, found at
* http://www.globus.org/toolkit/download/license.html.
* If you redistribute this file, with or without modifications,
* you must include this notice in the file.
*/
package org.apache.ws.util.jndi;

import org.apache.axis.AxisEngine;
import org.apache.axis.MessageContext;

import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.security.auth.Subject;
import java.security.PrivilegedExceptionAction;
import java.util.Hashtable;

/**
* LOG-DONE
*/
public class BeanFactory extends BasicBeanFactory {

    /**                  //todo axis package!
     * Create a new Bean instance. If <code>obj</code> is of type
     * {@link org.globus.wsrf.jndi.ServiceResourceRef ServiceResourceRef} the bean will be
     * created and initialized with security credentials associated
     * with the current thread if the service associated with this bean
     * has a security descriptor configured.
     */
    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                    Hashtable environment)
        throws NamingException {
        Subject subject = null;
        MessageContext msgCtx = null;

        if (obj instanceof ServiceResourceRef) {
            ServiceResourceRef resource = (ServiceResourceRef)obj;
            AxisEngine engine = resource.getAxisEngine();
            String serviceName =  resource.getServiceName();
            if (engine == null) {
                throw new NamingException("noServiceSet");
            }
            if (serviceName == null) {
                throw new NamingException("noEngineSet");
            }}

           /* ServiceManager serviceManager =
                ServiceManager.getServiceManager((AxisServer)engine);
            SecurityManager securityManager =
                SecurityManager.getManager();

            try {
                msgCtx = serviceManager.createMessageContext(serviceName);
                ServiceSecurityConfig.initialize(msgCtx);
                subject = securityManager.getServiceSubject(serviceName);
            } catch (Exception e) {
                NamingException ne =
                    new NamingException(i18n.getMessage("beanSecInitFailed"));
                ne.setRootCause(e);
                throw ne;
            }
        }*/

        try {
            if (subject == null) {
                return getInstance(msgCtx, obj, name, nameCtx, environment);
            } else {
              /*  GetInstanceAction action =
                    new GetInstanceAction(msgCtx, obj, name,
                                          nameCtx, environment);
                return JaasSubject.doAs(subject, action);*/
            }
        } catch (NamingException e) {
            throw e;
        } /*catch (PrivilegedActionException e) {
            Exception cause = e.getException();
            if (cause instanceof NamingException) {
                throw (NamingException)cause;
            } else {
                NamingException nm =
                    new NamingException("beanInitFailed");
                nm.setRootCause(cause);
                throw nm;
            }
        } */catch (Exception e) {
            NamingException nm =
                new NamingException("beanInitFailed");
            nm.setRootCause(e);
            throw nm;
        }
        //todo fix this method
        return null;
    }

    private Object getInstance(MessageContext msgCtx, Object obj, Name name,
                               Context nameCtx, Hashtable environment)
        throws NamingException {      //todo fix!
       // MessageContext oldCtx =
        //    ServiceManager.HelperAxisEngine.getCurrentMessageContext();
      //  ServiceManager.HelperAxisEngine.setCurrentMessageContext(msgCtx);
        try {
            return super.getObjectInstance(obj, name, nameCtx, environment);
        } finally {
           // ServiceManager.HelperAxisEngine.setCurrentMessageContext(oldCtx);
        }
    }
   
    private class GetInstanceAction implements PrivilegedExceptionAction {

        private MessageContext msgCtx;
        private Object obj;
        private Name name;
        private Context nameCtx;
        private Hashtable environment;

        private GetInstanceAction(MessageContext msgCtx, Object obj, Name name,
                                  Context nameCtx, Hashtable environment) {
            this.msgCtx = msgCtx;
            this.obj = obj;
            this.name = name;
            this.nameCtx = nameCtx;
            this.environment = environment;
        }

        public Object run() throws Exception {
            return getInstance(this.msgCtx, this.obj, this.name,
                               this.nameCtx, this.environment);
        }
    }
   
   
}
TOP

Related Classes of org.apache.ws.util.jndi.BeanFactory$GetInstanceAction

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.