コード例 #1
0
  @Test
  public void verifySaveWithReturnedPersistedInstance() {
    final RegisteredServiceImpl r = new RegisteredServiceImpl();
    r.setId(1000L);
    r.setName("test");
    r.setServiceId("test");

    final RegisteredService persistedRs = this.defaultServicesManagerImpl.save(r);
    assertNotNull(persistedRs);
    assertEquals(1000L, persistedRs.getId());
  }
  @Test
  public void checkSaveMethodWithNonExistentServiceAndNoAttributes() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setName("testSaveMethodWithNonExistentServiceAndNoAttributes");
    r.setServiceId("testId");
    r.setTheme("theme");
    r.setDescription("description");

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());

    assertEquals(r, r2);
    assertEquals(r2, r3);
  }
  @Test
  public void verifyAccessStrategyWithEndpoint() throws Exception {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setServiceId("^https://.+");
    r.setName("verifyAccessStrategyWithEndpoint");
    r.setId(62);

    final RemoteEndpointServiceAccessStrategy authz = new RemoteEndpointServiceAccessStrategy();

    authz.setEndpointUrl("http://www.google.com?this=that");
    authz.setAcceptableResponseCodes("200,405,403");
    authz.setUnauthorizedRedirectUrl(new URI("https://www.github.com"));
    r.setAccessStrategy(authz);

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());
    assertEquals(r2, r3);
  }
  @Test
  public void checkForAuthorizationStrategy() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setServiceId("^https://.+");
    r.setName("checkForAuthorizationStrategy");
    r.setId(42);

    final DefaultRegisteredServiceAccessStrategy authz =
        new DefaultRegisteredServiceAccessStrategy(false, false);

    final Map<String, Set<String>> attrs = new HashMap<>();
    attrs.put("cn", Sets.newHashSet("v1, v2, v3"));
    attrs.put("memberOf", Sets.newHashSet(Lists.newArrayList("v4, v5, v6")));
    authz.setRequiredAttributes(attrs);
    r.setAccessStrategy(authz);

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());
    assertEquals(r2, r3);
  }
  @Test
  public void verifyAccessStrategyWithStarEndDate() throws Exception {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setServiceId("^https://.+");
    r.setName("verifyAAccessStrategyWithStarEndDate");
    r.setId(62);

    final TimeBasedRegisteredServiceAccessStrategy authz =
        new TimeBasedRegisteredServiceAccessStrategy(true, false);

    authz.setStartingDateTime(ZonedDateTime.now(ZoneOffset.UTC).plusDays(1).toString());
    authz.setEndingDateTime(ZonedDateTime.now(ZoneOffset.UTC).plusDays(10).toString());

    authz.setUnauthorizedRedirectUrl(new URI("https://www.github.com"));
    r.setAccessStrategy(authz);

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());
    assertEquals(r2, r3);
  }
 @Test
 public void verifySaveMethodWithDefaultAnonymousAttribute() {
   final RegexRegisteredService r = new RegexRegisteredService();
   r.setName("testSaveMethodWithDefaultAnonymousAttribute");
   r.setServiceId("testId");
   r.setTheme("theme");
   r.setDescription("description");
   r.setUsernameAttributeProvider(
       new AnonymousRegisteredServiceUsernameAttributeProvider(
           new ShibbolethCompatiblePersistentIdGenerator("helloworld")));
   final RegisteredService r2 = this.dao.save(r);
   this.dao.load();
   final RegisteredService r3 = this.dao.findServiceById(r2.getId());
   final AnonymousRegisteredServiceUsernameAttributeProvider anon =
       (AnonymousRegisteredServiceUsernameAttributeProvider) r3.getUsernameAttributeProvider();
   final ShibbolethCompatiblePersistentIdGenerator ss =
       (ShibbolethCompatiblePersistentIdGenerator) anon.getPersistentIdGenerator();
   assertEquals(new String(ss.getSalt()), "helloworld");
   assertEquals(r2, r3);
 }
  @Test
  public void verifySaveAttributeReleasePolicyAllowedAttrRulesAndFilter() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setName("testSaveAttributeReleasePolicyAllowedAttrRulesAndFilter");
    r.setServiceId("testId");
    r.setTheme("testtheme");
    r.setEvaluationOrder(1000);
    r.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(true, false));
    r.setProxyPolicy(new RegexMatchingRegisteredServiceProxyPolicy("https://.+"));
    r.setRequiredHandlers(new HashSet<>(Lists.newArrayList("h1", "h2")));

    final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
    policy.setAllowedAttributes(Lists.newArrayList("1", "2", "3"));
    r.setAttributeReleasePolicy(policy);
    r.getAttributeReleasePolicy()
        .setAttributeFilter(new RegisteredServiceRegexAttributeFilter("\\w+"));

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());

    assertEquals(r, r2);
    assertEquals(r2, r3);
    assertNotNull(r3.getAttributeReleasePolicy());
    assertEquals(r2.getAttributeReleasePolicy(), r3.getAttributeReleasePolicy());
  }
  @Test
  public void verifySaveAttributeReleasePolicy() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setName("testSaveAttributeReleasePolicy");
    r.setServiceId("testId");
    r.setTheme("theme");
    r.setDescription("description");
    r.setAttributeReleasePolicy(new ReturnAllAttributeReleasePolicy());

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());

    assertEquals(r, r2);
    assertEquals(r2, r3);
    assertNotNull(r3.getAttributeReleasePolicy());
    assertEquals(r2.getAttributeReleasePolicy(), r3.getAttributeReleasePolicy());
  }
  @Test
  public void verifySaveAttributeReleasePolicyAllowedAttrRules() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setName("testSaveAttributeReleasePolicyAllowedAttrRules");
    r.setServiceId("testId");

    final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
    policy.setAllowedAttributes(Lists.newArrayList("1", "2", "3"));
    r.setAttributeReleasePolicy(policy);

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());

    assertEquals(r, r2);
    assertEquals(r2, r3);
    assertNotNull(r3.getAttributeReleasePolicy());
    assertEquals(r2.getAttributeReleasePolicy(), r3.getAttributeReleasePolicy());
  }
  @Test
  public void verifySaveAttributeReleasePolicyMappingRules() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setName("testSaveAttributeReleasePolicyMappingRules");
    r.setServiceId("testId");

    final Map<String, String> map = new HashMap<>();
    map.put("attr1", "newattr1");
    map.put("attr2", "newattr2");
    map.put("attr2", "newattr3");

    final ReturnMappedAttributeReleasePolicy policy = new ReturnMappedAttributeReleasePolicy();
    policy.setAllowedAttributes(map);
    r.setAttributeReleasePolicy(policy);

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());

    assertEquals(r, r2);
    assertEquals(r2, r3);
    assertNotNull(r3.getAttributeReleasePolicy());
    assertEquals(r2.getAttributeReleasePolicy(), r3.getAttributeReleasePolicy());
  }