Search in sources :

Example 1 with Password

use of com.sun.messaging.jmq.util.Password in project openmq by eclipse-ee4j.

the class LdapUserRepository method open.

@Override
public void open(String authType, Properties authProperties, Refreshable cacheData) throws LoginException {
    this.authType = authType;
    this.authProps = authProperties;
    String rep = authProps.getProperty(AccessController.PROP_AUTHENTICATION_PREFIX + authType + AccessController.PROP_USER_REPOSITORY_SUFFIX);
    if (rep == null) {
        throw new LoginException(Globals.getBrokerResources().getKString(BrokerResources.X_USER_REPOSITORY_NOT_DEFINED, authType));
    }
    repository = rep;
    if (!rep.equals(TYPE)) {
        String[] args = { rep, TYPE, this.getClass().getName() };
        throw new LoginException(Globals.getBrokerResources().getKString(BrokerResources.X_REPOSITORY_TYPE_MISMATCH, args));
    }
    String prefix = AccessController.PROP_USER_REPOSITORY_PREFIX + rep;
    server = authProps.getProperty(prefix + PROP_SERVER_SUFFIX);
    if (server == null || server.trim().equals("")) {
        String[] args = { authType, rep, PROP_SERVER_SUFFIX };
        throw new LoginException(Globals.getBrokerResources().getKString(BrokerResources.X_LDAP_REPOSITORY_PROPERTY_NOT_DEFINED, args));
    }
    server = "ldap://" + server;
    bindDN = authProps.getProperty(prefix + PROP_BINDDN_SUFFIX);
    if (bindDN != null && !bindDN.trim().equals("")) {
        bindPW = authProps.getProperty(prefix + PROP_BINDPW_SUFFIX);
        int retry = 0;
        Password pw = null;
        boolean setProp = bindPW == null || bindPW.equals("");
        while ((bindPW == null || bindPW.trim().equals("")) && retry < 5) {
            pw = new Password();
            if (pw.echoPassword()) {
                System.err.println(Globals.getBrokerResources().getString(BrokerResources.W_ECHO_PASSWORD));
            }
            System.err.print(Globals.getBrokerResources().getString(BrokerResources.M_ENTER_KEY_LDAP, bindDN));
            System.err.flush();
            bindPW = pw.getPassword();
            // Limit the number of times we try reading the passwd.
            // If the VM is run in the background the readLine()
            // will always return null and we'd get stuck in the loop
            retry++;
        }
        if (bindPW == null || bindPW.trim().equals("")) {
            logger.log(Logger.WARNING, BrokerResources.W_NO_LDAP_PASSWD, bindPW);
            bindDN = null;
        } else if (setProp) {
            authProps.put(prefix + PROP_BINDPW_SUFFIX, bindPW);
        }
    } else {
        bindDN = null;
    }
    usrformat = authProps.getProperty(prefix + PROP_USRFORMAT_SUFFIX);
    if (usrformat != null) {
        usrformat = usrformat.trim();
        if (usrformat.equals("")) {
            usrformat = null;
        } else if (!usrformat.trim().equals(DN_USRFORMAT)) {
            throw new LoginException(Globals.getBrokerResources().getKString(BrokerResources.X_UNSUPPORTED_PROPERTY_VALUE, "" + prefix + PROP_USRFORMAT_SUFFIX, usrformat));
        }
    }
    base = authProps.getProperty(prefix + PROP_BASE_SUFFIX);
    if (base != null && base.trim().equals("")) {
        base = null;
    }
    if (base == null && (usrformat == null || !usrformat.equals(DN_USRFORMAT))) {
        String[] args = { authType, rep, PROP_BASE_SUFFIX };
        throw new LoginException(Globals.getBrokerResources().getKString(BrokerResources.X_LDAP_REPOSITORY_PROPERTY_NOT_DEFINED, args));
    }
    ldapbase = null;
    if (base != null && usrformat != null && usrformat.equals(DN_USRFORMAT)) {
        try {
            ldapbase = new LdapName(base);
        } catch (Exception e) {
            throw new LoginException(e.toString());
        }
    }
    uidattr = authProps.getProperty(prefix + PROP_UIDATTR_SUFFIX);
    if (uidattr == null || uidattr.trim().equals("")) {
        String[] args = { authType, rep, PROP_UIDATTR_SUFFIX };
        throw new LoginException(Globals.getBrokerResources().getKString(BrokerResources.X_LDAP_REPOSITORY_PROPERTY_NOT_DEFINED, args));
    }
    usrfilter = authProps.getProperty(prefix + PROP_USRFILTER_SUFFIX);
    if (usrfilter != null && usrfilter.trim().equals("")) {
        usrfilter = null;
    }
    String tlimit = authProps.getProperty(prefix + PROP_TIMEOUT_SUFFIX);
    if (tlimit != null) {
        try {
            timelimitMillis = Integer.parseInt(tlimit) * 1000;
        } catch (NumberFormatException e) {
            timelimitMillis = -1;
        }
    }
    if (timelimitMillis < 0) {
        timelimitMillis = DEFAULT_TIMELIMIT_MILLIS;
    }
    String grpsrch = authProps.getProperty(prefix + PROP_GRPSEARCH_SUFFIX);
    if (grpsrch != null && grpsrch.equals("false")) {
        grpsearch = false;
    }
    if (grpsearch) {
        grpbase = authProps.getProperty(prefix + PROP_GRPBASE_SUFFIX);
        if (grpbase == null || grpbase.trim().equals("")) {
            String[] args = { authType, rep, PROP_GRPBASE_SUFFIX };
            throw new LoginException(Globals.getBrokerResources().getKString(BrokerResources.X_LDAP_REPOSITORY_PROPERTY_NOT_DEFINED, args));
        }
        gidattr = authProps.getProperty(prefix + PROP_GIDATTR_SUFFIX);
        if (gidattr == null || gidattr.trim().equals("")) {
            String[] args = { authType, rep, PROP_GIDATTR_SUFFIX };
            throw new LoginException(Globals.getBrokerResources().getKString(BrokerResources.X_LDAP_REPOSITORY_PROPERTY_NOT_DEFINED, args));
        }
        memattr = authProps.getProperty(prefix + PROP_MEMATTR_SUFFIX);
        if (memattr == null || memattr.trim().equals("")) {
            String[] args = { authType, rep, PROP_MEMATTR_SUFFIX };
            throw new LoginException(Globals.getBrokerResources().getKString(BrokerResources.X_LDAP_REPOSITORY_PROPERTY_NOT_DEFINED, args));
        }
        grpfilter = authProps.getProperty(prefix + PROP_GRPFILTER_SUFFIX);
        if (grpfilter != null && grpfilter.trim().equals("")) {
            grpfilter = null;
        }
    }
    // if grpsearch
    String ssl = authProps.getProperty(prefix + PROP_SSL_SUFFIX);
    if (ssl != null && ssl.equals("true")) {
        sslprotocol = true;
        ssl = authProps.getProperty(prefix + PROP_SSLFACTORY_SUFFIX);
        if (ssl != null && !ssl.trim().equals("")) {
            sslfactory = ssl.trim();
        }
    }
}
Also used : LoginException(javax.security.auth.login.LoginException) FailedLoginException(com.sun.messaging.jmq.auth.api.FailedLoginException) LoginException(javax.security.auth.login.LoginException) NamingException(javax.naming.NamingException) FailedLoginException(com.sun.messaging.jmq.auth.api.FailedLoginException) Password(com.sun.messaging.jmq.util.Password) LdapName(javax.naming.ldap.LdapName)

