ARTEMIS-522 fix AMQP ANON advert

This commit is contained in:
jbertram 2016-05-17 08:46:36 -05:00 committed by Clebert Suconic
parent bbe365eb69
commit b9b4107020
2 changed files with 27 additions and 7 deletions

View File

@ -56,7 +56,25 @@ public class ActiveMQProtonConnectionCallback implements AMQPConnectionCallback
@Override @Override
public ServerSASL[] getSASLMechnisms() { public ServerSASL[] getSASLMechnisms() {
return new ServerSASL[]{new AnonymousServerSASL(), new ActiveMQPlainSASL(manager.getServer().getSecurityStore(), manager.getServer().getSecurityManager())}; boolean supportsAnonymous = false;
try {
manager.getServer().getSecurityStore().authenticate(null, null, null);
supportsAnonymous = true;
}
catch (Exception e) {
// authentication failed so no anonymous support
}
ServerSASL[] result;
if (supportsAnonymous) {
result = new ServerSASL[]{new AnonymousServerSASL(), new ActiveMQPlainSASL(manager.getServer().getSecurityStore())};
}
else {
result = new ServerSASL[]{new ActiveMQPlainSASL(manager.getServer().getSecurityStore())};
}
return result;
} }
@Override @Override

View File

@ -17,24 +17,26 @@
package org.apache.activemq.artemis.core.protocol.proton.sasl; package org.apache.activemq.artemis.core.protocol.proton.sasl;
import org.apache.activemq.artemis.core.security.SecurityStore; import org.apache.activemq.artemis.core.security.SecurityStore;
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
import org.proton.plug.sasl.ServerSASLPlain; import org.proton.plug.sasl.ServerSASLPlain;
public class ActiveMQPlainSASL extends ServerSASLPlain { public class ActiveMQPlainSASL extends ServerSASLPlain {
private final ActiveMQSecurityManager securityManager;
private final SecurityStore securityStore; private final SecurityStore securityStore;
public ActiveMQPlainSASL(SecurityStore securityStore, ActiveMQSecurityManager securityManager) { public ActiveMQPlainSASL(SecurityStore securityStore) {
this.securityManager = securityManager;
this.securityStore = securityStore; this.securityStore = securityStore;
} }
@Override @Override
protected boolean authenticate(String user, String password) { protected boolean authenticate(String user, String password) {
if (securityStore.isSecurityEnabled()) { if (securityStore.isSecurityEnabled()) {
return securityManager.validateUser(user, password); try {
securityStore.authenticate(user, password, null);
return true;
}
catch (Exception e) {
return false;
}
} }
else { else {
return true; return true;