Package org.jboss.security.auth.callback

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


     
      Principal jduke1 = new SimplePrincipal("jduke1");
      SecurityAssociation.setPrincipal(jduke1);
      SecurityAssociation.setCredential("theduke1");

      UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke2",
         "theduke2");
      LoginContext lc = new LoginContext("testSingleThreadedRestoreIdentity", handler);
      lc.login();
      Subject subject = lc.getSubject();
      System.out.println("LC.Subject: "+subject);
View Full Code Here


      Principal jduke2 = new SimplePrincipal("jduke2");
      Subject subject2 = new Subject();
      SecurityAssociation.pushSubjectContext(subject2, jduke2, "theduke2");

      UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke3",
         "theduke3");
      LoginContext lc = new LoginContext("testSingleThreadedRestoreIdentity", handler);
      lc.login();
      Subject subject = lc.getSubject();
      System.out.println("LC.Subject: "+subject);
View Full Code Here

   {
      SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
      SecurityContextAssociation.setSecurityContext(sc);
     
      //Start with successful login. Then a failed login
      UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke", "jduke");
      LoginContext lc = new LoginContext("testAbortWithRestore", handler);
      lc.login();
      Subject subject = lc.getSubject();
      assertNotNull("Subject is not null", subject);
     
      SecurityContext currentSC = SecurityContextAssociation.getSecurityContext();
      assertNotNull("Current Security Context is not null", currentSC);
      verifySubjectInfo(currentSC);
     
      //Failed Login
      handler = new UsernamePasswordHandler("jduke", "BAD_PASSWORD");
      lc = new LoginContext("testAbortWithRestore", handler);
      try
      {
         lc.login();
         fail("Should have failed");
      }
      catch(LoginException le)
      {
         //pass
      }
      subject = lc.getSubject();
      assertNull("Subject from login context is null", subject);
     
      currentSC = SecurityContextAssociation.getSecurityContext();
      assertNotNull("Current Security Context is not null", currentSC);
      verifySubjectInfo(currentSC);
     
     
      //Successful Login
      SecurityContextAssociation.setSecurityContext(sc);
      handler = new UsernamePasswordHandler("jduke", "jduke");
      lc = new LoginContext("testAbortWithRestore", handler);
      lc.login();
      subject = lc.getSubject();
      assertNotNull("Subject is not null", subject);
     
      currentSC = SecurityContextAssociation.getSecurityContext();
      assertNotNull("Current Security Context is not null", currentSC);
      verifySubjectInfo(currentSC);
     
      //Failed Login
      handler = new UsernamePasswordHandler("jduke", "BAD_PASSWORD");
      lc = new LoginContext("testAbortWithRestore", handler);
      try
      {
         lc.login();
         fail("Should have failed");
View Full Code Here

      SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
      SecurityContextAssociation.setSecurityContext(sc);
     
      //Successful Login
      SecurityContextAssociation.setSecurityContext(sc);
      UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke", "jduke");
      LoginContext lc = new LoginContext("testAbortWithNoRestore", handler);
      lc.login();
      Subject subject = lc.getSubject();
      assertNotNull("Subject is not null", subject);
     
      SecurityContext currentSC = SecurityContextAssociation.getSecurityContext();
      assertNotNull("Current Security Context is not null", currentSC);
      this.verifySubjectInfo(currentSC);
     
      //Failed Login - calls abort on the login modules
      handler = new UsernamePasswordHandler("BAD_USER", "BAD_PASSWORD");
      lc = new LoginContext("testAbortWithNoRestore", handler);
      try
      {
         lc.login();
         fail("Should have failed");
      }
      catch(LoginException le)
      {
         //pass
      }
      //Ensure that the failed login context does not return a subject
      subject = lc.getSubject();
      assertNull("Subject is null", subject);
     
      //We have to ensure that the first successful authentication has not been removed from the stack
      currentSC = SecurityContextAssociation.getSecurityContext();
      assertNotNull("Current Security Context is not null", currentSC);
      this.verifySubjectInfo(currentSC);
           
      //Let us go through some logout cycles
      handler = new UsernamePasswordHandler("jduke", "jduke");
      lc = new LoginContext("testAbortWithNoRestore", handler);
      lc.login();
      subject = lc.getSubject();
      assertNotNull("Subject is not null", subject);
     
      currentSC = SecurityContextAssociation.getSecurityContext();
      assertNotNull("Current Security Context is not null", currentSC);
      this.verifySubjectInfo(currentSC);
     
      lc.logout();

      assertNull("Current Security Context is null", SecurityContextAssociation.getSecurityContext());
      subject = lc.getSubject();
      assertEquals("Subject from login context has no principals", 0, subject.getPrincipals().size());
     
      sc = SecurityContextFactory.createSecurityContext("test");
      SecurityContextAssociation.setSecurityContext(sc);
     
      //Failed Login - calls abort on the login modules
      handler = new UsernamePasswordHandler("BAD_USER", "BAD_PASSWORD");
      lc = new LoginContext("testAbortWithNoRestore", handler);
      try
      {
         lc.login();
         fail("Should have failed");
View Full Code Here

      public void run()
      {
         try
         {
            System.out.println("+++ testMultiThreadedRunnable");
            UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke",
               "theduke");
            LoginContext lc = new LoginContext("testSingleThreaded", handler);
            lc.login();
            Subject subject = lc.getSubject();
            System.out.println("LC.Subject: "+subject);
View Full Code Here

  }

  public void testClientLogin() throws Exception
  {
     log.info("testClientLogin");
     UsernamePasswordHandler handler = new UsernamePasswordHandler("scott", "secret".toCharArray());
     LoginContext lc = new LoginContext("testClientLogin", handler);
     lc.login();
     Subject subject = lc.getSubject();
     Principal scott = new SimplePrincipal("scott");
     assertTrue("Principals contains scott", subject.getPrincipals().contains(scott));
     Principal saPrincipal = SecurityAssociation.getPrincipal();
     assertTrue("SecurityAssociation.getPrincipal == scott", saPrincipal.equals(scott));

     UsernamePasswordHandler handler2 = new UsernamePasswordHandler("scott2", "secret2".toCharArray());
     LoginContext lc2 = new LoginContext("testClientLogin", handler2);
     lc2.login();
     Principal scott2 = new SimplePrincipal("scott2");
     saPrincipal = SecurityAssociation.getPrincipal();
     assertTrue("SecurityAssociation.getPrincipal == scott2", saPrincipal.equals(scott2));
View Full Code Here

  }

  public void testUsernamePassword() throws Exception
  {
     log.info("testUsernamePassword");
     UsernamePasswordHandler handler = new UsernamePasswordHandler("scott", "secret".toCharArray());
     LoginContext lc = new LoginContext("testUsernamePassword", 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

     lc.logout();
  }
  public void testUsernamePasswordHash() throws Exception
  {
     log.info("testUsernamePasswordHash");
     UsernamePasswordHandler handler = new UsernamePasswordHandler("scott", "secret".toCharArray());
     LoginContext lc = new LoginContext("testUsernamePasswordHash", 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 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

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.