Skip to content

Commit 1537978

Browse files
author
zengfr
committed
easymqtt4j 1.1
1 parent d6154eb commit 1537978

File tree

43 files changed

+631
-208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+631
-208
lines changed

easymqtt4j-activemq-plugins/pom.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
66
<artifactId>easymqtt4j</artifactId>
7-
<groupId>com.zengfr.easymqtt4j</groupId>
7+
<groupId>com.github.zengfr.easymqtt4j</groupId>
88
<version>1.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
@@ -14,14 +14,32 @@
1414
<groupId>org.apache.activemq</groupId>
1515
<artifactId>activemq-broker</artifactId>
1616
</dependency>
17+
<dependency>
18+
<groupId>org.apache.activemq</groupId>
19+
<artifactId>activemq-jaas</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>com.github.zengfr.easymqtt4j</groupId>
23+
<artifactId>easymqtt4j-jaas-plugins</artifactId>
24+
</dependency>
1725
</dependencies>
1826
<dependencyManagement>
1927
<dependencies>
28+
<dependency>
29+
<groupId>com.github.zengfr.easymqtt4j</groupId>
30+
<artifactId>easymqtt4j-jaas-plugins</artifactId>
31+
<version>${project.version}</version>
32+
</dependency>
2033
<dependency>
2134
<groupId>org.apache.activemq</groupId>
2235
<artifactId>activemq-broker</artifactId>
2336
<version>5.15.13</version>
2437
</dependency>
38+
<dependency>
39+
<groupId>org.apache.activemq</groupId>
40+
<artifactId>activemq-jaas</artifactId>
41+
<version>5.15.13</version>
42+
</dependency>
2543
</dependencies>
2644
</dependencyManagement>
2745

easymqtt4j-activemq-plugins/src/main/java/com/zengfr/easymqtt4j/plugins/ActiveMQBrokerFilter.java renamed to easymqtt4j-activemq-plugins/src/main/java/com/github/zengfr/easymqtt4j/plugins/activemq/ActiveMQBrokerFilter.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
package com.zengfr.easymqtt4j.plugins;
1+
package com.github.zengfr.easymqtt4j.plugins.activemq;
22
import org.apache.activemq.broker.Broker;
33
import org.apache.activemq.broker.BrokerFilter;
4-
import org.apache.activemq.broker.ProducerBrokerExchange;
5-
import org.apache.activemq.command.Message;
6-
import org.apache.activemq.plugin.StatisticsBrokerPlugin;
74

85
/**
96
* Created by zengfr on 2020/6/1.

easymqtt4j-activemq-plugins/src/main/java/com/zengfr/easymqtt4j/plugins/ActiveMQBrokerPlugin.java renamed to easymqtt4j-activemq-plugins/src/main/java/com/github/zengfr/easymqtt4j/plugins/activemq/ActiveMQBrokerPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
package com.zengfr.easymqtt4j.plugins;
1+
package com.github.zengfr.easymqtt4j.plugins.activemq;
22
import org.apache.activemq.broker.Broker;
33
import org.apache.activemq.broker.BrokerPlugin;
4-
import org.apache.activemq.plugin.StatisticsBrokerPlugin;
54

65
/**
76
* Created by zengfr on 2020/6/1.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.github.zengfr.easymqtt4j.plugins.activemq;
2+
3+
4+
import com.github.zengfr.easymqtt4j.plugins.jaas.JaasAbstractJdbcLoginModule;
5+
import org.apache.activemq.jaas.GroupPrincipal;
6+
import org.apache.activemq.jaas.UserPrincipal;
7+
8+
import javax.security.auth.Subject;
9+
import java.security.Principal;
10+
import java.util.Set;
11+
12+
/**
13+
* Created by zengfr on 2020/6/5.
14+
*/
15+
public class ActiveMQJdbcLoginModule extends JaasAbstractJdbcLoginModule {
16+
17+
18+
public ActiveMQJdbcLoginModule() {
19+
super();
20+
}
21+
22+
23+
@Override
24+
protected boolean commitPrincipals(Subject subject, Context context) {
25+
String userName = context.userName;
26+
Set<Principal> principals = subject.getPrincipals();
27+
UserPrincipal userPrincipal = new UserPrincipal(userName);
28+
principals.add(userPrincipal);
29+
30+
Set<String> groups = getUserGroups(userName);
31+
log.debug(String.format("groups:%s,%s", userName, groups));
32+
if (groups != null) {
33+
context.groups = groups;
34+
for (String entry : context.groups) {
35+
principals.add(new GroupPrincipal(entry));
36+
}
37+
}
38+
return true;
39+
}
40+
41+
42+
}

easymqtt4j-artemis-plugins/pom.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
66
<artifactId>easymqtt4j</artifactId>
7-
<groupId>com.zengfr.easymqtt4j</groupId>
7+
<groupId>com.github.zengfr.easymqtt4j</groupId>
88
<version>1.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
@@ -18,6 +18,15 @@
1818
<groupId>org.apache.activemq</groupId>
1919
<artifactId>artemis-server</artifactId>
2020
</dependency>
21+
<!--dependency>
22+
<groupId>org.hibernate</groupId>
23+
<artifactId>hibernate-core</artifactId>
24+
<version>5.4.4.Final</version>
25+
</dependency-->
26+
<dependency>
27+
<groupId>com.github.zengfr.easymqtt4j</groupId>
28+
<artifactId>easymqtt4j-jaas-plugins</artifactId>
29+
</dependency>
2130
</dependencies>
2231
<dependencyManagement>
2332
<dependencies>
@@ -26,7 +35,13 @@
2635
<artifactId>artemis-server</artifactId>
2736
<version>2.12.0</version>
2837
</dependency>
38+
<dependency>
39+
<groupId>com.github.zengfr.easymqtt4j</groupId>
40+
<artifactId>easymqtt4j-jaas-plugins</artifactId>
41+
<version>${project.version}</version>
42+
</dependency>
2943
</dependencies>
44+
3045
</dependencyManagement>
3146

