Skip to content

Commit

Permalink
:feat: update artemis ACL and Principal fix
Browse files Browse the repository at this point in the history
Signed-off-by: riccardomodanese <riccardo.modanese@eurotech.com>
  • Loading branch information
riccardomodanese committed Nov 18, 2024
1 parent fa1a00e commit faba0e8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ private Subject authenticateInternalConn(ConnectionInfo connectionInfo, String c
username, connectionInfo.getClientId(), connectionInfo.getClientIp(), remotingConnection.getID(),
remotingConnection.getTransportConnection().getRemoteAddress(), remotingConnection.getTransportConnection().isOpen());
//TODO double check why the client id is null once coming from AMQP connection (the Kapua connection factory with custom client id generation is called)
KapuaPrincipal kapuaPrincipal = buildInternalKapuaPrincipal(getAdminAccountInfo().getId(), username, connectionInfo.getClientId());
//auto generate client id if null. It shouldn't be null but in some case the one from JMS connection is.
String clientId = connectionInfo.getClientId();
//set a random client id value if not set by the client
//from JMS 2 specs "Although setting client ID remains mandatory when creating an unshared durable subscription, it is optional when creating a shared durable subscription."
if (Strings.isNullOrEmpty(clientId)) {
clientId = clientIdPrefix + INDEX.getAndIncrement();
logger.info("Updated empty client id to: {}", clientId);
}
KapuaPrincipal kapuaPrincipal = buildInternalKapuaPrincipal(getAdminAccountInfo().getId(), username, clientId);
//auto generate client id if null. It shouldn't be null but in some case the one from JMS connection is.
//update client id with account|clientId (see pattern)
String fullClientId = Utils.getFullClientId(getAdminAccountInfo().getId(), clientId);
remotingConnection.setClientID(fullClientId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public class Acl {
private final HierarchicalRepository<KapuaPrincipal> admin;

public Acl(LoginMetric loginMetric, KapuaPrincipal principal, List<AuthAcl> authAcls) throws KapuaIllegalArgumentException {
wildcardConfiguration = new WildcardConfiguration().setSingleWord(SINGLE_WORD)
.setAnyWords(ANY_WORDS)
.setDelimiter(SEPARATOR);
wildcardConfiguration = new WildcardConfiguration().
setSingleWord(SINGLE_WORD).
setAnyWords(ANY_WORDS).
setDelimiter(SEPARATOR);
if (principal == null) {
throw new KapuaIllegalArgumentException("principal", null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</bean>

<bean id="connectionFactory" class="org.eclipse.kapua.service.client.amqp.ServiceConnectionFactoryImpl">
<constructor-arg name="schema" type="java.lang.String" value="amqp"/>
<constructor-arg name="host" type="java.lang.String" value="${BROKER_HOST}"/>
<constructor-arg name="port" type="int" value="${BROKER_PORT}"/>
<constructor-arg name="username" type="java.lang.String" value="${BROKER_INTERNAL_USERNAME}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</bean>

<bean id="connectionFactory" class="org.eclipse.kapua.service.client.amqp.ServiceConnectionFactoryImpl">
<constructor-arg name="schema" type="java.lang.String" value="amqp"/>
<constructor-arg name="host" type="java.lang.String" value="${BROKER_HOST}"/>
<constructor-arg name="port" type="int" value="${BROKER_PORT}"/>
<constructor-arg name="username" type="java.lang.String" value="${BROKER_INTERNAL_USERNAME}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</bean>

<bean id="connectionFactory" class="org.eclipse.kapua.service.client.amqp.ServiceConnectionFactoryImpl">
<constructor-arg name="schema" type="java.lang.String" value="amqp"/>
<constructor-arg name="host" type="java.lang.String" value="${SERVICE_BROKER_HOST}"/>
<constructor-arg name="port" type="int" value="${SERVICE_BROKER_PORT}"/>
<constructor-arg name="username" type="java.lang.String" value="${SERVICE_BROKER_USERNAME}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class AclCreator {
protected final static String HASH = "#";

protected String addressClassifier;
protected String addressClassifierEscaped;
protected String addressClassifierHash;

protected String aclCtrlAccReply;
Expand All @@ -48,15 +47,14 @@ public class AclCreator {
@Inject
public AclCreator() {
addressClassifier = SystemSetting.getInstance().getMessageClassifier();
addressClassifierEscaped = "\\" + SystemSetting.getInstance().getMessageClassifier();
addressClassifierHash = addressClassifierEscaped + "/" + HASH;
aclCtrlAccReply = addressClassifierEscaped + "/{0}/+/+/REPLY/#";
aclCtrlAccCliMqttLifeCycle = addressClassifierEscaped + "/{0}/{1}/MQTT/#";
aclCtrlAcc = addressClassifierEscaped + "/{0}/#";
aclCtrlAccCli = addressClassifierEscaped + "/{0}/{1}/#";
addressClassifierHash = addressClassifier + "/" + HASH;
aclCtrlAccReply = addressClassifier + "/{0}/+/+/REPLY/#";
aclCtrlAccCliMqttLifeCycle = addressClassifier + "/{0}/{1}/MQTT/#";
aclCtrlAcc = addressClassifier + "/{0}/#";
aclCtrlAccCli = addressClassifier + "/{0}/{1}/#";
aclDataAcc = "{0}/#";
aclDataAccCli = "{0}/{1}/#";
aclCtrlAccNotify = addressClassifierEscaped + "/{0}/+/+/NOTIFY/{1}/#";
aclCtrlAccNotify = addressClassifier + "/{0}/+/+/NOTIFY/{1}/#";
}

public List<AuthAcl> buildAcls(boolean[] permission, String accountName, String clientId, StringBuilder aclDestinationsLog) {
Expand Down

0 comments on commit faba0e8

Please sign in to comment.