Package org.jboss.security.auth.callback

Examples of org.jboss.security.auth.callback.UsernamePasswordHandler


   {
      log.info("testUsernamePasswordHashWithDigestCallback");
      // secret in ascii
      byte[] passBytes = {115, 101, 99, 114, 101, 116};
      String pass = new String(passBytes, "UTF-8");
      UsernamePasswordHandler handler = new UsernamePasswordHandler("scott", pass.toCharArray());
      LoginContext lc = new LoginContext("testUsernamePasswordHashWithDigestCallback", handler);
      lc.login();
      Subject subject = lc.getSubject();
      Set groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains scott", subject.getPrincipals().contains(new SimplePrincipal("scott")));
View Full Code Here


   }

   public void testUsersRoles() throws Exception
   {
      log.info("testUsersRoles");
      UsernamePasswordHandler handler = new UsernamePasswordHandler("scott", "echoman".toCharArray());
      LoginContext lc = new LoginContext("testUsersRoles", handler);
      lc.login();
      Subject subject = lc.getSubject();
      Set groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains scott", subject.getPrincipals().contains(new SimplePrincipal("scott")));
      assertTrue("Principals contains Roles", groups.contains(new SimplePrincipal("Roles")));
      assertTrue("Principals contains CallerPrincipal", groups.contains(new SimplePrincipal("CallerPrincipal")));
      Group roles = (Group) groups.iterator().next();
      Iterator groupsIter = groups.iterator();
      while( groupsIter.hasNext() )
      {
         roles = (Group) groupsIter.next();
         if( roles.getName().equals("Roles") )
         {
            assertTrue("Echo is a role", roles.isMember(new SimplePrincipal("Echo")));
            assertTrue("Java is NOT a role", roles.isMember(new SimplePrincipal("Java")) == false);
            assertTrue("Coder is NOT a role", roles.isMember(new SimplePrincipal("Coder")) == false);
         }
         else if( roles.getName().equals("CallerPrincipal") )
         {
            log.info("CallerPrincipal is "+roles.members().nextElement());
            boolean isMember = roles.isMember(new SimplePrincipal("callerScott"));
            assertTrue("CallerPrincipal is callerScott", isMember);
         }
      }
      lc.logout();

      handler = new UsernamePasswordHandler("stark", "javaman".toCharArray());
      lc = new LoginContext("testUsersRoles", handler);
      lc.login();
      subject = lc.getSubject();
      groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains stark", subject.getPrincipals().contains(new SimplePrincipal("stark")));
      assertTrue("Principals contains Roles", groups.contains(new SimplePrincipal("Roles")));
      assertTrue("Principals contains CallerPrincipal", groups.contains(new SimplePrincipal("CallerPrincipal")));
      groupsIter = groups.iterator();
      while( groupsIter.hasNext() )
      {
         roles = (Group) groupsIter.next();
         if( roles.getName().equals("Roles") )
         {
            assertTrue("Echo is NOT a role", roles.isMember(new SimplePrincipal("Echo")) == false);
            assertTrue("Java is a role", roles.isMember(new SimplePrincipal("Java")));
            assertTrue("Coder is a role", roles.isMember(new SimplePrincipal("Coder")));
         }
         else if( roles.getName().equals("CallerPrincipal") )
         {
            log.info("CallerPrincipal is "+roles.members().nextElement());
            boolean isMember = roles.isMember(new SimplePrincipal("callerStark"));
            assertTrue("CallerPrincipal is callerStark", isMember);
         }
      }
      lc.logout();

      // Test the usernames with common prefix
      log.info("Testing similar usernames");
      handler = new UsernamePasswordHandler("jdukeman", "anotherduke".toCharArray());
      lc = new LoginContext("testUsersRoles", handler);
      lc.login();
      subject = lc.getSubject();
      groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains jdukeman", subject.getPrincipals().contains(new SimplePrincipal("jdukeman")));
View Full Code Here

   }

   public void testUsersRolesHash() throws Exception
   {
      log.info("testUsersRolesHash");
      UsernamePasswordHandler handler = new UsernamePasswordHandler("scott", "echoman".toCharArray());
      LoginContext lc = new LoginContext("testUsersRolesHash", handler);
      lc.login();
      Subject subject = lc.getSubject();
      Set groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains scott", subject.getPrincipals().contains(new SimplePrincipal("scott")));
View Full Code Here

   }

   public void testAnonUsersRoles() throws Exception
   {
      log.info("testAnonUsersRoles");
      UsernamePasswordHandler handler = new UsernamePasswordHandler(null, null);
      LoginContext lc = new LoginContext("testAnonUsersRoles", handler);
      lc.login();
      Subject subject = lc.getSubject();
      Set groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains nobody", subject.getPrincipals().contains(new SimplePrincipal("nobody")));
View Full Code Here

      lc.logout();
   }
   public void testAnon() throws Exception
   {
      log.info("testAnon");
      UsernamePasswordHandler handler = new UsernamePasswordHandler(null, null);
      LoginContext lc = new LoginContext("testAnon", handler);
      lc.login();
      Subject subject = lc.getSubject();
      Set groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains nobody", subject.getPrincipals().contains(new SimplePrincipal("nobody")));
View Full Code Here

      lc.logout();
   }
   public void testNull() throws Exception
   {
      log.info("testNull");
      UsernamePasswordHandler handler = new UsernamePasswordHandler(null, null);
      LoginContext lc = new LoginContext("testNull", handler);
      try
      {
         lc.login();
         fail("Should not be able to login as null, null");
View Full Code Here

   }

   public void testSimple() throws Exception
   {
      log.info("testSimple");
      UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke", "jduke".toCharArray());
      LoginContext lc = new LoginContext("testSimple", handler);
      lc.login();
      Subject subject = lc.getSubject();
      Set groups = subject.getPrincipals(Group.class);
      assertTrue("Principals contains jduke", subject.getPrincipals().contains(new SimplePrincipal("jduke")));
View Full Code Here

      log.info("testJdbc");
     
      Connection conn = setupLoginTables();
      try
      {
         UsernamePasswordHandler handler = new UsernamePasswordHandler("stark", "javaman".toCharArray());
         LoginContext lc = new LoginContext("testJdbc", handler);
         lc.login();
         Subject subject = lc.getSubject();
         Set groups = subject.getPrincipals(Group.class);
         assertTrue("Principals contains stark", subject.getPrincipals().contains(new SimplePrincipal("stark")));
View Full Code Here

         /* Test that the UsersRolesLoginModule is sufficient to login. Only the
          users.properties file has a jduke=theduke username to password mapping,
          and the DatabaseServerLoginModule will fail.
         */
         UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke", "theduke".toCharArray());
         LoginContext lc = new LoginContext("testControlFlags", handler);
         lc.login();
         Subject subject = lc.getSubject();
         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 = findRolesGroup(groups);
         // Only the roles from the DatabaseServerLoginModule should exist
         assertTrue("Role1 is a role", roles.isMember(new SimplePrincipal("Role1")));
         assertTrue("Role2 is a role", roles.isMember(new SimplePrincipal("Role2")));
         assertTrue("Role3 is NOT a role", !roles.isMember(new SimplePrincipal("Role3")));
         assertTrue("Role4 is NOT a role", !roles.isMember(new SimplePrincipal("Role4")));
         lc.logout();

         /* Test that the DatabaseServerLoginModule is sufficient to login. Only the
           Principals table has a jduke=jduke username to password mapping, and
           the UsersRolesLoginModule will fail.
         */
         handler = new UsernamePasswordHandler("jduke", "jduke".toCharArray());
         lc = new LoginContext("testControlFlags", handler);
         lc.login();
         subject = lc.getSubject();
         groups = subject.getPrincipals(Group.class);
         assertTrue("Principals contains jduke", subject.getPrincipals().contains(new SimplePrincipal("jduke")));
View Full Code Here

        processRequest(request, response);
    }

    private LoginContext doLogin(String username, String password) throws LoginException
    {
        UsernamePasswordHandler handler = new UsernamePasswordHandler(username, password.toCharArray());
        LoginContext lc = new LoginContext("client-login", handler);
        lc.login();
        return lc;
    }
View Full Code Here

TOP

Related Classes of org.jboss.security.auth.callback.UsernamePasswordHandler

Copyright © 2018 www.massapicom. 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.