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

The following examples show how to use org.jasig.cas.TestUtils#getRegisteredService() . 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: DefaultRegisteredServiceMfaRoleProcessorImplTest.java    From cas-mfa with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveServiceWithOnlyAuthnMethodAttribute() throws Exception {
    final WebApplicationService was = getTargetService();
    final Authentication auth = getAuthentication(true);

    final RegisteredService rswa = TestUtils.getRegisteredService("test1");

    final DefaultRegisteredServiceProperty prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(CAS_AUTHN_METHOD));
    rswa.getProperties().put(MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD, prop);

    final DefaultRegisteredServiceMfaRoleProcessorImpl resolver = new DefaultRegisteredServiceMfaRoleProcessorImpl(
            getMFWASF(was), getAMCP(), getServicesManager(rswa));

    final List<MultiFactorAuthenticationRequestContext> result = resolver.resolve(auth, was);
    assertNotNull(result);
    assertEquals(0, result.size());
}
 
Example 2
Source File: DefaultRegisteredServiceMfaRoleProcessorImplTest.java    From cas-mfa with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveWithoutIncompleteServiceMfaAttributes() throws Exception {
    final WebApplicationService was = getTargetService();
    final Authentication auth = getAuthentication(true);

    final RegisteredService rswa = TestUtils.getRegisteredService("test1");

    DefaultRegisteredServiceProperty prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(CAS_AUTHN_METHOD));
    rswa.getProperties().put(MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD, prop);

    prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(MEMBER_OF_VALUE));
    rswa.getProperties().put(RegisteredServiceMfaRoleProcessor.MFA_ATTRIBUTE_PATTERN, prop);

    final DefaultRegisteredServiceMfaRoleProcessorImpl resolver = new DefaultRegisteredServiceMfaRoleProcessorImpl(
            getMFWASF(was), getAMCP(), getServicesManager(rswa));

    final List<MultiFactorAuthenticationRequestContext> result = resolver.resolve(auth, was);
    assertNotNull(result);
    assertEquals(0, result.size());
}
 
Example 3
Source File: RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractorTests.java    From cas-mfa with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceWithNoAttributeValue() {
    final List<ArgumentExtractor> set = new ArrayList<>();
    set.add(new CasArgumentExtractor());
    
    final MultiFactorWebApplicationServiceFactory factory = mock(MultiFactorWebApplicationServiceFactory.class);
    final AuthenticationMethodVerifier verifier = mock(AuthenticationMethodVerifier.class);

    final RegisteredService svc = TestUtils.getRegisteredService(CAS_SERVICE);
    final DefaultRegisteredServiceProperty prop = new DefaultRegisteredServiceProperty();
    svc.getProperties().put(MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD, prop);
    
    final ServicesManager mgmr = mock(ServicesManager.class);
    when(mgmr.findServiceBy(anyInt())).thenReturn(svc);
    when(mgmr.findServiceBy(any(Service.class))).thenReturn(svc);
    
    final RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor extractor = 
            new RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor(set, factory, mgmr, verifier);
    
    final MultiFactorAuthenticationSupportingWebApplicationService webSvc =
            (MultiFactorAuthenticationSupportingWebApplicationService) extractor.extractService(getRequest());
    assertNull(webSvc);
}
 
Example 4
Source File: InMemoryServiceRegistryDaoImplTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifySaveAndDelete()  {
    final InMemoryServiceRegistryDaoImpl reg = new InMemoryServiceRegistryDaoImpl();
    final RegisteredService svc = TestUtils.getRegisteredService("service");
    assertEquals(reg.save(svc), svc);
    assertTrue(reg.delete(svc));
    assertEquals(reg.load().size(), 0);
}
 
