当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionInfo.getUserName方法代码示例

本文整理汇总了Java中org.apache.activemq.command.ConnectionInfo.getUserName方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionInfo.getUserName方法的具体用法?Java ConnectionInfo.getUserName怎么用?Java ConnectionInfo.getUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.activemq.command.ConnectionInfo的用法示例。


在下文中一共展示了ConnectionInfo.getUserName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: useCertificateAuthentication

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
/**
 * Determine if a client certificate authentication should be tried.
 * 
 * @param connector
 *            the connector
 * @param info
 *            the connection info
 * @return true if the certificate authentication should be used.
 * @throws IOException
 *             in case of an error
 * @throws URISyntaxException
 *             in case of an error
 */
private boolean useCertificateAuthentication(Connector connector, ConnectionInfo info)
        throws IOException,
        URISyntaxException {
    boolean isSSL = isSslConnection(connector);

    boolean haveUsernamePassword = info.getUserName() != null && info.getPassword() != null;

    // if its as ssl request and we force a client certificate we will do the certificate
    // authentication
    if (isSSL && this.settingsDao.isForceSSLClientAuthentication()) {
        return true;
    }

    // if we have a password, use it
    if (haveUsernamePassword) {
        return false;
    }

    // finally depend on the SSL flag
    return isSSL;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:35,代码来源:CommunoteJaasAuthenticationBroker.java

示例2: addConnection

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
@Override
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {



    //String redisUri = configStore.getVar(PluginVariables.REDIS_CONNECTION_STRING);

    //logger.debug("Establishing Redis connection using uri={} ", redisUri);
    //Jedis jedis = new Jedis(redisUri);

    String username = info.getUserName();
    String password = info.getPassword();

    boolean isAuthenticated = false;

    try {
        isAuthenticated = webAuthClient.authenticate(username, password);
    } catch (Exception e) {
        throw new SecurityException("Error during calling web authentication server");
    }

    /*logger.debug("Querying Redis using [key={}, username={}] ", REDIS_KEY, username);
    String response = jedis.hget(REDIS_KEY, username);
    */

    if(isAuthenticated) {
        logger.debug("Found username [{}]. Allowing connection", username);
        super.addConnection(context, info);
    } else {
        throw new SecurityException("Invalid credentials");
    }
}
 
开发者ID:zapotek6,项目名称:activemq-webauth-plugin,代码行数:33,代码来源:WebAuthBroker.java

示例3: addConnection

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
@Override
public void addConnection(ConnectionContext context, ConnectionInfo info)
        throws Exception {
    if (context.getSecurityContext() == null) {
        // Set the TCCL since it seems JAAS needs it to find the login
        // module classes.
        ClassLoader original = Thread.currentThread()
                .getContextClassLoader();
        Thread.currentThread().setContextClassLoader(
                JaasAuthenticationBroker.class.getClassLoader());

        try {
            CommunoteMQCallbackHandler callback = new CommunoteMQCallbackHandler(
                    info.getUserName(), info.getPassword(), context
                            .getConnection().getRemoteAddress(),
                    ((TransportConnector) context.getConnector()).getUri()
                            .toString());
            LoginContext lc = new LoginContext(jaasConfiguration, callback);
            lc.login();
            Subject subject = lc.getSubject();
            SecurityContext s = new JaasSecurityContext(info.getUserName(),
                    subject);
            context.setSecurityContext(s);
            securityContexts.add(s);
        } catch (Exception e) {
            LOGGER.debug(e.getMessage(), e);
            throw new SecurityException(e.getMessage(), e);
        } finally {
            Thread.currentThread().setContextClassLoader(original);
        }
    }
    super.addConnection(context, info);
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:34,代码来源:CommunoteUsernamePasswordJaasAuthenticationBroker.java

示例4: handleEmbeddedConnection

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
/**
 * It is in an internal connection so register a user
 * 
 * @param context
 *            the context
 * @param info
 *            the connection info
 */
private void handleEmbeddedConnection(ConnectionContext context, ConnectionInfo info) {
    UserPrincipal principal = new UserPrincipal(
            CommunoteJaasLoginModule.LOCAL_COMMUNOTE_USER);
    GroupPrincipal groupPrincipal = new GroupPrincipal("users");

    Subject subject = new Subject();
    subject.getPrincipals().add(principal);
    subject.getPrincipals().add(groupPrincipal);

    SecurityContext s = new JaasSecurityContext(info.getUserName(),
            subject);
    context.setSecurityContext(s);
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:22,代码来源:CommunoteJaasAuthenticationBroker.java

示例5: addConnection

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
/**
 * Overridden to allow for authentication based on client certificates.
 * Connections being added will be authenticated based on their certificate
 * chain and the JAAS module specified through the JAAS framework. NOTE: The
 * security context's username will be set to the first UserPrincipal
 * created by the login module.
 * 
 * @param context The context for the incoming Connection.
 * @param info The ConnectionInfo Command representing the incoming
 *                connection.
 */
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {

    if (context.getSecurityContext() == null) {
        if (!(info.getTransportContext() instanceof X509Certificate[])) {
            throw new SecurityException("Unable to authenticate transport without SSL certificate.");
        }

        // Set the TCCL since it seems JAAS needs it to find the login
        // module classes.
        ClassLoader original = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(JaasAuthenticationBroker.class.getClassLoader());
        try {
            // Do the login.
            try {
                CallbackHandler callback = new JaasCertificateCallbackHandler((X509Certificate[])info.getTransportContext());
                LoginContext lc = new LoginContext(jaasConfiguration, callback);
                lc.login();
                Subject subject = lc.getSubject();

                String dnName = "";

                for (Principal principal : subject.getPrincipals()) {
                    if (principal instanceof UserPrincipal) {
                        dnName = ((UserPrincipal)principal).getName();
                        break;
                    }
                }
                SecurityContext s = new JaasCertificateSecurityContext(dnName, subject, (X509Certificate[])info.getTransportContext());
                context.setSecurityContext(s);
            } catch (Exception e) {
                throw new SecurityException("User name [" + info.getUserName() + "] or password is invalid. " + e.getMessage(), e);
            }
        } finally {
            Thread.currentThread().setContextClassLoader(original);
        }
    }
    super.addConnection(context, info);
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:50,代码来源:JaasCertificateAuthenticationBroker.java

示例6: addConnection

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
@Override
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {

    if (context.getSecurityContext() == null) {
        // Set the TCCL since it seems JAAS needs it to find the login
        // module classes.
        ClassLoader original = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(JaasAuthenticationBroker.class.getClassLoader());
        try {
            // Do the login.
            try {
                JassCredentialCallbackHandler callback = new JassCredentialCallbackHandler(info
                    .getUserName(), info.getPassword());
                LoginContext lc = new LoginContext(jassConfiguration, callback);
                lc.login();
                Subject subject = lc.getSubject();

                SecurityContext s = new JaasSecurityContext(info.getUserName(), subject);
                context.setSecurityContext(s);
                securityContexts.add(s);
            } catch (Exception e) {
                throw (SecurityException)new SecurityException("User name [" + info.getUserName() + "] or password is invalid.")
                    .initCause(e);
            }
        } finally {
            Thread.currentThread().setContextClassLoader(original);
        }
    }
    super.addConnection(context, info);
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:31,代码来源:JaasAuthenticationBroker.java

示例7: getUsername

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
@Override
public String getUsername() {
   ConnectionInfo info = getConnectionInfo();
   if (info == null) {
      return null;
   }
   return info.getUserName();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:9,代码来源:OpenWireConnection.java

示例8: addConnection

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
/**
 * Add new connection.
 *
 * @param context
 * @param info
 * @throws Exception
 * @see org.apache.activemq.broker.BrokerFilter#addConnection(org.apache.activemq.broker.ConnectionContext, org.apache.activemq.command.ConnectionInfo)
 */
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
    String clientId = info.getClientId();
    String usr = info.getUserName();
    String pass = info.getPassword();

    logger.info("Add new connection { Remote Address: " + context.getConnection().getRemoteAddress()
            + ", User: " + usr + ", ClientID: " + clientId + "  } ");

    if (usr != null && pass != null) {
        if (SYSTEM_USER.equals(usr) || (SUPER_USER.equals(usr) && superpass.equals(pass))) {
            userMap.put(clientId, "*");
        } else {
            String[] parts = usr.split(":");
            if (parts.length > 1) {
                String ns = parts[0];/*"/public/packer/providers"*/
                String cloudName = parts[1]; /*"ec2.us-east-1a"*/
                CmsCISimple cloud = cmsClient.getCloudCi(ns, cloudName);
                if (cloud != null) {
                    String authkey = cloud.getCiAttributes().get("auth");
                    if (authkey.equals(pass)) {
                        String queueName = (ns.replaceAll("/", ".") + "." + cloudName + QUEUE_SUFFIX).substring(1);
                        userMap.put(clientId, queueName);
                    } else {
                        logger.error("Got bad password for cloud " + cloudName + ", NsPath: " + ns);
                        throw new CmsAuthException("Bad password for user: " + usr);
                    }

                } else {
                    logger.error("Got null cloud object for user: " + usr);
                    throw new CmsAuthException("Bad user/pass combination");
                }
            } else {
                throw new CmsAuthException("Bad user/pass combination");
            }
        }
    } else {
        logger.error("Got null user/pass");
        throw new CmsAuthException("Got null user/pass");
    }
    super.addConnection(context, info);
}
 
开发者ID:oneops,项目名称:oneops,代码行数:50,代码来源:OneopsAuthBroker.java

示例9: addConnection

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
@Override
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {

    SecurityContext s = context.getSecurityContext();
    if (s == null) {
        // Check the username and password.
        if (anonymousAccessAllowed && info.getUserName() == null && info.getPassword() == null) {
            info.setUserName(anonymousUser);
            s = new SecurityContext(info.getUserName()) {
                @Override
                public Set<Principal> getPrincipals() {
                    Set<Principal> groups = new HashSet<Principal>();
                    groups.add(new GroupPrincipal(anonymousGroup));
                    return groups;
                }
            };
        } else {
            String pw = userPasswords.get(info.getUserName());
            if (pw == null || !pw.equals(info.getPassword())) {
                throw new SecurityException(
                        "User name [" + info.getUserName() + "] or password is invalid.");
            }

            final Set<Principal> groups = userGroups.get(info.getUserName());
            s = new SecurityContext(info.getUserName()) {
                @Override
                public Set<Principal> getPrincipals() {
                    return groups;
                }
            };
        }

        context.setSecurityContext(s);
        securityContexts.add(s);
    }

    try {
        super.addConnection(context, info);
    } catch (Exception e) {
        securityContexts.remove(s);
        context.setSecurityContext(null);
        throw e;
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:45,代码来源:SimpleAuthenticationBroker.java

示例10: addConnection

import org.apache.activemq.command.ConnectionInfo; //导入方法依赖的package包/类
public void addConnection(OpenWireConnection connection, ConnectionInfo info) throws Exception {
   String username = info.getUserName();
   String password = info.getPassword();

   try {
      validateUser(username, password, connection);
   } catch (ActiveMQSecurityException e) {
      // We need to send an exception used by the openwire
      SecurityException ex = new SecurityException("User name [" + username + "] or password is invalid.");
      ex.initCause(e);
      throw ex;
   }

   String clientId = info.getClientId();
   if (clientId == null) {
      throw new InvalidClientIDException("No clientID specified for connection request");
   }

   synchronized (clientIdSet) {
      AMQConnectionContext context;
      context = clientIdSet.get(clientId);
      if (context != null) {
         if (info.isFailoverReconnect()) {
            OpenWireConnection oldConnection = context.getConnection();
            oldConnection.disconnect(true);
            connections.remove(oldConnection);
            connection.reconnect(context, info);
         } else {
            throw new InvalidClientIDException("Broker: " + getBrokerName() + " - Client: " + clientId + " already connected from " + context.getConnection().getRemoteAddress());
         }
      } else {
         //new connection
         context = connection.initContext(info);
         clientIdSet.put(clientId, context);
      }

      connections.add(connection);

      ActiveMQTopic topic = AdvisorySupport.getConnectionAdvisoryTopic();
      // do not distribute passwords in advisory messages. usernames okay
      ConnectionInfo copy = info.copy();
      copy.setPassword("");
      fireAdvisory(context, topic, copy);

      // init the conn
      context.getConnection().addSessions(context.getConnectionState().getSessionIds());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:49,代码来源:OpenWireProtocolManager.java


注:本文中的org.apache.activemq.command.ConnectionInfo.getUserName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。