Java Code Examples for org.jasig.cas.TestUtils#getAuthentication()

The following examples show how to use org.jasig.cas.TestUtils#getAuthentication() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheCredentialsMetaDataPopulatorTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyAttributePopulationWithPasswordWithDifferentCredentialsType() {
    final Authentication auth = TestUtils.getAuthentication();
    final Map<String, String> map = new HashMap<>();
    final CacheCredentialsMetaDataPopulator populator = new CacheCredentialsMetaDataPopulator(map);

    final Credential c = new Credential() {
        @Override
        public String getId() {
            return "something";
        }
    };

    if (populator.supports(c)) {
        populator.populateAttributes(DefaultAuthenticationBuilder.newInstance(auth), c);
    }

    assertEquals(map.size(), 0);

}
 
Example 2
Source File: ServiceTicketImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test
public void testTicketGrantingTicketGrantedTwice() {
    Authentication a = TestUtils.getAuthentication();
    TicketGrantingTicket t = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    ServiceTicket s = t.grantServiceTicket(this.uniqueTicketIdGenerator.getNewTicketId(ServiceTicket.PREFIX),
            TestUtils.getService(), new MultiTimeUseOrTimeoutExpirationPolicy(1, 5000), false);
    s.grantTicketGrantingTicket(this.uniqueTicketIdGenerator.getNewTicketId(TicketGrantingTicket.PREFIX), a,
            new NeverExpiresExpirationPolicy());

    try {
        s.grantTicketGrantingTicket(this.uniqueTicketIdGenerator.getNewTicketId(TicketGrantingTicket.PREFIX), a,
                new NeverExpiresExpirationPolicy());
        fail("Exception expected.");
    } catch (final Exception e) {
        return;
    }
}
 
Example 3
Source File: DistributedTicketRegistryTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateOfRegistry() {
    final TicketGrantingTicket t = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    this.ticketRegistry.addTicket(t);
    final TicketGrantingTicket returned = (TicketGrantingTicket) this.ticketRegistry.getTicket("test");

    final ServiceTicket s = returned.grantServiceTicket("test2", TestUtils.getService(),
            new NeverExpiresExpirationPolicy(), true);

    this.ticketRegistry.addTicket(s);
    final ServiceTicket s2 = (ServiceTicket) this.ticketRegistry.getTicket("test2");
    assertNotNull(s2.grantTicketGrantingTicket("ff", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy()));

    assertTrue(s2.isValidFor(TestUtils.getService()));
    assertTrue(this.wasTicketUpdated);

    returned.markTicketExpired();
    assertTrue(t.isExpired());
}
 
Example 4
Source File: TimeoutExpirationPolicyTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.expirationPolicy = new TimeoutExpirationPolicy(TIMEOUT);

    this.ticket = new TicketGrantingTicketImpl("test", TestUtils
        .getAuthentication(), this.expirationPolicy);

}
 
Example 5
Source File: TicketGrantingTicketImplTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyIsRootFalse() {
    final TicketGrantingTicketImpl t1 = new TicketGrantingTicketImpl("test", null, null,
        TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
    final TicketGrantingTicket t = new TicketGrantingTicketImpl("test",
            new SimpleWebApplicationServiceImpl("gantor"), t1,
        TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());

    assertFalse(t.isRoot());
}
 
Example 6
Source File: AbstractTicketRegistryTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@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, TestUtils.getService(),
                new NeverExpiresExpirationPolicy(), false);
        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());

        for (final Ticket ticket : tickets) {
            if (!ticketRegistryTickets.contains(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.");
    }
}
 
Example 7
Source File: ImmutableAssertionTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyGetterFalseForNewLogin() {
    final List<Authentication> list = new ArrayList<>();

    list.add(TestUtils.getAuthentication());

    final ImmutableAssertion assertion = new ImmutableAssertion(
            TestUtils.getAuthentication(), list, TestUtils.getService(), false);

    assertFalse(assertion.isFromNewLogin());
}
 
Example 8
Source File: ImmutableAssertionTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyEqualsWithValidObject() {
    final List<Authentication> list1 = new ArrayList<>();
    final List<Authentication> list2 = new ArrayList<>();

    final Authentication auth = TestUtils.getAuthentication();
    list1.add(auth);
    list2.add(auth);

    final ImmutableAssertion assertion1 = new ImmutableAssertion(auth, list1, TestUtils.getService(), true);
    final ImmutableAssertion assertion2 = new ImmutableAssertion(auth, list2, TestUtils.getService(), true);

    assertTrue(assertion1.equals(assertion2));
}
 
Example 9
Source File: MultiTimeUseOrTimeoutExpirationPolicyTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.expirationPolicy = new MultiTimeUseOrTimeoutExpirationPolicy(NUMBER_OF_USES, TIMEOUT_MILLISECONDS,
            TimeUnit.MILLISECONDS);

    this.ticket = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(), this.expirationPolicy);

}
 
