Examples of LoginContext


Examples of javax.security.auth.login.LoginContext

                new LoginCallbackHandler(username, password);
        User user = null;
        UserManager userManager = UserManager.getInstance();
        UserActivityLogger logger = UserActivityLogger.getInstance();
        try{
            final LoginContext loginContext =
                    new LoginContext(AuthConstants.AUTH_CONFIG_INDEX,
                            callbackHandler);
            loginContext.login();
            /*  Need this for external login modules, user is really
            authenticated after this step   */

            Set principals = loginContext.getSubject().getPrincipals();
            Object obj = null;
            for(Iterator principalIt = principals.iterator(); principalIt.hasNext();){
                if((obj = principalIt.next()) instanceof User){
                    user = (User)obj;
                    break;
View Full Code Here

Examples of javax.security.auth.login.LoginContext

    * through the jmx/invoker/AuthenticatedRMIAdaptor
    * @throws Exception
    */
   public void testConfigurableRolesAuthorizedAccess() throws Exception
   {
      LoginContext lc = login("admin", "admin".toCharArray());
      InitialContext ctx = getInitialContext();
      MBeanServerConnection conn = (MBeanServerConnection) ctx.lookup("jmx/invoker/ConfigurableAuthorizedRMIAdaptor");
      ObjectName server = new ObjectName("jboss.system:type=Server");
      String version = (String) conn.getAttribute(server, "Version");
      log.info("Obtained server version: "+version);
      MBeanInfo info = conn.getMBeanInfo(server);
      assertNotNull("MBeanInfo != null", info);
      Integer mbeanCount = conn.getMBeanCount();
      assertNotNull("mbeanCount != null", mbeanCount);
      lc.logout();
   }
View Full Code Here

Examples of javax.security.auth.login.LoginContext

         URL authURL = loader.getResource("security/auth.conf");
         System.setProperty("java.security.auth.login.config", authURL.toString());
      }
      AppCallbackHandler handler = new AppCallbackHandler(username, password);
      log.debug("Creating LoginContext("+confName+")");
      LoginContext lc = new LoginContext(confName, handler);
      lc.login();
      log.debug("Created LoginContext, subject="+lc.getSubject());
      return lc;
   }
View Full Code Here

Examples of javax.security.auth.login.LoginContext

      // Specify the login conf file location
      String authConf = super.getResourceURL("security/auth.conf");
      getLog().debug("Using auth.conf: "+authConf);
      System.setProperty("java.security.auth.login.config", authConf);
      AppCallbackHandler handler = new AppCallbackHandler("admin", "admin".toCharArray());
      LoginContext lc = new LoginContext("testSecureHttpInvoker", handler);
      lc.login();

      // Test the secured JNDI factory
      env.setProperty(Context.PROVIDER_URL, INVOKER_BASE  + "restricted/JNDIFactory");
      getLog().debug("Creating InitialContext with env="+env);
      InitialContext ctx = new InitialContext(env);
      getLog().debug("Created InitialContext");
      Object obj = ctx.lookup("jmx");
      getLog().debug("lookup(jmx) : "+obj);
      Context jmxCtx = (Context) obj;
      NamingEnumeration list = jmxCtx.list("");
      while( list.hasMore() )
      {
         Object entry = list.next();
         getLog().debug(" + "+entry);
      }
      ctx.close();
      lc.logout();

      Principal p = SecurityAssociation.getPrincipal();
      assertTrue("SecurityAssociation.getPrincipal is null", p == null);

      /* This is now failing because we don't appear to have anyway to flush
View Full Code Here

Examples of javax.security.auth.login.LoginContext

   
         UsernamePasswordHandler handler = new UsernamePasswordHandler(username,
            credentials);
         Configuration conf = getConfiguration();
         // Do the JAAS login
         LoginContext lc = new LoginContext(protocol, null, handler, conf);
         lc.login();
      }
      catch(LoginException e)
      {
         AuthenticationException ex = new AuthenticationException("Failed to login using protocol="+protocol);
         ex.setRootCause(e);
View Full Code Here

Examples of javax.security.auth.login.LoginContext

            username = principal.toString();
         }
         UsernamePasswordHandler handler = new UsernamePasswordHandler(username,
            credentials);
         // Do the JAAS login
         LoginContext lc = new LoginContext(protocol, handler);
         lc.login();
      }
      catch(LoginException e)
      {
         AuthenticationException ex = new AuthenticationException("Failed to login using protocol="+protocol);
         ex.setRootCause(e);
View Full Code Here

Examples of javax.security.auth.login.LoginContext

   protected void startService() throws Exception
   {
      try
      {
         LoginContext lc = new LoginContext(securityDomain, callbackHandler);
         lc.login();
         this.systemSubject = lc.getSubject();
      }
      catch(Throwable t)
      {
         log.fatal("SystemAuthenticator failed, server will shutdown NOW!", t);
         LoginException le = new LoginException("SystemAuthenticator failed, msg="+t.getMessage());
View Full Code Here

Examples of javax.security.auth.login.LoginContext

   protected void stopService() throws Exception
   {
      if( systemSubject != null )
      {
         LoginContext lc = new LoginContext(securityDomain, systemSubject, callbackHandler);
         lc.logout();
      }
   }
View Full Code Here

Examples of javax.security.auth.login.LoginContext

   public void testLdapExample1() throws Exception
   {
      System.out.println("testLdapExample1");
      UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke", "theduke".toCharArray());
      LoginContext lc = new LoginContext("testLdapExample1", handler);
      lc.login();

      Subject subject = lc.getSubject();
      System.out.println("Subject: "+subject);

      Set groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains jduke", subject.getPrincipals().contains(new SimplePrincipal("jduke")));
      assertTrue("Principals contains Roles", groups.contains(new SimplePrincipal("Roles")));
      Group roles = (Group) groups.iterator().next();
      assertTrue("Echo is a role", roles.isMember(new SimplePrincipal("Echo")));
      assertTrue("TheDuke is a role", roles.isMember(new SimplePrincipal("TheDuke")));

      lc.logout();
   }
View Full Code Here

Examples of javax.security.auth.login.LoginContext

   }
   public void testLdapExample11() throws Exception
   {
      System.out.println("testLdapExample11");
      UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke", "theduke".toCharArray());
      LoginContext lc = new LoginContext("testLdapExample11", handler);
      lc.login();

      Subject subject = lc.getSubject();
      System.out.println("Subject: "+subject);

      Set groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains jduke", subject.getPrincipals().contains(new SimplePrincipal("jduke")));
      assertTrue("Principals contains Roles", groups.contains(new SimplePrincipal("Roles")));
      Group roles = (Group) groups.iterator().next();
      assertTrue("Echo is a role", roles.isMember(new SimplePrincipal("Echo")));
      assertTrue("TheDuke is a role", roles.isMember(new SimplePrincipal("TheDuke")));

      lc.logout();
   }
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.