Search in sources :

Example 11 with JMXPrincipal

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();
}
Also used : StringWriter(java.io.StringWriter) JMXPrincipal(javax.management.remote.JMXPrincipal) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 12 with JMXPrincipal

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;
}
Also used : JMXPrincipal(javax.management.remote.JMXPrincipal) X509Certificate(java.security.cert.X509Certificate)

Example 13 with JMXPrincipal

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);
}
Also used : JMXPrincipal(javax.management.remote.JMXPrincipal) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) X509Certificate(java.security.cert.X509Certificate) StubTransportListener(org.apache.activemq.transport.StubTransportListener) ObjectStreamWireFormat(org.apache.activemq.wireformat.ObjectStreamWireFormat)

Example 14 with JMXPrincipal

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;
        }
    };
}
Also used : Role(org.glassfish.security.common.Role) Group(org.glassfish.security.common.Group) JMXAuthenticator(javax.management.remote.JMXAuthenticator) JMXPrincipal(javax.management.remote.JMXPrincipal) Subject(javax.security.auth.Subject) PrincipalImpl(org.glassfish.security.common.PrincipalImpl)

Example 15 with JMXPrincipal

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);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXAuthenticator(javax.management.remote.JMXAuthenticator) JMXPrincipal(javax.management.remote.JMXPrincipal) Subject(javax.security.auth.Subject) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer)

Aggregations

JMXPrincipal (javax.management.remote.JMXPrincipal)15 Subject (javax.security.auth.Subject)10 Principal (java.security.Principal)4 MBeanServer (javax.management.MBeanServer)4 JMXServiceURL (javax.management.remote.JMXServiceURL)4 Properties (java.util.Properties)3 MBeanServerConnection (javax.management.MBeanServerConnection)3 ObjectName (javax.management.ObjectName)3 JMXConnector (javax.management.remote.JMXConnector)3 JMXConnectorServer (javax.management.remote.JMXConnectorServer)3 JMXPluggableAuthenticator (com.sun.jmx.remote.security.JMXPluggableAuthenticator)2 RemoteException (java.rmi.RemoteException)2 LocateRegistry (java.rmi.registry.LocateRegistry)2 Registry (java.rmi.registry.Registry)2 AccessControlContext (java.security.AccessControlContext)2 X509Certificate (java.security.cert.X509Certificate)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 Attribute (javax.management.Attribute)2 Notification (javax.management.Notification)2