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

The following examples show how to use org.jasig.cas.TestUtils#getService() . 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: ServiceTicketImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTicket() {
    Service simpleService = TestUtils.getService();
    ServiceTicket s = new ServiceTicketImpl("stest1", this.ticketGrantingTicket, simpleService, false,
            new NeverExpiresExpirationPolicy());
    assertEquals(this.ticketGrantingTicket, s.getGrantingTicket());
}
 
Example 2
Source File: ServiceTicketImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetService() {
    Service simpleService = TestUtils.getService();
    ServiceTicket s = new ServiceTicketImpl("stest1", this.ticketGrantingTicket, simpleService, false,
            new NeverExpiresExpirationPolicy());
    assertEquals(simpleService, s.getService());
}
 
Example 3
Source File: KryoTranscoderTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@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 Date());
    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, TestUtils.getService(), null, bldr.build(),
                    new NeverExpiresExpirationPolicy());

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

    final ServiceTicket ticket = expectedTGT.grantServiceTicket(ST_ID,
            TestUtils.getService(),
            new NeverExpiresExpirationPolicy(), false);
    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 4
Source File: ImmutableAssertionTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualsWithNull() {
    final List<Authentication> list = new ArrayList<Authentication>();
    list.add(TestUtils.getAuthentication());

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

    assertFalse(assertion.equals(null));
}
 
Example 5
Source File: DefaultCasAttributeEncoderTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void checkAttributesEncodedCorrectly() {
    final Service service = TestUtils.getService("testencryption");
    final CasAttributeEncoder encoder = new DefaultCasAttributeEncoder(this.servicesManager);
    final Map<String, Object> encoded = encoder.encodeAttributes(this.attributes, service);
    assertEquals(encoded.size(), this.attributes.size());
    checkEncryptedValues(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL_CREDENTIAL, encoded);
    checkEncryptedValues(CasViewConstants.MODEL_ATTRIBUTE_NAME_PROXY_GRANTING_TICKET, encoded);
}
 
Example 6
Source File: DefaultCasAttributeEncoderTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void checkNoPublicKeyDefined() {
    final Service service = TestUtils.getService("testDefault");
    final CasAttributeEncoder encoder = new DefaultCasAttributeEncoder(this.servicesManager);
    final Map<String, Object> encoded = encoder.encodeAttributes(this.attributes, service);
    assertEquals(encoded.size(), this.attributes.size() - 2);
}
 
Example 7
Source File: ImmutableAssertionTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyGetService() {
    final Service service = TestUtils.getService();

    final List<Authentication> list = new ArrayList<>();
    list.add(TestUtils.getAuthentication());

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

    assertEquals(service, assertion.getService());
}
 
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: 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 10
Source File: Saml10SuccessResponseViewTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyResponse() throws Exception {
    final Map<String, Object> model = new HashMap<>();

    final Map<String, Object> attributes = new HashMap<>();
    attributes.put("testAttribute", "testValue");
    attributes.put("testEmptyCollection", Collections.emptyList());
    attributes.put("testAttributeCollection", Arrays.asList("tac1", "tac2"));
    final Principal principal = new DefaultPrincipalFactory().createPrincipal("testPrincipal", attributes);

    final Map<String, Object> authAttributes = new HashMap<>();
    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 11
Source File: ImmutableAssertionTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyGettersForChainedPrincipals() {
    final List<Authentication> list = new ArrayList<>();

    list.add(TestUtils.getAuthentication("test"));
    list.add(TestUtils.getAuthentication("test1"));
    list.add(TestUtils.getAuthentication("test2"));

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

    assertEquals(list.toArray(new Authentication[0]).length, assertion.getChainedAuthentications().size());
}
 
Example 12
Source File: ServiceTicketImplTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyGetTicket() {
    final Service simpleService = TestUtils.getService();
    final ServiceTicket s = new ServiceTicketImpl("stest1", this.ticketGrantingTicket, simpleService, false,
            new NeverExpiresExpirationPolicy());
    assertEquals(this.ticketGrantingTicket, s.getGrantingTicket());
}
 
Example 13
Source File: ImmutableAssertionTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testGettersForChainedPrincipals() {
    final List<Authentication> list = new ArrayList<Authentication>();

    list.add(TestUtils.getAuthentication("test"));
    list.add(TestUtils.getAuthentication("test1"));
    list.add(TestUtils.getAuthentication("test2"));

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

    assertEquals(list.toArray(new Authentication[0]).length, assertion.getChainedAuthentications().size());
}
 
Example 14
Source File: Saml10SuccessResponseViewTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyResponseWithoutAuthMethod() throws Exception {
    final Map<String, Object> model = new HashMap<>();

    final Map<String, Object> attributes = new HashMap<>();
    attributes.put("testAttribute", "testValue");
    final Principal principal = new DefaultPrincipalFactory().createPrincipal("testPrincipal", attributes);

    final Map<String, Object> authnAttributes = new HashMap<>();
    authnAttributes.put("authnAttribute1", "authnAttrbuteV1");
    authnAttributes.put("authnAttribute2", "authnAttrbuteV2");
    authnAttributes.put(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME, Boolean.TRUE);

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

    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"));
    assertTrue(written.contains("authnAttribute1"));
    assertTrue(written.contains("authnAttribute2"));
    assertTrue(written.contains(CasProtocolConstants.VALIDATION_REMEMBER_ME_ATTRIBUTE_NAME));
    assertTrue(written.contains("urn:oasis:names:tc:SAML:1.0:am:unspecified"));
}
 
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 testGetService() {
    final Service service = TestUtils.getService();

    final List<Authentication> list = new ArrayList<Authentication>();
    list.add(TestUtils.getAuthentication());

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

    assertEquals(service, assertion.getService());
}
 
Example 16
Source File: ServiceTicketImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
@Test
public void testIsFromNewLoginTrue() {
    ServiceTicket s = new ServiceTicketImpl("stest1", this.ticketGrantingTicket, TestUtils.getService(), true,
            new NeverExpiresExpirationPolicy());
    assertTrue(s.isFromNewLogin());
}
 
Example 17
Source File: ServiceTicketImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
@Test(expected = Exception.class)
public void testNoTicket() {
    new ServiceTicketImpl("stest1", null, TestUtils.getService(), true, new NeverExpiresExpirationPolicy());
}
 
Example 18
Source File: ServiceTicketImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
@Test
public void testIsFromNewLoginFalse() {
    ServiceTicket s = new ServiceTicketImpl("stest1", this.ticketGrantingTicket, TestUtils.getService(), false,
            new NeverExpiresExpirationPolicy());
    assertFalse(s.isFromNewLogin());
}
 
Example 19
Source File: ServiceTicketImplTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Test
public void verifyIsFromNewLoginTrue() {
    final ServiceTicket s = new ServiceTicketImpl("stest1", this.ticketGrantingTicket, TestUtils.getService(), true,
            new NeverExpiresExpirationPolicy());
    assertTrue(s.isFromNewLogin());
}
 
Example 20
Source File: ServiceTicketImplTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Test(expected = Exception.class)
public void verifyNoTicket() {
    new ServiceTicketImpl("stest1", null, TestUtils.getService(), true, new NeverExpiresExpirationPolicy());
}