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


Java ConnectionContext.getSecurityContext方法代码示例

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


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

示例1: addConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
 * Overridden to allow for authentication using different Jaas
 * configurations depending on if the connection is SSL or not.
 *
 * @param context The context for the incoming Connection.
 * @param info The ConnectionInfo Command representing the incoming
 *                connection.
 */
@Override
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
    if (context.getSecurityContext() == null) {
        boolean isSSL;
        Connector connector = context.getConnector();
        if (connector instanceof TransportConnector) {
            TransportConnector transportConnector = (TransportConnector) connector;
            isSSL = transportConnector.getServer().isSslServer();
        } else {
            isSSL = false;
        }

        if (isSSL) {
            this.sslBroker.addConnection(context, info);
        } else {
            this.nonSslBroker.addConnection(context, info);
        }
        super.addConnection(context, info);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:29,代码来源:JaasDualAuthenticationBroker.java

示例2: 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

示例3: 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

示例4: addConnection

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
 * Overridden to allow for authentication using different Jaas configurations depending on if
 * the connection is SSL or not.
 * 
 * @param context
 *            The context for the incoming Connection.
 * @param info
 *            The ConnectionInfo Command representing the incoming connection.
 * @throws Exception
 *             in case of an error
 */
@Override
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
    try {
        if (context.getSecurityContext() == null) {

            Connector connector = context.getConnector();

            if (isEmbeddedConnection(context, info)) {

                handleEmbeddedConnection(context, info);
                super.addConnection(context, info);
            } else if (useCertificateAuthentication(connector, info)) {

                this.handleCertificateConnection(context, info);
                super.addConnection(context, info);
            } else if (assertForceSsl(context, info)) {
                this.usernamePasswordBroker.addConnection(context, info);
            } else {
                throw new SecurityException(
                        "Cannot add connection since no authentication could be appled. Check the configurations");
            }
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new SecurityException("Error in authentication " + e.getMessage(), e);
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:39,代码来源:CommunoteJaasAuthenticationBroker.java

示例5: checkSecurityContext

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
protected SecurityContext checkSecurityContext(ConnectionContext context) throws SecurityException {
    final SecurityContext securityContext = context.getSecurityContext();
    if (securityContext == null) {
        throw new SecurityException("User is not authenticated.");
    }
    return securityContext;
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:8,代码来源:AuthorizationBroker.java

示例6: 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

示例7: 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

示例8: addConnection

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


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