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


Java ConnectionContext.setSecurityContext方法代码示例

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


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

示例1: fireFailedForwardAdvisory

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
private void fireFailedForwardAdvisory(MessageDispatch messageDispatch, Throwable error) {
    if (configuration.isAdvisoryForFailedForward()) {
        AdvisoryBroker advisoryBroker = null;
        try {
            advisoryBroker = (AdvisoryBroker) brokerService.getBroker().getAdaptor(AdvisoryBroker.class);

            if (advisoryBroker != null) {
                ConnectionContext context = new ConnectionContext();
                context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
                context.setBroker(brokerService.getBroker());

                ActiveMQMessage advisoryMessage = new ActiveMQMessage();
                advisoryMessage.setStringProperty("cause", error.getLocalizedMessage());
                advisoryBroker.fireAdvisory(context, AdvisorySupport.getNetworkBridgeForwardFailureAdvisoryTopic(), messageDispatch.getMessage(), null,
                    advisoryMessage);

            }
        } catch (Exception e) {
            LOG.warn("failed to fire forward failure advisory, cause: {}", e);
            LOG.debug("detail", e);
        }
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:24,代码来源:DemandForwardingBridgeSupport.java

示例2: networkBridgeStarted

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void networkBridgeStarted(BrokerInfo brokerInfo, boolean createdByDuplex, String remoteIp) {
    try {
     if (brokerInfo != null) {
         ActiveMQMessage advisoryMessage = new ActiveMQMessage();
         advisoryMessage.setBooleanProperty("started", true);
         advisoryMessage.setBooleanProperty("createdByDuplex", createdByDuplex);
         advisoryMessage.setStringProperty("remoteIp", remoteIp);
         networkBridges.putIfAbsent(brokerInfo, advisoryMessage);

         ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic();

         ConnectionContext context = new ConnectionContext();
         context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
         context.setBroker(getBrokerService().getBroker());
         fireAdvisory(context, topic, brokerInfo, null, advisoryMessage);
     }
    } catch (Exception e) {
        handleFireFailure("network bridge started", e);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:22,代码来源:AdvisoryBroker.java

示例3: networkBridgeStopped

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void networkBridgeStopped(BrokerInfo brokerInfo) {
    try {
     if (brokerInfo != null) {
         ActiveMQMessage advisoryMessage = new ActiveMQMessage();
         advisoryMessage.setBooleanProperty("started", false);
         networkBridges.remove(brokerInfo);

         ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic();

         ConnectionContext context = new ConnectionContext();
         context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
         context.setBroker(getBrokerService().getBroker());
         fireAdvisory(context, topic, brokerInfo, null, advisoryMessage);
     }
    } catch (Exception e) {
        handleFireFailure("network bridge stopped", e);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:20,代码来源:AdvisoryBroker.java

示例4: addConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
    SecurityContext securityContext = context.getSecurityContext();
    if (securityContext == null) {
        securityContext = authenticate(info.getUserName(), info.getPassword(), null);
        context.setSecurityContext(securityContext);
        securityContexts.add(securityContext);
    }

    try {
        super.addConnection(context, info);
    } catch (Exception e) {
        securityContexts.remove(securityContext);
        context.setSecurityContext(null);
        throw e;
    }
}
 
开发者ID:ctytgat,项目名称:amq-jdbc-security,代码行数:18,代码来源:JdbcAuthenticationBroker.java

示例5: removeConnection

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

    super.removeConnection(context, info, error);
    if (this.securityContexts.remove(context.getSecurityContext())) {
        context.setSecurityContext((SecurityContext) null);
    }

}
 
开发者ID:hishamaborob,项目名称:ActiveMQ-JWT-Authentication-Plugin,代码行数:10,代码来源:JWTAuthenticationBroker.java

示例6: addConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的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

示例7: removeConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void removeConnection(ConnectionContext context,
        ConnectionInfo info, Throwable error) throws Exception {
    super.removeConnection(context, info, error);
    if (securityContexts.remove(context.getSecurityContext())) {
        context.setSecurityContext(null);
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:9,代码来源:CommunoteUsernamePasswordJaasAuthenticationBroker.java

示例8: handleCertificateConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
 * We expect a client certificate so check it if it is a communote user one
 * 
 * TODO do the extraction of the ou and cn and dn in a common place in the core
 * 
 * @param context
 *            the context
 * @param info
 *            the info
 * @throws Exception
 *             in case of an error
 */
private void handleCertificateConnection(ConnectionContext context, ConnectionInfo info)
        throws Exception {

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

    X509Certificate[] certificates = (X509Certificate[]) info.getTransportContext();

    CommunoteUserCertificate cert = CommunoteUserCertificate.pickValid(certificates);
    if (cert == null) {
        throw new SecurityException(
                "Unable to authenticate transport. No valid SSL certificate found.");
    }

    String dnName = cert.getSubjectName();

    UserPrincipal principal = new UserPrincipal(dnName);
    GroupPrincipal groupPrincipal = new GroupPrincipal(CommunoteJaasLoginModule.ROLE_USERS);

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

    SecurityContext s = new JaasCertificateSecurityContext(dnName, subject,
            (X509Certificate[]) info.getTransportContext());
    context.setSecurityContext(s);

}
 
开发者ID:Communote,项目名称:communote-server,代码行数:43,代码来源:CommunoteJaasAuthenticationBroker.java

示例9: handleEmbeddedConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的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

示例10: removeConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
    super.removeConnection(context, info, error);
    if (securityContexts.remove(context.getSecurityContext())) {
        context.setSecurityContext(null);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:8,代码来源:AbstractAuthenticationBroker.java

示例11: addConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的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

示例12: addConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的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

示例13: nowMasterBroker

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void nowMasterBroker() {
    super.nowMasterBroker();
    try {
        ActiveMQTopic topic = AdvisorySupport.getMasterBrokerAdvisoryTopic();
        ActiveMQMessage advisoryMessage = new ActiveMQMessage();
        ConnectionContext context = new ConnectionContext();
        context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
        context.setBroker(getBrokerService().getBroker());
        fireAdvisory(context, topic,null,null,advisoryMessage);
    } catch (Exception e) {
        handleFireFailure("now master broker", e);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:15,代码来源:AdvisoryBroker.java

示例14: createConnectionContext

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
protected ConnectionContext createConnectionContext() {
    ConnectionContext answer = new ConnectionContext(new NonCachedMessageEvaluationContext());
    answer.setBroker(this.broker);
    answer.getMessageEvaluationContext().setDestination(getActiveMQDestination());
    answer.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
    return answer;
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:8,代码来源:BaseDestination.java

示例15: createAdminConnectionContext

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
 * Factory method to create the new administration connection context
 * object. Note this method is here rather than inside a default broker
 * implementation to ensure that the broker reference inside it is the outer
 * most interceptor
 */
protected static ConnectionContext createAdminConnectionContext(Broker broker) {
    ConnectionContext context = new ConnectionContext();
    context.setBroker(broker);
    context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
    return context;
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:13,代码来源:BrokerSupport.java


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