private static Map<String, String> createAuthorizationAttributeMap(
      String snaaName, Properties props) {
    Map<String, String> attributes = new HashMap<String, String>();

    List<String> keys = new LinkedList<String>();
    // getting keys from properties
    for (Object o : props.keySet()) {
      if (((String) o).startsWith(snaaName + authorizationAtt)
          && ((String) o).endsWith(authorizationKeyAtt)) {
        keys.add((String) o);
      }
    }

    for (String k : keys) {
      String key = props.getProperty(k);
      // getting plain key-number from properties
      String plainKeyProperty = k.replaceAll(snaaName + authorizationAtt + ".", "");
      plainKeyProperty = plainKeyProperty.replaceAll(authorizationKeyAtt, "");

      String keyPrefix = snaaName + authorizationAtt + "." + plainKeyProperty;

      // building value-property-string
      String value = props.getProperty(keyPrefix + authorizationValAtt);

      // finally put key and values
      attributes.put(key, value);
    }

    return attributes;
  }
  @SuppressWarnings("unused")
  private static void callShibbAsWS()
      throws MalformedURLException, SNAAExceptionException, AuthenticationExceptionException {

    SNAA port = WisebedServiceHelper.getSNAAService("http://*****:*****@wisebed1.itm.uni-luebeck.de");
    auth1.setPassword("xxx");

    List<AuthenticationTriple> authTriples = new ArrayList<AuthenticationTriple>();
    authTriples.add(auth1);
    port.authenticate(authTriples);
    Action action = new Action();
    action.setAction("sth");
    port.isAuthorized(new ArrayList<SecretAuthenticationKey>(), action);
  }
  @SuppressWarnings("unused")
  private static void callFederatorAsWS()
      throws MalformedURLException, SNAAExceptionException, AuthenticationExceptionException {

    SNAA port = WisebedServiceHelper.getSNAAService("http://*****:*****@wisebed1.itm.uni-luebeck.de");
    auth1.setPassword("xxx");
    authTriples.add(auth1);

    AuthenticationTriple auth2 = new AuthenticationTriple();
    auth2.setUrnPrefix("urn:wisebed:dummy1");
    auth2.setUsername("*****@*****.**");
    auth2.setPassword("xxx");
    authTriples.add(auth2);

    AuthenticationTriple auth3 = new AuthenticationTriple();
    auth3.setUrnPrefix("urn:wisebed:dummy2");
    auth3.setUsername("*****@*****.**");
    auth3.setPassword("xxx");
    authTriples.add(auth3);

    AuthenticationTriple auth4 = new AuthenticationTriple();
    auth4.setUrnPrefix("urn:wisebed:shib2");
    auth4.setUsername("*****@*****.**");
    auth4.setPassword("xxx");
    authTriples.add(auth4);

    try {
      List<SecretAuthenticationKey> keys = port.authenticate(authTriples);
      log.info("Got authentication keys: " + keys);
      Action action = new Action();
      action.setAction("sth");
      boolean b = port.isAuthorized(new ArrayList<SecretAuthenticationKey>(), action);
      log.info("Is authorized: " + b);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  @Override
  public List<SecretAuthenticationKey> authenticate(
      @WebParam(name = "authenticationData", targetNamespace = "")
          List<AuthenticationTriple> authenticationData)
      throws AuthenticationExceptionException, SNAAExceptionException {

    Map<String, Set<AuthenticationTriple>> intersectionPrefixSet =
        getIntersectionPrefixSetAT(authenticationData);

    Set<Future<List<SecretAuthenticationKey>>> futures =
        new HashSet<Future<List<SecretAuthenticationKey>>>();

    for (String wsEndpointUrl : intersectionPrefixSet.keySet()) {
      AuthenticationCallable authenticationCallable =
          new AuthenticationCallable(
              wsEndpointUrl,
              new ArrayList<AuthenticationTriple>(intersectionPrefixSet.get(wsEndpointUrl)));
      Future<List<SecretAuthenticationKey>> future = executorService.submit(authenticationCallable);
      futures.add(future);
    }

    List<SecretAuthenticationKey> resultSet = new LinkedList<SecretAuthenticationKey>();

    for (Future<List<SecretAuthenticationKey>> future : futures) {
      try {
        resultSet.addAll(future.get());
      } catch (InterruptedException e) {
        SNAAException exception = new SNAAException();
        exception.setMessage(e.getMessage());
        throw new SNAAExceptionException(e.getMessage(), exception, e);
      } catch (ExecutionException e) {
        SNAAException exception = new SNAAException();
        exception.setMessage(e.getMessage());
        throw new SNAAExceptionException(e.getMessage(), exception, e);
      }
    }

    return resultSet;
  }