Example 2 with Password

use of com.sun.messaging.jmq.util.Password in project openmq by eclipse-ee4j.

the class UserMgrUtils method getPasswordInput.

/**
 * Return password input.
 */
public static String getPasswordInput(UserMgrProperties userMgrProps, String question) {
    Password pw = new Password();
    if (pw.echoPassword()) {
        Output.stdOutPrintln(Globals.getBrokerResources().getString(BrokerResources.W_ECHO_PASSWORD));
    }
    Output.stdOutPrint(question);
    return pw.getPassword();
}
Also used : Password(com.sun.messaging.jmq.util.Password)

Example 3 with Password

use of com.sun.messaging.jmq.util.Password in project openmq by eclipse-ee4j.

the class CommonCmdRunnerUtil method getPassword.

/**
 * Return the password without echoing.
 */
public static String getPassword() {
    Password pw = new Password();
    if (pw.echoPassword()) {
        CommonGlobals.stdOutPrintln(ar.getString(ar.W_ECHO_PASSWORD));
    }
    CommonGlobals.stdOutPrint(ar.getString(ar.I_JMQCMD_PASSWORD));
    return pw.getPassword();
}
Also used : Password(com.sun.messaging.jmq.util.Password)

Example 4 with Password

use of com.sun.messaging.jmq.util.Password in project openmq by eclipse-ee4j.

