Examples of JMXPrincipal


Examples of javax.management.remote.JMXPrincipal

            if (creds.length != 2) throw new SecurityException("Bad credentials");
            String user = creds[0];
            String password = creds[1];
            if (!"test".equals(user)) throw new SecurityException("Unknown user");
            if (!"test".equals(password)) throw new SecurityException("Wrong password");
            Principal principal = new JMXPrincipal(user);
            Set principals = new HashSet();
            principals.add(principal);
            Subject subject = new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
            return subject;
         }
      });

      JMXConnectorServer cntorServer = null;
      JMXConnector cntor = null;
      try
      {
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, serverEnv, newMBeanServer());

         // Required by the server
         addPermission(new SocketPermission("localhost:" + url.getPort(), "listen"));
         cntorServer.start();

         policy.setSeparateClientServerPermissions(true);

         Map clientEnv = createClientEnvironment();
         clientEnv.put(JMXConnector.CREDENTIALS, new String[]{"test", "test"});
         policy.addClientPermission(new SocketPermission("localhost:" + url.getPort(), "connect"));
         policy.addServerPermission(new JMXPrincipal("test"), new AuthPermission("doAsPrivileged"));
         policy.addServerPermission(new JMXPrincipal("test"), new SocketPermission("localhost:" + url.getPort(), "listen"));
         policy.addServerPermission(new JMXPrincipal("test"), new SocketPermission("*:1024-" + url.getPort(), "accept"));
         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), clientEnv);

         addPermission(new MBeanTrustPermission("*"));
         policy.addServerPermission(new JMXPrincipal("test"), new MBeanPermission("*", "instantiate, registerMBean, getAttribute"));
         MBeanServerConnection cntion = cntor.getMBeanServerConnection();
         ObjectName name = ObjectName.getInstance(":name=subject");
         cntion.createMBean(SubjectCheck.class.getName(), name, null);
         policy.addServerPermission(new JMXPrincipal("test"), new AuthPermission("getSubject"));
         Subject subject = (Subject)cntion.getAttribute(name, "Subject");

         Set principals = subject.getPrincipals();
         assertNotNull(principals);
         assertEquals(principals.size(), 1);
         Principal principal = (Principal)principals.iterator().next();
         assertTrue(principal instanceof JMXPrincipal);
         assertEquals(principal.getName(), "test");
      }
      finally
      {
         if (cntor != null) cntor.close();
         if (cntorServer != null) cntorServer.stop();
View Full Code Here

Examples of javax.management.remote.JMXPrincipal

            if (creds.length != 2) throw new SecurityException("Bad credentials");
            String user = creds[0];
            String password = creds[1];
            if (!"test".equals(user)) throw new SecurityException("Unknown user");
            if (!"test".equals(password)) throw new SecurityException("Wrong password");
            Principal principal = new JMXPrincipal(user);
            Set principals = new HashSet();
            principals.add(principal);
            Subject subject = new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
            return subject;
         }
      });

      JMXConnectorServer cntorServer = null;
      JMXConnector cntor = null;
      try
      {
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, serverEnv, newMBeanServer());
         // Required by the server
         addPermission(new SocketPermission("localhost:" + url.getPort(), "listen"));
         cntorServer.start();

         policy.setSeparateClientServerPermissions(true);

         Map clientEnv = createClientEnvironment();
         clientEnv.put(JMXConnector.CREDENTIALS, new String[]{"test", "test"});
         policy.addClientPermission(new SocketPermission("localhost:" + url.getPort(), "connect"));
         policy.addServerPermission(new JMXPrincipal("test"), new AuthPermission("doAsPrivileged"));
         policy.addServerPermission(new JMXPrincipal("test"), new SocketPermission("localhost:" + url.getPort(), "listen"));
         policy.addServerPermission(new JMXPrincipal("test"), new SocketPermission("*:1024-" + url.getPort(), "accept"));
         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), clientEnv);

         addPermission(new MBeanTrustPermission("*"));
         policy.addServerPermission(new JMXPrincipal("delegate"), new MBeanPermission("*", "instantiate, registerMBean, getAttribute"));
         policy.addServerPermission(new JMXPrincipal("test"), new SubjectDelegationPermission(JMXPrincipal.class.getName() + ".delegate"));

         Set delegates = new HashSet();
         delegates.add(new JMXPrincipal("delegate"));
         Subject delegate = new Subject(true, delegates, Collections.EMPTY_SET, Collections.EMPTY_SET);
         MBeanServerConnection cntion = cntor.getMBeanServerConnection(delegate);
         ObjectName name = ObjectName.getInstance(":name=subject");
         cntion.createMBean(SubjectCheck.class.getName(), name, null);
         policy.addServerPermission(new JMXPrincipal("delegate"), new AuthPermission("getSubject"));
         Subject subject = (Subject)cntion.getAttribute(name, "Subject");

         Set principals = subject.getPrincipals();
         assertNotNull(principals);
         assertEquals(principals.size(), 1);
         Principal principal = (Principal)principals.iterator().next();
         assertTrue(principal instanceof JMXPrincipal);
         assertEquals(principal.getName(), "delegate");
      }
      finally
      {
         if (cntor != null) cntor.close();
         if (cntorServer != null) cntorServer.stop();
View Full Code Here

Examples of javax.management.remote.JMXPrincipal

      serverEnv.put(JMXConnectorServer.AUTHENTICATOR, new JMXAuthenticator()
      {
         public Subject authenticate(Object credentials) throws SecurityException
         {
            Set principals = new HashSet();
            principals.add(new JMXPrincipal(principalName));
            return new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
         }
      });

      JMXConnectorServer cntorServer = null;
View Full Code Here

Examples of javax.management.remote.JMXPrincipal

      serverEnv.put(JMXConnectorServer.AUTHENTICATOR, new JMXAuthenticator()
      {
         public Subject authenticate(Object credentials) throws SecurityException
         {
            Set principals = new HashSet();
            principals.add(new JMXPrincipal("authenticatedPrincipal"));
            return new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
         }
      });
      JMXConnectorServer cntorServer = null;
      try
      {
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, serverEnv, newMBeanServer());
         cntorServer.start();

         Map clientEnv = getEnvironment();
         clientEnv.put(JMXConnector.CREDENTIALS, new String[0]);

         JMXConnector cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), clientEnv);
         Set principals = new HashSet();
         String delegatedName = "delegatedPrincipal";
         principals.add(new JMXPrincipal(delegatedName));
         Subject delegate = new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
         MBeanServerConnection mbsc = cntor.getMBeanServerConnection(delegate);

         ObjectName name = ObjectName.getInstance("", "test", "invocation");
         ObjectInstance instance = mbsc.createMBean(Support.class.getName(), name, null);
