Example #1
0
  @Test
  public void verifyEncodeDecode() throws Exception {
    final ServiceTicket expectedST = new MockServiceTicket(ST_ID);
    assertEquals(expectedST, transcoder.decode(transcoder.encode(expectedST)));

    final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    final TicketGrantingTicket expectedTGT =
        new MockTicketGrantingTicket(TGT_ID, userPassCredential, this.principalAttributes);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));

    internalProxyTest("http://localhost");
    internalProxyTest("https://localhost:8080/path/file.html?p1=v1&p2=v2#fragment");
  }
Example #2
0
  @Test
  public void verifyEncodeDecodeTGTImpl() throws Exception {
    final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    final AuthenticationBuilder bldr =
        new DefaultAuthenticationBuilder(
            new DefaultPrincipalFactory()
                .createPrincipal("user", Collections.unmodifiableMap(this.principalAttributes)));
    bldr.setAttributes(Collections.unmodifiableMap(this.principalAttributes));
    bldr.setAuthenticationDate(new DateTime());
    bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
    bldr.addFailure("error", AccountNotFoundException.class);
    bldr.addSuccess(
        "authn",
        new DefaultHandlerResult(
            new AcceptUsersAuthenticationHandler(),
            new BasicCredentialMetaData(userPassCredential)));

    final TicketGrantingTicket parent =
        new TicketGrantingTicketImpl(
            TGT_ID,
            org.jasig.cas.authentication.TestUtils.getService(),
            null,
            bldr.build(),
            new NeverExpiresExpirationPolicy());

    final TicketGrantingTicket expectedTGT =
        new TicketGrantingTicketImpl(
            TGT_ID,
            org.jasig.cas.services.TestUtils.getService(),
            null,
            bldr.build(),
            new NeverExpiresExpirationPolicy());

    final ServiceTicket ticket =
        expectedTGT.grantServiceTicket(
            ST_ID,
            org.jasig.cas.services.TestUtils.getService(),
            new NeverExpiresExpirationPolicy(),
            false,
            true);
    CachedData result = transcoder.encode(expectedTGT);
    final TicketGrantingTicket resultTicket = (TicketGrantingTicket) transcoder.decode(result);

    assertEquals(expectedTGT, resultTicket);
    result = transcoder.encode(ticket);
    final ServiceTicket resultStTicket = (ServiceTicket) transcoder.decode(result);
    assertEquals(ticket, resultStTicket);
  }
Example #3
0
 @Test
 public void verifyEncodeDecodeTGTWithListOrderedMap() throws Exception {
   final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
   @SuppressWarnings("unchecked")
   final TicketGrantingTicket expectedTGT =
       new MockTicketGrantingTicket(TGT_ID, userPassCredential, this.principalAttributes);
   expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
   assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
 }
Example #4
0
 @Test
 public void verifyEncodeDecodeTGTWithUnmodifiableMap() throws Exception {
   final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
   final TicketGrantingTicket expectedTGT =
       new MockTicketGrantingTicket(
           TGT_ID, userPassCredential, Collections.unmodifiableMap(this.principalAttributes));
   expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
   assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
 }
Example #5
0
 private void internalProxyTest(final String proxyUrl) throws MalformedURLException {
   final Credential proxyCredential =
       new HttpBasedServiceCredential(
           new URL(proxyUrl), TestUtils.getRegisteredService("https://.+"));
   final TicketGrantingTicket expectedTGT =
       new MockTicketGrantingTicket(TGT_ID, proxyCredential, this.principalAttributes);
   expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
   assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
 }
Example #6
0
 @Test
 public void verifyEncodeDecodeTGTWithSingletonMap() throws Exception {
   final Map<String, Object> newAttributes =
       Collections.singletonMap(NICKNAME_KEY, (Object) NICKNAME_VALUE);
   final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
   final TicketGrantingTicket expectedTGT =
       new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
   expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
   assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
 }
Example #7
0
 @Test
 public void verifyEncodeDecodeTGTWithUnmodifiableSet() throws Exception {
   final Map<String, Object> newAttributes = new HashMap<>();
   final Set<String> values = new HashSet<>();
   values.add(NICKNAME_VALUE);
   newAttributes.put(NICKNAME_KEY, Collections.unmodifiableSet(values));
   final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
   final TicketGrantingTicket expectedTGT =
       new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
   expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
   assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
 }
Example #8
0
 @Test
 public void verifyEncodeDecodeRegisteredService() throws Exception {
   final RegisteredService service = TestUtils.getRegisteredService("helloworld");
   assertEquals(service, transcoder.decode(transcoder.encode(service)));
 }