Example 10
Source File: ProxyControllerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotAuthorizedPGT() throws Exception {
    final TicketGrantingTicket ticket = new TicketGrantingTicketImpl("ticketGrantingTicketId", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    getTicketRegistry().addTicket(ticket);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("pgt", ticket.getId());
    request.addParameter("targetService", "service");

    final Map<String, Object> map = this.proxyController.handleRequestInternal(request,  new MockHttpServletResponse()).getModel();
    assertTrue(!map.containsKey("ticket"));
}
 
Example 11
Source File: Saml10SuccessResponseViewTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testResponseWithNoAttributes() throws Exception {
    final Map<String, Object> model = new HashMap<String, Object>();

    final SimplePrincipal principal = new SimplePrincipal("testPrincipal");

    final Map<String, Object> authAttributes = new HashMap<String, Object>();
    authAttributes.put(
            SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD,
            SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT);
    authAttributes.put("testSamlAttribute", "value");

    final Authentication primary = TestUtils.getAuthentication(principal, authAttributes);

    final Assertion assertion = new ImmutableAssertion(
            primary, Collections.singletonList(primary), TestUtils.getService(), true);
    model.put("assertion", assertion);

    final MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
    final String written = servletResponse.getContentAsString();

    assertTrue(written.contains("testPrincipal"));
    assertTrue(written.contains(SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT));
    assertTrue(written.contains("AuthenticationMethod"));
}
 
Example 12
Source File: DistributedTicketRegistryTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testProxiedInstancesEqual() {
    final TicketGrantingTicket t = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    this.ticketRegistry.addTicket(t);

    final TicketGrantingTicket returned = (TicketGrantingTicket) this.ticketRegistry.getTicket("test");
    assertEquals(t, returned);
    assertEquals(returned, t);

    assertEquals(t.getCreationTime(), returned.getCreationTime());
    assertEquals(t.getAuthentication(), returned.getAuthentication());
    assertEquals(t.getCountOfUses(), returned.getCountOfUses());
    assertEquals(t.getGrantingTicket(), returned.getGrantingTicket());
    assertEquals(t.getId(), returned.getId());
    assertEquals(t.getChainedAuthentications(), returned.getChainedAuthentications());
    assertEquals(t.isExpired(), returned.isExpired());
    assertEquals(t.isRoot(), returned.isRoot());

    final ServiceTicket s = t.grantServiceTicket("stest", TestUtils.getService(),
            new NeverExpiresExpirationPolicy(), false);
    this.ticketRegistry.addTicket(s);

    final ServiceTicket sreturned = (ServiceTicket) this.ticketRegistry.getTicket("stest");
    assertEquals(s, sreturned);
    assertEquals(sreturned, s);

    assertEquals(s.getCreationTime(), sreturned.getCreationTime());
    assertEquals(s.getCountOfUses(), sreturned.getCountOfUses());
    assertEquals(s.getGrantingTicket(), sreturned.getGrantingTicket());
    assertEquals(s.getId(), sreturned.getId());
    assertEquals(s.isExpired(), sreturned.isExpired());
    assertEquals(s.getService(), sreturned.getService());
    assertEquals(s.isFromNewLogin(), sreturned.isFromNewLogin());
}
 
Example 13
Source File: TicketGrantingTicketImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsRootFalse() {
    TicketGrantingTicketImpl t1 = new TicketGrantingTicketImpl("test", null,
        TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
    TicketGrantingTicket t = new TicketGrantingTicketImpl("test", t1,
        TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());

    assertFalse(t.isRoot());
}
 
Example 14
Source File: Saml10SuccessResponseViewTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testResponse() throws Exception {
    final Map<String, Object> model = new HashMap<String, Object>();

    final Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("testAttribute", "testValue");
    attributes.put("testEmptyCollection", Collections.emptyList());
    attributes.put("testAttributeCollection", Arrays.asList(new String[] {"tac1", "tac2"}));
    final SimplePrincipal principal = new SimplePrincipal("testPrincipal", attributes);

    final Map<String, Object> authAttributes = new HashMap<String, Object>();
    authAttributes.put(
            SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD,
            SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT);
    authAttributes.put("testSamlAttribute", "value");

    final Authentication primary = TestUtils.getAuthentication(principal, authAttributes);
    final Assertion assertion = new ImmutableAssertion(
            primary, Collections.singletonList(primary), TestUtils.getService(), true);
    model.put("assertion", assertion);

    final MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
    final String written = servletResponse.getContentAsString();

    assertTrue(written.contains("testPrincipal"));
    assertTrue(written.contains("testAttribute"));
    assertTrue(written.contains("testValue"));
    assertFalse(written.contains("testEmptyCollection"));
    assertTrue(written.contains("testAttributeCollection"));
    assertTrue(written.contains("tac1"));
    assertTrue(written.contains("tac2"));
    assertTrue(written.contains(SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT));
    assertTrue(written.contains("AuthenticationMethod"));
    assertTrue(written.contains("AssertionID"));
}
 
Example 15
Source File: ImmutableAssertionTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetterFalseForNewLogin() {
    final List<Authentication> list = new ArrayList<Authentication>();

    list.add(TestUtils.getAuthentication());

    final ImmutableAssertion assertion = new ImmutableAssertion(
            TestUtils.getAuthentication(), list, TestUtils.getService(), false);

    assertFalse(assertion.isFromNewLogin());
}
 
Example 16
Source File: ServiceTicketImplTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyIsExpiredTrueBecauseOfRoot() {
    final TicketGrantingTicket t = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    final ServiceTicket s = t.grantServiceTicket(this.uniqueTicketIdGenerator.getNewTicketId(ServiceTicket.PREFIX),
            TestUtils.getService(), new NeverExpiresExpirationPolicy(), false);
    t.markTicketExpired();

    assertTrue(s.isExpired());
}
 
Example 17
Source File: JpaTicketRegistryTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
static TicketGrantingTicket newTGT() {
    final Principal principal = new SimplePrincipal(
            "bob", Collections.singletonMap("displayName", (Object) "Bob"));
    return new TicketGrantingTicketImpl(
            ID_GENERATOR.getNewTicketId("TGT"),
            TestUtils.getAuthentication(principal),
            EXP_POLICY_TGT);
}
 
Example 18
Source File: ImmutableAssertionTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyEqualsWithNull() {
    final List<Authentication> list = new ArrayList<>();
    list.add(TestUtils.getAuthentication());

    final ImmutableAssertion assertion = new ImmutableAssertion(
            TestUtils.getAuthentication(), list, TestUtils.getService(), true);

    assertNotEquals(assertion, null);
}
 
Example 19
Source File: AbstractRegistryCleanerTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
protected void populateRegistryWithExpiredTickets() {
    for (int i = 0; i < 10; i++) {
        final TicketGrantingTicket ticket = new TicketGrantingTicketImpl("test" + i, TestUtils.getAuthentication(),
                new NeverExpiresExpirationPolicy());
        ticket.markTicketExpired();
        this.ticketRegistry.addTicket(ticket);
    }
}
 
Example 20
Source File: ServiceTicketImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testTicketGrantingTicket() {
    Authentication a = TestUtils.getAuthentication();
    TicketGrantingTicket t = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    ServiceTicket s = t.grantServiceTicket(this.uniqueTicketIdGenerator.getNewTicketId(ServiceTicket.PREFIX),
            TestUtils.getService(), new MultiTimeUseOrTimeoutExpirationPolicy(1, 5000), false);
    TicketGrantingTicket t1 = s.grantTicketGrantingTicket(
            this.uniqueTicketIdGenerator.getNewTicketId(TicketGrantingTicket.PREFIX), a,
            new NeverExpiresExpirationPolicy());

    assertEquals(a, t1.getAuthentication());
}