public void receiveSaslMechanisms(final SaslMechanisms saslMechanisms) { if (Arrays.asList(saslMechanisms.getSaslServerMechanisms()).contains(Symbol.valueOf("PLAIN"))) { SaslInit init = new SaslInit(); init.setMechanism(Symbol.valueOf("PLAIN")); init.setHostname(_remoteHostname); byte[] usernameBytes = _user.getName().getBytes(Charset.forName("UTF-8")); byte[] passwordBytes = _password.getBytes(Charset.forName("UTF-8")); byte[] initResponse = new byte[usernameBytes.length + passwordBytes.length + 2]; System.arraycopy(usernameBytes, 0, initResponse, 1, usernameBytes.length); System.arraycopy( passwordBytes, 0, initResponse, usernameBytes.length + 2, passwordBytes.length); init.setInitialResponse(new Binary(initResponse)); _saslFrameOutput.send(new SASLFrame(init), null); } }
public void receiveSaslInit(final SaslInit saslInit) { Symbol mechanism = saslInit.getMechanism(); final Binary initialResponse = saslInit.getInitialResponse(); byte[] response = initialResponse == null ? new byte[0] : initialResponse.getArray(); try { _saslServer = _saslServerProvider.getSaslServer(mechanism.toString(), "localhost"); // Process response from the client byte[] challenge = _saslServer.evaluateResponse(response != null ? response : new byte[0]); if (_saslServer.isComplete()) { SaslOutcome outcome = new SaslOutcome(); outcome.setCode(SaslCode.OK); _saslFrameOutput.send(new SASLFrame(outcome), null); synchronized (getLock()) { _saslComplete = true; _authenticated = true; getLock().notifyAll(); } if (_onSaslCompleteTask != null) { _onSaslCompleteTask.run(); } } else { SaslChallenge challengeBody = new SaslChallenge(); challengeBody.setChallenge(new Binary(challenge)); _saslFrameOutput.send(new SASLFrame(challengeBody), null); } } catch (SaslException e) { SaslOutcome outcome = new SaslOutcome(); outcome.setCode(SaslCode.AUTH); _saslFrameOutput.send(new SASLFrame(outcome), null); synchronized (getLock()) { _saslComplete = true; _authenticated = false; getLock().notifyAll(); } if (_onSaslCompleteTask != null) { _onSaslCompleteTask.run(); } } }
public void initiateSASL() { SaslMechanisms mechanisms = new SaslMechanisms(); final Enumeration<SaslServerFactory> saslServerFactories = Sasl.getSaslServerFactories(); SaslServerFactory f; ArrayList<Symbol> mechanismsList = new ArrayList<Symbol>(); while (saslServerFactories.hasMoreElements()) { f = saslServerFactories.nextElement(); final String[] mechanismNames = f.getMechanismNames(null); for (String name : mechanismNames) { mechanismsList.add(Symbol.valueOf(name)); } } mechanisms.setSaslServerMechanisms(mechanismsList.toArray(new Symbol[mechanismsList.size()])); _saslFrameOutput.send(new SASLFrame(mechanisms), null); }
public class OpenConstructor extends DescribedTypeConstructor<Open> { private static final Object[] DESCRIPTORS = { Symbol.valueOf("amqp:open:list"), UnsignedLong.valueOf(0x0000000000000010L), }; private static final OpenConstructor INSTANCE = new OpenConstructor(); public static void register(DescribedTypeConstructorRegistry registry) { for (Object descriptor : DESCRIPTORS) { registry.register(descriptor, INSTANCE); } } public Open construct(Object underlying) { if (underlying instanceof List) { List list = (List) underlying; Open obj = new Open(); int position = 0; final int size = list.size(); if (position < size) { Object val = list.get(position); position++; if (val != null) { try { obj.setContainerId((String) val); } catch (ClassCastException e) { // TODO Error } } } else { return obj; } if (position < size) { Object val = list.get(position); position++; if (val != null) { try { obj.setHostname((String) val); } catch (ClassCastException e) { // TODO Error } } } else { return obj; } if (position < size) { Object val = list.get(position); position++; if (val != null) { try { obj.setMaxFrameSize((UnsignedInteger) val); } catch (ClassCastException e) { // TODO Error } } } else { return obj; } if (position < size) { Object val = list.get(position); position++; if (val != null) { try { obj.setChannelMax((UnsignedShort) val); } catch (ClassCastException e) { // TODO Error } } } else { return obj; } if (position < size) { Object val = list.get(position); position++; if (val != null) { try { obj.setIdleTimeOut((UnsignedInteger) val); } catch (ClassCastException e) { // TODO Error } } } else { return obj; } if (position < size) { Object val = list.get(position); position++; if (val != null) { if (val instanceof Symbol[]) { obj.setOutgoingLocales((Symbol[]) val); } else { try { obj.setOutgoingLocales(new Symbol[] {(Symbol) val}); } catch (ClassCastException e) { // TODO Error } } } } else { return obj; } if (position < size) { Object val = list.get(position); position++; if (val != null) { if (val instanceof Symbol[]) { obj.setIncomingLocales((Symbol[]) val); } else { try { obj.setIncomingLocales(new Symbol[] {(Symbol) val}); } catch (ClassCastException e) { // TODO Error } } } } else { return obj; } if (position < size) { Object val = list.get(position); position++; if (val != null) { if (val instanceof Symbol[]) { obj.setOfferedCapabilities((Symbol[]) val); } else { try { obj.setOfferedCapabilities(new Symbol[] {(Symbol) val}); } catch (ClassCastException e) { // TODO Error } } } } else { return obj; } if (position < size) { Object val = list.get(position); position++; if (val != null) { if (val instanceof Symbol[]) { obj.setDesiredCapabilities((Symbol[]) val); } else { try { obj.setDesiredCapabilities(new Symbol[] {(Symbol) val}); } catch (ClassCastException e) { // TODO Error } } } } else { return obj; } if (position < size) { Object val = list.get(position); position++; if (val != null) { try { obj.setProperties((Map) val); } catch (ClassCastException e) { // TODO Error } } } else { return obj; } return obj; } else { // TODO - error return null; } } }