the class CmdRunner method getPassword.

/**
 * Return user input without echoing, if possible.
 */
private String getPassword(String question) {
    Password pw = new Password();
    if (pw.echoPassword()) {
        Globals.stdOutPrintln(ar.getString(ar.W_ECHO_PASSWORD));
    }
    Globals.stdOutPrint(question);
    return pw.getPassword();
}
Also used : Password(com.sun.messaging.jmq.util.Password)

Example 5 with Password

use of com.sun.messaging.jmq.util.Password in project openmq by eclipse-ee4j.

the class KeystoreUtil method getKeystorePassword.

public static String getKeystorePassword() throws IOException {
    if (pass_phrase == null) {
        BrokerConfig bcfg;
        Password pw = null;
        bcfg = Globals.getConfig();
        // Get Passphrase from property setting
        pass_phrase = bcfg.getProperty(KEYSTORE_PASSWORD_PROP);
        // if passphrase is null then get it thro' user interaction
        int retry = 0;
        pw = new Password();
        if (pw.echoPassword()) {
            System.err.println(Globals.getBrokerResources().getString(BrokerResources.W_ECHO_PASSWORD));
        }
        while ((pass_phrase == null || pass_phrase.equals("")) && retry <= 5) {
            System.err.print(br.getString(BrokerResources.M_ENTER_KEY_PWD, getKeystoreLocation()));
            System.err.flush();
            if (Broker.getBroker().background) {
                // We're running in the background and can't
                // read the password. We still prompt for it
                // so it's more obvious what's going on
                // (instead of just silently failing)
                // See 4451214
                System.err.print("\n");
                break;
            }
            pass_phrase = pw.getPassword();
            // Limit the number of times we try reading the passwd.
            // If the VM is run in the background the readLine()
            // will always return null and we'd get stuck
            // in the loop
            retry++;
        }
    }
    return (pass_phrase);
}
Also used : BrokerConfig(com.sun.messaging.jmq.jmsserver.config.BrokerConfig) Password(com.sun.messaging.jmq.util.Password)

Aggregations

Password (com.sun.messaging.jmq.util.Password)7 BridgeServiceManager (com.sun.messaging.bridge.api.BridgeServiceManager)1 FailedLoginException (com.sun.messaging.jmq.auth.api.FailedLoginException)1 com.sun.messaging.jmq.jmsserver.cluster.api (com.sun.messaging.jmq.jmsserver.cluster.api)1 BrokerConfig (com.sun.messaging.jmq.jmsserver.config.BrokerConfig)1 PacketRouter (com.sun.messaging.jmq.jmsserver.data.PacketRouter)1 AdminDataHandler (com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler)1 Agent (com.sun.messaging.jmq.jmsserver.management.agent.Agent)1 CoreLifecycleSpi (com.sun.messaging.jmq.jmsserver.plugin.spi.CoreLifecycleSpi)1 MQThread (com.sun.messaging.jmq.util.MQThread)1 Rlimit (com.sun.messaging.jmq.util.Rlimit)1 MQTimer (com.sun.messaging.jmq.util.timer.MQTimer)1 NamingException (javax.naming.NamingException)1 LdapName (javax.naming.ldap.LdapName)1 LoginException (javax.security.auth.login.LoginException)1