コード例 #1
0
  private String getGluuCustomPersonAttributesWithValues(GluuCustomPerson gluuCustomPerson) {
    StringBuilder sb = new StringBuilder();
    sb.append("dn: '").append(gluuCustomPerson.getDn()).append("'\n");
    sb.append("inum: '").append(gluuCustomPerson.getInum()).append("',\n");
    sb.append("gluuStatus: '").append(gluuCustomPerson.getStatus()).append("'");

    for (GluuCustomAttribute customAttribute : gluuCustomPerson.getCustomAttributes()) {
      sb.append("\n").append(customAttribute.getName()).append(": '");
      if ((customAttribute.getValues() != null) && (customAttribute.getValues().length > 1)) {
        sb.append(Arrays.toString(customAttribute.getValues()));
      } else {
        sb.append(customAttribute.getValue());
      }
      sb.append("'");
    }

    return sb.toString();
  }
コード例 #2
0
  @Path("/Associate/")
  @POST
  @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Response createAssociation(
      @HeaderParam("Authorization") String authorization, PersonAssociation personAssociation)
      throws Exception {

    personService = PersonService.instance();
    clientService = ClientService.instance();

    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
      return authorizationResponse;
    }

    try {
      log.info("creating an instance of gluuCustomperson");
      GluuCustomPerson person =
          personService.getPersonByInum(personAssociation.getUserAssociation().replaceAll(" ", ""));

      log.info("setting AssociatedClientDNs");
      List<String> cleanCDNList = new ArrayList<String>();
      for (String dn : personAssociation.getEntryAssociations()) {
        cleanCDNList.add(dn.replaceAll(" ", ""));
      }

      person.setAssociatedClient(cleanCDNList);

      log.info("updating person");

      personService.updatePerson(person);

      log.info("setting user in clients");
      for (String clientDn : personAssociation.getEntryAssociations()) {
        log.info("getting a client");
        OxAuthCustomClient client =
            clientService.getClientByAttributeCustom(
                applicationConfiguration.getClientAssociationAttribute(),
                clientDn.replaceAll(" ", ""));

        log.info("the inum of the client ", client.getInum());

        log.info("checking if the list is empty");
        boolean isAPDNsEmpty = client.getAttributes("associatedPerson") == null;

        log.info("instantiating a new arraylist");

        List<String> listOfpersons = new ArrayList<String>();
        log.info("getting AssociatedPersonDN");
        if (!isAPDNsEmpty) {
          listOfpersons = new ArrayList(Arrays.asList(client.getAttributes("associatedPerson")));
          /*
           * for(String dn :
           * client.getAttributes("associatedPersonDN")){ if(dn !=
           * null && !dn.equalsIgnoreCase("")){listOfpersons.add(dn);}
           * }
           */

        }
        log.info("getting persons dn");
        String personInum = personAssociation.getUserAssociation().replaceAll(" ", "");

        if (isAPDNsEmpty || !listOfpersons.contains(personInum)) {
          log.info("adding person");
          listOfpersons.add(personInum);
        }

        String[] arrayOfpersons = new String[listOfpersons.size()];
        for (int i = 0; i < listOfpersons.size(); i++) {
          arrayOfpersons[i] = listOfpersons.get(i);
        }
        log.info("setting list of AssociatedPersonDns");
        client.setAttribute("associatedPerson", arrayOfpersons);
        log.info("Updating client");
        clientService.updateCustomClient(client);
      }

      String uri = "/ClientAssociation/Associate/" + person.getInum();
      log.info("returning response");
      return Response.created(URI.create(uri)).entity(personAssociation).build();

    } catch (Exception ex) {
      log.error("Failed to add Association", ex);
      // log.info("Failed to add Association" , ex);
      return getErrorResponse(
          "Unexpected processing error, please check the input parameters",
          Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
  }