Example 5
Source File: DefaultRegisteredServiceMfaRoleProcessorImplTest.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveServiceWithMfaAttributesUserInRole() throws Exception {
    final WebApplicationService was = getTargetService();
    final Authentication auth = getAuthentication(true);


    final RegisteredService rswa = TestUtils.getRegisteredService("test1");

    DefaultRegisteredServiceProperty prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(CAS_AUTHN_METHOD));
    rswa.getProperties().put(MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD, prop);

    prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(MEMBER_OF));
    rswa.getProperties().put(RegisteredServiceMfaRoleProcessor.MFA_ATTRIBUTE_NAME, prop);

    prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(MEMBER_OF_VALUE));
    rswa.getProperties().put(RegisteredServiceMfaRoleProcessor.MFA_ATTRIBUTE_PATTERN, prop);

    final DefaultRegisteredServiceMfaRoleProcessorImpl resolver = new DefaultRegisteredServiceMfaRoleProcessorImpl(
            getMFWASF(was), getAMCP(), getServicesManager(rswa));

    final List<MultiFactorAuthenticationRequestContext> result = resolver.resolve(auth, was);
    assertNotNull(result);
    assertEquals(CAS_AUTHN_METHOD, result.get(0).getMfaService().getAuthenticationMethod());
}
 
Example 6
Source File: DefaultRegisteredServiceMfaRoleProcessorImplTest.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveWithoutAnyServiceMfaAttributes() throws Exception {
    final WebApplicationService was = getTargetService();
    final Authentication auth = getAuthentication(true);

    final RegisteredService rswa = TestUtils.getRegisteredService("test1");
    final DefaultRegisteredServiceMfaRoleProcessorImpl resolver = new DefaultRegisteredServiceMfaRoleProcessorImpl(
        getMFWASF(was), getAMCP(), getServicesManager(rswa));

    final List<MultiFactorAuthenticationRequestContext> result = resolver.resolve(auth, was);
    assertNotNull(result);
    assertEquals(0, result.size());
}
 
Example 7
Source File: RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractorTests.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceWithMfaRole() {
    final List<ArgumentExtractor> set = new ArrayList<>();
    set.add(new CasArgumentExtractor());

    final MultiFactorWebApplicationServiceFactory factory = mock(MultiFactorWebApplicationServiceFactory.class);
    when(factory.create(anyString(), anyString(), anyString(), any(Response.ResponseType.class),
            anyString(), any(AuthenticationMethodSource.class)))
            .thenReturn(getMfaService());

    final AuthenticationMethodVerifier verifier = mock(AuthenticationMethodVerifier.class);

    final RegisteredService svc = TestUtils.getRegisteredService(CAS_SERVICE);
    DefaultRegisteredServiceProperty prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(CAS_AUTHN_METHOD));
    svc.getProperties().put(MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD, prop);

    prop = new DefaultRegisteredServiceProperty();
    svc.getProperties().put(RegisteredServiceMfaRoleProcessor.MFA_ATTRIBUTE_NAME, prop);

    prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(CAS_AUTHN_METHOD));
    svc.getProperties().put(RegisteredServiceMfaRoleProcessor.MFA_ATTRIBUTE_PATTERN, prop);

    final ServicesManager mgmr = mock(ServicesManager.class);
    when(mgmr.findServiceBy(anyInt())).thenReturn(svc);
    when(mgmr.findServiceBy(any(Service.class))).thenReturn(svc);

    final RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor extractor =
            new RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor(set, factory, mgmr, verifier);

    final MultiFactorAuthenticationSupportingWebApplicationService webSvc =
            (MultiFactorAuthenticationSupportingWebApplicationService) extractor.extractService(getRequest());
    assertNull(webSvc);
}
 
Example 8
Source File: RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractorTests.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceWithDefaultMfaAttribute() {
    final List<ArgumentExtractor> set = new ArrayList<>();
    set.add(new CasArgumentExtractor());
    
    final MultiFactorWebApplicationServiceFactory factory = mock(MultiFactorWebApplicationServiceFactory.class);
    when(factory.create(anyString(), anyString(), anyString(), any(Response.ResponseType.class),
            anyString(), any(AuthenticationMethodSource.class)))
        .thenReturn(getMfaService());
    
    final AuthenticationMethodVerifier verifier = mock(AuthenticationMethodVerifier.class);

    final RegisteredService svc = TestUtils.getRegisteredService(CAS_SERVICE);
    final DefaultRegisteredServiceProperty prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(CAS_AUTHN_METHOD));
    svc.getProperties().put(MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD, prop);
    
    final ServicesManager mgmr = mock(ServicesManager.class);
    when(mgmr.findServiceBy(anyInt())).thenReturn(svc);
    when(mgmr.findServiceBy(any(Service.class))).thenReturn(svc);
    
    final RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor extractor = 
            new RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor(set, factory, mgmr, verifier);

    final MultiFactorAuthenticationSupportingWebApplicationService webSvc =
            (MultiFactorAuthenticationSupportingWebApplicationService) extractor.extractService(getRequest());
    assertNotNull(webSvc);
    assertEquals(webSvc.getAuthenticationMethod(), CAS_AUTHN_METHOD);
}
 
