1 package org
.argeo
.security
.activemq
;
3 import org
.apache
.activemq
.broker
.BrokerPluginSupport
;
4 import org
.apache
.activemq
.broker
.ConnectionContext
;
5 import org
.apache
.activemq
.command
.ConnectionInfo
;
6 import org
.argeo
.ArgeoException
;
7 import org
.argeo
.security
.core
.InternalAuthentication
;
8 import org
.springframework
.security
.Authentication
;
9 import org
.springframework
.security
.AuthenticationManager
;
10 import org
.springframework
.security
.context
.SecurityContext
;
11 import org
.springframework
.security
.context
.SecurityContextHolder
;
12 import org
.springframework
.security
.providers
.UsernamePasswordAuthenticationToken
;
14 public class ActiveMqSecurityBrokerPlugin
extends BrokerPluginSupport
{
15 // private final static Log log = LogFactory
16 // .getLog(ActiveMqSecurityBrokerPlugin.class);
18 private AuthenticationManager authenticationManager
;
19 private String systemUsername
= InternalAuthentication
.DEFAULT_SYSTEM_USERNAME
;
20 private String systemRole
= InternalAuthentication
.DEFAULT_SYSTEM_ROLE
;
23 public void addConnection(ConnectionContext context
, ConnectionInfo info
)
25 String username
= info
.getUserName();
27 throw new ArgeoException("No user name provided");
28 String password
= info
.getPassword();
29 if (password
== null) {
30 password
= context
.getConnection().getRemoteAddress().substring(1);
31 password
= password
.substring(0, password
.lastIndexOf(':'));
34 SecurityContext securityContext
= SecurityContextHolder
.getContext();
36 final Authentication authRequest
;
37 if (username
.equals(systemUsername
))
38 authRequest
= new InternalAuthentication(password
, username
,
41 authRequest
= new UsernamePasswordAuthenticationToken(username
,
44 final Authentication auth
= authenticationManager
45 .authenticate(authRequest
);
46 securityContext
.setAuthentication(auth
);
47 context
.setSecurityContext(new ActiveMqSpringSecurityContext(
50 super.addConnection(context
, info
);
53 public void setAuthenticationManager(
54 AuthenticationManager authenticationManager
) {
55 this.authenticationManager
= authenticationManager
;
58 public void setSystemUsername(String systemUsername
) {
59 this.systemUsername
= systemUsername
;
62 public void setSystemRole(String systemRole
) {
63 this.systemRole
= systemRole
;