Package open.dolphin.impl.login

Source Code of open.dolphin.impl.login.LoginHelper

package open.dolphin.impl.login;

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.ejb.client.ContextSelector;
import org.jboss.ejb.client.EJBClientConfiguration;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;

/**
* jndi 呼び出しのキモ部分の抽出
* AddFacilityDialog, DolphinMasterMaker, OIDGeter, InitDatabase で使用
* @author pns
*/
public class LoginHelper {
   
    // jndi 呼び出し名パラメータ
    private static final String APP_NAME = "opendolphin-ea-ear-1.3.0.8"; // .ear ファイルの名前
    private static final String MODULE_NAME = "opendolphin-ea-ejb-1.3.0.8"; // .jar ファイルの名前
    private static final String DISTINCT_NAME = "";
    private static final String BEAN_NAME = "%sImpl"; // getService に入ってくる name に Impl をつけたものが bean name になる
    private static final String VIEW_CLASS_NAME = "open.dolphin.ejb.%s"; // 実際のクラス名
    private static final String LOOKUP_NAME = "ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME + "/" + BEAN_NAME + "!" + VIEW_CLASS_NAME;
   
    // InitialContext property
    private static final Properties NAMING_PROP = new Properties();
    static {
        NAMING_PROP.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");       
    }
   
    /**
     * EJBClientContext の設定
     * @param hostAddress
     * @param hostPort
     * @param principal
     * @param password
     */
    public static void setEJBClientContext(String hostAddress, String hostPort, String principal, String password) {
        // LoginContext, SecurityAssociation は廃止されて,EJBClientContext を使うようになった
        Properties props = new Properties();
        props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
        props.put("remote.connections", "default");
        props.put("remote.connection.default.host", hostAddress);
        props.put("remote.connection.default.port", hostPort);
        props.put("remote.connection.default.username", principal);
        props.put("remote.connection.default.password", password);
        //props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
        props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");

        // create client configuration
        final EJBClientConfiguration clientConfiguration = new PropertiesBasedEJBClientConfiguration(props);
        // create a context selector
        final ContextSelector<EJBClientContext> contextSelector = new ConfigBasedEJBClientContextSelector(clientConfiguration);
        // set the selector for use
        EJBClientContext.setSelector(contextSelector);       
    }
   
    /**
     * jndi 呼び出しヘルパー
     * @param className
     * @return
     * @throws NamingException
     */
    public static Object lookup(String className) throws NamingException {
        //System.out.println("jndi name = " + String.format(LOOKUP_NAME, className, className));
        return new InitialContext(NAMING_PROP).lookup(String.format(LOOKUP_NAME, className, className));               
    }
}
TOP

Related Classes of open.dolphin.impl.login.LoginHelper

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.