Example 9
Source File: HttpBasedServiceCredentialTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyEqualsWithNull() throws Exception {
    final HttpBasedServiceCredential c = new HttpBasedServiceCredential(new URL("http://www.cnn.com"),
            TestUtils.getRegisteredService("https://some.app.edu"));

    assertNotEquals(c, null);
}
 
Example 10
Source File: InMemoryServiceRegistryDaoImplTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifySaveAndFind()  {
    final InMemoryServiceRegistryDaoImpl reg = new InMemoryServiceRegistryDaoImpl();
    final RegisteredService svc = TestUtils.getRegisteredService("service");
    assertEquals(reg.save(svc), svc);
    assertEquals(reg.findServiceById(svc.getId()), svc);
}
 
Example 11
Source File: InMemoryServiceRegistryDaoImplTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
 public void verifySaveAndLoad()  {
    final InMemoryServiceRegistryDaoImpl reg = new InMemoryServiceRegistryDaoImpl();
    final RegisteredService svc = TestUtils.getRegisteredService("service");
    assertEquals(reg.save(svc), svc);
    assertEquals(reg.load().size(), 1);
}
 
Example 12
Source File: HttpBasedServiceCredentialTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyEqualsWithTrue() throws Exception {
    final HttpBasedServiceCredential c = new HttpBasedServiceCredential(new URL("http://www.cnn.com"),
            TestUtils.getRegisteredService("https://some.app.edu"));
    final HttpBasedServiceCredential c2 = new HttpBasedServiceCredential(new URL("http://www.cnn.com"),
            TestUtils.getRegisteredService("https://some.app.edu"));

    assertTrue(c.equals(c2));
    assertTrue(c2.equals(c));
}
 
Example 13
Source File: HttpBasedServiceCredentialTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyEqualsWithFalse() throws Exception {
    final HttpBasedServiceCredential c = new HttpBasedServiceCredential(new URL("http://www.cnn.com"),
            TestUtils.getRegisteredService("https://some.app.edu"));
    final HttpBasedServiceCredential c2 = new HttpBasedServiceCredential(new URL("http://www.msn.com"),
            TestUtils.getRegisteredService("https://some.app.edu"));

    assertFalse(c.equals(c2));
    assertFalse(c.equals(new Object()));
}
 
Example 14
Source File: MongoServiceRegistryDaoTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
private RegisteredService buildService(final int i) {
    return TestUtils.getRegisteredService("^http://www.serviceid" + i + ".org");
}
 
Example 15
Source File: InMemoryServiceRegistryDaoImplTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Test
public void verifySave()  {
    final InMemoryServiceRegistryDaoImpl reg = new InMemoryServiceRegistryDaoImpl();
    final RegisteredService svc = TestUtils.getRegisteredService("service");
    assertEquals(reg.save(svc), svc);
}
 
Example 16
Source File: AbstractRegisteredServiceTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Test
public void verifyServiceCopy() throws Exception {
    final RegisteredService svc1 = TestUtils.getRegisteredService(SERVICEID);
    final RegisteredService svc2 = svc1.clone();
    assertEquals(svc1, svc2);
}
 
Example 17
Source File: AbstractRegisteredServiceTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Test
public void verifyServiceEquality() {
    final RegisteredService svc1 = TestUtils.getRegisteredService(SERVICEID);
    final RegisteredService svc2 = TestUtils.getRegisteredService(SERVICEID);
    assertEquals(svc1, svc2);
}