HashLoginService loginService = new HashLoginService("CometD-Realm");
loginService.putUser(userName, Credential.getCredential(password), roles);
server.addBean(loginService);
Handler handler = server.getHandler();
ConstraintSecurityHandler security = new ConstraintSecurityHandler();
server.setHandler(security);
security.setHandler(handler);
Constraint constraint = new Constraint();
constraint.setAuthenticate(true);
constraint.setRoles(roles);
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec(cometdServletPath + "/*");
mapping.setConstraint(constraint);
security.setConstraintMappings(Collections.singletonList(mapping));
security.setAuthenticator(new BasicAuthenticator());
security.setLoginService(loginService);
connector.setPort(port);
server.start();
LongPollingTransport transport = new LongPollingTransport(null, httpClient)