protected SecurityContext checkSecurityContext(ConnectionContext context) throws SecurityException { final SecurityContext securityContext = context.getSecurityContext(); if (securityContext == null) { throw new SecurityException("User is not authenticated."); } return securityContext; }
private boolean isBrokerContext(ConnectionContext context) { return context.getSecurityContext() != null && context.getSecurityContext().isBrokerContext(); }
@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); } }
@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()); SecurityContext securityContext = null; try { securityContext = authenticate(info.getUserName(), info.getPassword(), null); context.setSecurityContext(securityContext); securityContexts.add(securityContext); super.addConnection(context, info); } catch (Exception error) { if (securityContext != null) { securityContexts.remove(securityContext); } context.setSecurityContext(null); throw error; } finally { Thread.currentThread().setContextClassLoader(original); } } else { super.addConnection(context, info); } }
/** * 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. */ @Override 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 { SecurityContext s = authenticate(info.getUserName(), info.getPassword(), (X509Certificate[]) info.getTransportContext()); context.setSecurityContext(s); } finally { Thread.currentThread().setContextClassLoader(original); } } super.addConnection(context, info); }
@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; } }
/** * 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) { if (isSSL(context, info)) { this.sslBroker.addConnection(context, info); } else { this.nonSslBroker.addConnection(context, info); } super.addConnection(context, info); } }
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { final ConnectionContext context = producerExchange.getConnectionContext(); String userID = context.getUserName(); if (isUseAuthenticatePrincipal()) { SecurityContext securityContext = context.getSecurityContext(); if (securityContext != null) { Set<?> principals = securityContext.getPrincipals(); if (principals != null) { for (Object candidate : principals) { if (candidate instanceof UserPrincipal) { userID = ((UserPrincipal)candidate).getName(); break; } } } } } messageSend.setUserID(userID); super.send(producerExchange, messageSend); }
if (context.getSecurityContext() == null || !context.getSecurityContext().isBrokerContext()) { adminContext = BrokerSupport.getConnectionContext(this);
protected SecurityContext checkSecurityContext(ConnectionContext context) throws SecurityException { final SecurityContext securityContext = context.getSecurityContext(); if (securityContext == null) { throw new SecurityException("User is not authenticated."); } return securityContext; }
protected SecurityContext checkSecurityContext(ConnectionContext context) throws SecurityException { final SecurityContext securityContext = context.getSecurityContext(); if (securityContext == null) { throw new SecurityException("User is not authenticated."); } return securityContext; }
protected SecurityContext checkSecurityContext(ConnectionContext context) throws SecurityException { final SecurityContext securityContext = context.getSecurityContext(); if (securityContext == null) { throw new SecurityException("User is not authenticated."); } return securityContext; }
protected KapuaSecurityContext getKapuaSecurityContext(ConnectionContext context) throws SecurityException { SecurityContext securityContext = context.getSecurityContext(); if (securityContext == null || !(securityContext instanceof KapuaSecurityContext)) { throw new SecurityException("Invalid SecurityContext."); } return (KapuaSecurityContext) securityContext; }
@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); } }
@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); } }
public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); if (securityContexts.remove(context.getSecurityContext())) { context.setSecurityContext(null); } }
public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); if (securityContexts.remove(context.getSecurityContext())) { context.setSecurityContext(null); } }
@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); } }
public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); if (securityContexts.remove(context.getSecurityContext())) { context.setSecurityContext(null); } Set<ConnectionContext> conns = userConnection.get(info.getUserName()); if (conns != null) { conns.remove(context); } }
protected boolean isSystemBroker(DestinationAction action) { ConnectionContext context = action.getConnectionContext(); SecurityContext securityContext = context.getSecurityContext(); return securityContext != null && securityContext.isBrokerContext(); }