Java源码示例:org.jasig.cas.web.support.CasArgumentExtractor

示例1
@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);
}
 
示例2
@Test
public void testServiceWithDifferentServiceType() {
    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 = mock(RegisteredService.class);
    when(svc.getId()).thenReturn(0L);
    when(svc.getServiceId()).thenReturn(CAS_SERVICE);
    
    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);
}
 
示例3
@Test
public void verifyFindService() {
    final SamlArgumentExtractor openIdArgumentExtractor = new SamlArgumentExtractor();
    final CasArgumentExtractor casArgumentExtractor = new CasArgumentExtractor();
    final ArgumentExtractor[] argumentExtractors = new ArgumentExtractor[] {
            openIdArgumentExtractor, casArgumentExtractor};
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "test");

    final Service service = WebUtils.getService(Arrays
            .asList(argumentExtractors), request);

    assertEquals("test", service.getId());
}
 
示例4
@Before
public void onSetUp() throws Exception {
    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.serviceValidateController = new ServiceValidateController();
    this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService());
    final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler();
    proxyHandler.setHttpClient(new SimpleHttpClientFactoryBean().getObject());
    this.serviceValidateController.setProxyHandler(proxyHandler);
    this.serviceValidateController.setApplicationContext(context);
    this.serviceValidateController.setArgumentExtractor(new CasArgumentExtractor());
    this.serviceValidateController.setServicesManager(this.servicesManager);
}
 
示例5
@Before
public void setUp() throws Exception {
    this.warnCookieGenerator = new CookieRetrievingCookieGenerator();
    this.tgtCookieGenerator = new CookieRetrievingCookieGenerator();
    this.action.setTicketGrantingTicketCookieGenerator(this.tgtCookieGenerator);
    this.action.setWarnCookieGenerator(this.warnCookieGenerator);
    final ArgumentExtractor[] argExtractors = new ArgumentExtractor[] {new CasArgumentExtractor()};
    this.action.setArgumentExtractors(Arrays.asList(argExtractors));

    this.servicesManager = mock(ServicesManager.class);
    when(this.servicesManager.findServiceBy(any(Service.class))).thenReturn(TestUtils.getRegisteredService("test"));
    this.action.setServicesManager(this.servicesManager);

    this.action.afterPropertiesSet();
}
 
示例6
@Test
public void testFindService() {
    final SamlArgumentExtractor openIdArgumentExtractor = new SamlArgumentExtractor();
    final CasArgumentExtractor casArgumentExtractor = new CasArgumentExtractor();
    final ArgumentExtractor[] argumentExtractors = new ArgumentExtractor[] {
            openIdArgumentExtractor, casArgumentExtractor};
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "test");

    final Service service = WebUtils.getService(Arrays
            .asList(argumentExtractors), request);

    assertEquals("test", service.getId());
}
 
示例7
@Before
public void setUp() throws Exception {
    this.warnCookieGenerator = new CookieRetrievingCookieGenerator();
    this.warnCookieGenerator.setCookiePath("");
    this.tgtCookieGenerator = new CookieRetrievingCookieGenerator();
    this.tgtCookieGenerator.setCookiePath("");
    this.action.setTicketGrantingTicketCookieGenerator(this.tgtCookieGenerator);
    this.action.setWarnCookieGenerator(this.warnCookieGenerator);
    final ArgumentExtractor[] argExtractors = new ArgumentExtractor[] {new CasArgumentExtractor()};
    this.action.setArgumentExtractors(Arrays.asList(argExtractors));
    this.action.afterPropertiesSet();
    this.action.afterPropertiesSet();
}
 
示例8
@Before
public void onSetUp() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.serviceValidateController = new ServiceValidateController();
    this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService());
    final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler();
    proxyHandler.setHttpClient(new SimpleHttpClient());
    this.serviceValidateController.setProxyHandler(proxyHandler);
    this.serviceValidateController.setApplicationContext(context);
    this.serviceValidateController.setArgumentExtractor(new CasArgumentExtractor());
}
 
示例9
@Before
public void setUp() throws Exception {
    this.servicesManager = new DefaultServicesManagerImpl(new InMemoryServiceRegistryDaoImpl());

    this.serviceThemeResolver = new ServiceThemeResolver();
    this.serviceThemeResolver.setDefaultThemeName("test");
    this.serviceThemeResolver.setServicesManager(this.servicesManager);
    this.serviceThemeResolver.setArgumentExtractors(Arrays.asList((ArgumentExtractor) new CasArgumentExtractor()));
    final Map<String, String> mobileBrowsers = new HashMap<String, String>();
    mobileBrowsers.put("Mozilla", "theme");
    this.serviceThemeResolver.setMobileBrowsers(mobileBrowsers);
}
 
示例10
@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);
}
 
示例11
@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);
}
 
示例12
public RequestParameterMultiFactorAuthenticationArgumentExtractorTests() {
    this.supportedArgumentExtractors = new ArrayList<>();
    this.supportedArgumentExtractors.add(new CasArgumentExtractor());
    this.supportedArgumentExtractors.add(new SamlArgumentExtractor());
    this.mfaWebApplicationServiceFactory = new DefaultMultiFactorWebApplicationServiceFactory();
}