3247

easymqtt4j-artemis-plugins/src/main/java/com/zengfr/easymqtt4j/plugins/ArtemisActiveMQServerPlugin.java renamed to easymqtt4j-artemis-plugins/src/main/java/com/github/zengfr/easymqtt4j/plugins/ArtemisActiveMQServerPlugin.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
package com.zengfr.easymqtt4j.plugins;
1+
package com.github.zengfr.easymqtt4j.plugins;
22

33
import org.apache.activemq.artemis.api.core.*;
44
import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
5-
import org.apache.activemq.artemis.core.config.Configuration;
6-
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
75
import org.apache.activemq.artemis.core.persistence.OperationContext;
86
import org.apache.activemq.artemis.core.postoffice.QueueBinding;
97
import org.apache.activemq.artemis.core.server.ServerSession;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// * Created by zengfr on 2020/5/15.
33
// */
44
//import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
5-
//import org.apache.activemq.artemis.spi.core.security.jaas.CertificateCallback;
6-
//import org.apache.activemq.artemis.spi.core.security.jaas.JaasCallbackHandler;
7-
//import org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal;
8-
//import org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal;
5+
//import org.apache.activemq.artemis.spi.core.security.com.github.zengfr.easymqtt4j.jaas.CertificateCallback;
6+
//import org.apache.activemq.artemis.spi.core.security.com.github.zengfr.easymqtt4j.jaas.JaasCallbackHandler;
7+
//import org.apache.activemq.artemis.spi.core.security.com.github.zengfr.easymqtt4j.jaas.RolePrincipal;
8+
//import org.apache.activemq.artemis.spi.core.security.com.github.zengfr.easymqtt4j.jaas.UserPrincipal;
99
//import org.apache.qpid.proton.Proton;
1010
//import org.apache.qpid.proton.amqp.Symbol;
1111
//import org.apache.qpid.proton.engine.Connection;
@@ -96,7 +96,7 @@
9696
//
9797
// static {
9898
// try {
99-
// Class<?> jassCallbackHandlerClass = Class.forName("org.apache.activemq.artemis.spi.core.security.jaas.JaasCallbackHandler");
99+
// Class<?> jassCallbackHandlerClass = Class.forName("org.apache.activemq.artemis.spi.core.security.com.github.zengfr.easymqtt4j.jaas.JaasCallbackHandler");
100100
// REMOTING_CONNECTION_FIELD = jassCallbackHandlerClass.getField("remotingConnection");
101101
// REMOTING_CONNECTION_FIELD.setAccessible(true);
102102
// } catch (ClassNotFoundException | NoSuchFieldException ignored) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.zengfr.easymqtt4j.plugins; /**
1+
package com.github.zengfr.easymqtt4j.plugins; /**
22
* Created by zengfr on 2020/5/15.
33
*/
44
import java.util.Collections;

easymqtt4j-artemis-plugins/src/main/java/com/zengfr/easymqtt4j/plugins/ArtemisSecuritySettingPlugin.java renamed to easymqtt4j-artemis-plugins/src/main/java/com/github/zengfr/easymqtt4j/plugins/ArtemisSecuritySettingPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.zengfr.easymqtt4j.plugins;
1+
package com.github.zengfr.easymqtt4j.plugins;
22

33
import org.apache.activemq.artemis.core.security.Role;
44
import org.apache.activemq.artemis.core.server.SecuritySettingPlugin;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.github.zengfr.easymqtt4j.plugins.artemis;
2+
3+
import com.github.zengfr.easymqtt4j.plugins.jaas.JaasAbstractJdbcLoginModule;
4+
import org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal;
5+
import org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal;
6+
7+
import javax.security.auth.Subject;
8+
import java.security.Principal;
9+
import java.util.Set;
10+
11+
/**
12+
* Created by zengfr on 2020/6/5.
13+
*/
14+
public class ArtemisJdbcLoginModule extends JaasAbstractJdbcLoginModule {
15+
16+
17+
public ArtemisJdbcLoginModule() {
18+
super();
19+
20+
}
21+
22+
@Override
23+
protected boolean commitPrincipals(Subject subject, Context context) {
24+
String userName = context.userName;
25+
Set<Principal> principals = subject.getPrincipals();
26+
UserPrincipal userPrincipal = new UserPrincipal(userName);
27+
principals.add(userPrincipal);
28+
29+
Set<String> roles = getUserRoles(userName);
30+
log.debug(String.format("roles:%s,%s", userName, roles));
31+
if (roles != null) {
32+
context.roles = roles;
33+
for (String entry : context.roles) {
34+
principals.add(new RolePrincipal(entry));
35+
}
36+
}
37+
return true;
38+
}
39+
40+
}

0 commit comments

Comments
 (0)