@Test
 public void verifyAttributesWithPrincipal() {
   final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
   resolver.setAttributeRepository(TestUtils.getAttributeRepository());
   resolver.setPrincipalAttributeName("cn");
   final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
   final Principal p = resolver.resolve(c);
   assertNotNull(p);
   assertNotEquals(p.getId(), TestUtils.CONST_USERNAME);
   assertTrue(p.getAttributes().containsKey("memberOf"));
 }
 @Test
 public void verifyNoAttributesWithPrincipal() {
   final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
   resolver.setPrincipalAttributeName(TestUtils.CONST_USERNAME);
   final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
   final Principal p = resolver.resolve(c);
   assertNotNull(p);
 }
示例#3
0
 /**
  * Method to add a TicketGrantingTicket to the ticket cache. This should add the ticket and
  * return. Failure upon any exception.
  */
 @Test
 public void verifyAddTicketToCache() {
   try {
     this.ticketRegistry.addTicket(
         new TicketGrantingTicketImpl(
             "TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
   } catch (final Exception e) {
     fail("Caught an exception. But no exception should have been thrown.");
   }
 }
示例#4
0
 @Test
 public void verifyDeleteNullTicket() {
   try {
     this.ticketRegistry.addTicket(
         new TicketGrantingTicketImpl(
             "TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
     assertFalse("Ticket was deleted.", this.ticketRegistry.deleteTicket(null));
   } catch (final Exception e) {
     fail("Caught an exception. But no exception should have been thrown.");
   }
 }
示例#5
0
 @Test
 public void verifyGetExistingTicketWithInproperClass() {
   try {
     this.ticketRegistry.addTicket(
         new TicketGrantingTicketImpl(
             "TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
     this.ticketRegistry.getTicket("TEST", ServiceTicket.class);
   } catch (final ClassCastException e) {
     return;
   }
   fail("ClassCastfinal Exception expected.");
 }
示例#6
0
  @Test
  public void verifyGetTicketsFromRegistryEqualToTicketsAdded() {
    final Collection<Ticket> tickets = new ArrayList<>();

    for (int i = 0; i < TICKETS_IN_REGISTRY; i++) {
      final TicketGrantingTicket ticketGrantingTicket =
          new TicketGrantingTicketImpl(
              "TEST" + i, TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
      final ServiceTicket st =
          ticketGrantingTicket.grantServiceTicket(
              "tests" + i,
              org.apereo.cas.services.TestUtils.getService(),
              new NeverExpiresExpirationPolicy(),
              false,
              true);
      tickets.add(ticketGrantingTicket);
      tickets.add(st);
      this.ticketRegistry.addTicket(ticketGrantingTicket);
      this.ticketRegistry.addTicket(st);
    }

    try {
      final Collection<Ticket> ticketRegistryTickets = this.ticketRegistry.getTickets();
      assertEquals(
          "The size of the registry is not the same as the collection.",
          ticketRegistryTickets.size(),
          tickets.size());

      tickets
          .stream()
          .filter(ticket -> !ticketRegistryTickets.contains(ticket))
          .forEach(
              ticket ->
                  fail(
                      "Ticket was added to registry but was not found in retrieval of collection of all tickets."));
    } catch (final Exception e) {
      fail("Caught an exception. But no exception should have been thrown.");
    }
  }
示例#7
0
  @Test
  public void verifyDeleteTicketWithChildren() {
    try {
      this.ticketRegistry.addTicket(
          new TicketGrantingTicketImpl(
              "TGT", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
      final TicketGrantingTicket tgt =
          this.ticketRegistry.getTicket("TGT", TicketGrantingTicket.class);

      final Service service = org.apereo.cas.services.TestUtils.getService("TGT_DELETE_TEST");

      final ServiceTicket st1 =
          tgt.grantServiceTicket("ST1", service, new NeverExpiresExpirationPolicy(), true, false);
      final ServiceTicket st2 =
          tgt.grantServiceTicket("ST2", service, new NeverExpiresExpirationPolicy(), true, false);
      final ServiceTicket st3 =
          tgt.grantServiceTicket("ST3", service, new NeverExpiresExpirationPolicy(), true, false);

      this.ticketRegistry.addTicket(st1);
      this.ticketRegistry.addTicket(st2);
      this.ticketRegistry.addTicket(st3);

      assertNotNull(this.ticketRegistry.getTicket("TGT", TicketGrantingTicket.class));
      assertNotNull(this.ticketRegistry.getTicket("ST1", ServiceTicket.class));
      assertNotNull(this.ticketRegistry.getTicket("ST2", ServiceTicket.class));
      assertNotNull(this.ticketRegistry.getTicket("ST3", ServiceTicket.class));

      this.ticketRegistry.deleteTicket(tgt.getId());

      assertNull(this.ticketRegistry.getTicket("TGT", TicketGrantingTicket.class));
      assertNull(this.ticketRegistry.getTicket("ST1", ServiceTicket.class));
      assertNull(this.ticketRegistry.getTicket("ST2", ServiceTicket.class));
      assertNull(this.ticketRegistry.getTicket("ST3", ServiceTicket.class));
    } catch (final Exception e) {
      fail("Caught an exception. But no exception should have been thrown.");
    }
  }