use of javax.management.remote.JMXPrincipal in project java-docs-samples by GoogleCloudPlatform.
the class UsersServletTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
helper.setUp();
// Set up some fake HTTP requests
// If the user isn't logged in, use this request
when(mockRequestNotLoggedIn.getRequestURI()).thenReturn(FAKE_URL);
when(mockRequestNotLoggedIn.getUserPrincipal()).thenReturn(null);
// If the user is logged in, use this request
when(mockRequestLoggedIn.getRequestURI()).thenReturn(FAKE_URL);
// Most of the classes that implement Principal have been
// deprecated. JMXPrincipal seems like a safe choice.
when(mockRequestLoggedIn.getUserPrincipal()).thenReturn(new JMXPrincipal(FAKE_NAME));
// Set up a fake HTTP response.
responseWriter = new StringWriter();
when(mockResponse.getWriter()).thenReturn(new PrintWriter(responseWriter));
servletUnderTest = new UsersServlet();
}
use of javax.management.remote.JMXPrincipal in project activemq-artemis by apache.
the class SslSocketHelper method createSSLSocket.
public static SSLSocket createSSLSocket(String certDistinguishedName, boolean wantAuth, boolean needAuth) throws IOException {
JMXPrincipal principal = new JMXPrincipal(certDistinguishedName);
X509Certificate cert = new StubX509Certificate(principal);
StubSSLSession sslSession = new StubSSLSession(cert);
StubSSLSocket sslSocket = new StubSSLSocket(sslSession);
sslSocket.setWantClientAuth(wantAuth);
sslSocket.setNeedClientAuth(needAuth);
return sslSocket;
}
use of javax.management.remote.JMXPrincipal in project activemq-artemis by apache.
the class SslTransportTest method createTransportAndConsume.
private void createTransportAndConsume(boolean wantAuth, boolean needAuth) throws IOException {
JMXPrincipal principal = new JMXPrincipal(certDistinguishedName);
X509Certificate cert = new StubX509Certificate(principal);
StubSSLSession sslSession = new StubSSLSession(cert);
sslSocket = new StubSSLSocket(sslSession);
sslSocket.setWantClientAuth(wantAuth);
sslSocket.setNeedClientAuth(needAuth);
SslTransport transport = new SslTransport(new ObjectStreamWireFormat(), sslSocket);
stubListener = new StubTransportListener();
transport.setTransportListener(stubListener);
ConnectionInfo sentInfo = new ConnectionInfo();
sentInfo.setUserName(username);
sentInfo.setPassword(password);
transport.doConsume(sentInfo);
}
use of javax.management.remote.JMXPrincipal in project Payara by payara.
the class ConnectorStarter method getAccessController.
public JMXAuthenticator getAccessController() {
// needed by the system.
return new JMXAuthenticator() {
/**
* We actually wait for the first authentication request to delegate/
* @param credentials
* @return
*/
public Subject authenticate(Object credentials) {
// lazy init...
// todo : lloyd, if this becomes a performance bottleneck, we should cache
// on first access.
JMXAuthenticator controller = mHabitat.getService(JMXAuthenticator.class);
Subject adminSubject = controller.authenticate(credentials);
if (adminSubject != null) {
// extract the principal name and create a JMXPrincipal and add to the subject PAYARA-1251
Set<PrincipalImpl> principals = adminSubject.getPrincipals(PrincipalImpl.class);
for (PrincipalImpl principal : principals) {
if (!(principal instanceof Group) && !(principal instanceof Role)) {
adminSubject.getPrincipals().add(new JMXPrincipal(principal.getName()));
}
}
}
return adminSubject;
}
};
}
use of javax.management.remote.JMXPrincipal in project Openfire by igniterealtime.
the class JMXManager method start.
private void start() {
setContainer(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
int jmxPort = JMXManager.getPort();
String jmxUrl = "/jndi/rmi://localhost:" + jmxPort + "/jmxrmi";
Map<String, Object> env = new HashMap<>();
if (JMXManager.isSecure()) {
env.put("jmx.remote.authenticator", new JMXAuthenticator() {
@Override
public Subject authenticate(Object credentials) {
if (!(credentials instanceof String[])) {
if (credentials == null) {
throw new SecurityException("Credentials required");
}
throw new SecurityException("Credentials should be String[]");
}
final String[] aCredentials = (String[]) credentials;
if (aCredentials.length < 2) {
throw new SecurityException("Credentials should have at least two elements");
}
String username = aCredentials[0];
String password = aCredentials[1];
try {
AuthFactory.authenticate(username, password);
} catch (Exception ex) {
Log.error("Authentication failed for " + username);
throw new SecurityException();
}
if (AdminManager.getInstance().isUserAdmin(username, true)) {
return new Subject(true, Collections.singleton(new JMXPrincipal(username)), Collections.EMPTY_SET, Collections.EMPTY_SET);
} else {
Log.error("Authorization failed for " + username);
throw new SecurityException();
}
}
});
}
try {
jmxServer = new ConnectorServer(new JMXServiceURL("rmi", null, jmxPort, jmxUrl), env, "org.eclipse.jetty.jmx:name=rmiconnectorserver");
jmxServer.start();
} catch (Exception e) {
Log.error("Failed to start JMX connector", e);
}
}
Aggregations