View Full Code Here

Examples of javax.management.remote.JMXPrincipal

      public boolean authenticated(String name)
      {
         Subject subject = Subject.getSubject(AccessController.getContext());
         if (subject == null) return false;
         Set principals = subject.getPrincipals();
         return principals.contains(new JMXPrincipal(name));
      }
View Full Code Here

Examples of javax.management.remote.JMXPrincipal

      public boolean delegated(String name)
      {
         Subject subject = Subject.getSubject(AccessController.getContext());
         if (subject == null) return false;
         Set principals = subject.getPrincipals();
         return principals.contains(new JMXPrincipal(name));
      }
View Full Code Here

Examples of javax.management.remote.JMXPrincipal

      return jcn;
   }

   public JMXPrincipal createJMXPrincipal()
   {
      JMXPrincipal jp = new JMXPrincipal(JMXPrincipal.class.getName());
      return jp;
   }
View Full Code Here

Examples of javax.management.remote.JMXPrincipal

            sharedState.put(USERNAME_KEY, username);
            sharedState.put(PASSWORD_KEY, password);
        }

        // Create a new user principal
        user = new JMXPrincipal(username);

        if (logger.debugOn()) {
            logger.debug("login",
                "User '" + username + "' successfully validated");
        }
View Full Code Here

Examples of javax.management.remote.JMXPrincipal

            throw new SecurityException("Authentication manager failed", result.getCause());
        }
        else if (AuthenticationStatus.SUCCESS.equals(result.getStatus()))
        {
            final Subject subject = result.getSubject();
            subject.getPrincipals().add(new JMXPrincipal(username));
            subject.setReadOnly();
            return subject;
        }
        else
        {
View Full Code Here

Examples of javax.management.remote.JMXPrincipal

    protected void tearDown() throws Exception {
        super.tearDown();
    }

    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);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.