Exemplo n.º 1
0
  public List<SecurityQuestionAnswerDTO> createUsersSecurityQuestionsList(
      PrismObject<UserType> user) {
    LOGGER.debug("Security Questions Loading for user: "******"User SecurityQuestion ANswer List is Not null");
        List<SecurityQuestionAnswerDTO> secQuestAnswListDTO =
            new ArrayList<SecurityQuestionAnswerDTO>();
        for (Iterator iterator = secQuestAnsList.iterator(); iterator.hasNext(); ) {
          SecurityQuestionAnswerType securityQuestionAnswerType =
              (SecurityQuestionAnswerType) iterator.next();

          Protector protector = getPrismContext().getDefaultProtector();
          String decoded = "";
          if (securityQuestionAnswerType.getQuestionAnswer().getEncryptedDataType() != null) {
            try {
              decoded = protector.decryptString(securityQuestionAnswerType.getQuestionAnswer());

            } catch (EncryptionException e) {
              LoggingUtils.logException(LOGGER, "Couldn't decrypt user answer", e);
            }
          }
          // LOGGER.debug("SecAnswerIdentifier:"+securityQuestionAnswerType.getQuestionIdentifier());
          secQuestAnswListDTO.add(
              new SecurityQuestionAnswerDTO(
                  securityQuestionAnswerType.getQuestionIdentifier(), decoded));
        }

        return secQuestAnswListDTO;
      }
    }
    return null;
  }
Exemplo n.º 2
0
  private void updateQuestions(String useroid, AjaxRequestTarget target) {

    Task task = createSimpleTask(OPERATION_SAVE_QUESTIONS);
    OperationResult result = new OperationResult(OPERATION_SAVE_QUESTIONS);
    SchemaRegistry registry = getPrismContext().getSchemaRegistry();
    SecurityQuestionAnswerType[] answerTypeList = new SecurityQuestionAnswerType[questionNumber];

    try {
      int listnum = 0;
      for (Iterator iterator = pqPanels.iterator(); iterator.hasNext(); ) {
        MyPasswordQuestionsPanel type = (MyPasswordQuestionsPanel) iterator.next();

        SecurityQuestionAnswerType answerType = new SecurityQuestionAnswerType();
        ProtectedStringType answer = new ProtectedStringType();

        answer.setClearValue(
            ((TextField<String>) type.get(MyPasswordQuestionsPanel.F_ANSWER)).getModelObject());
        answerType.setQuestionAnswer(answer);

        // used apache's unescapeHtml method for special chars like \'
        String results =
            StringEscapeUtils.unescapeHtml(
                (type.get(MyPasswordQuestionsPanel.F_QUESTION)).getDefaultModelObjectAsString());
        answerType.setQuestionIdentifier(getQuestionIdentifierFromQuestion(results));
        answerTypeList[listnum] = answerType;
        listnum++;
      }

      // if(answerTypeList.length !=)

      // fill in answerType data here
      ItemPath path =
          new ItemPath(
              UserType.F_CREDENTIALS,
              CredentialsType.F_SECURITY_QUESTIONS,
              SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
      ObjectDelta<UserType> objectDelta =
          ObjectDelta.createModificationReplaceContainer(
              UserType.class, useroid, path, getPrismContext(), answerTypeList);

      Collection<ObjectDelta<? extends ObjectType>> deltas =
          MiscSchemaUtil.createCollection(objectDelta);
      getModelService().executeChanges(deltas, null, task, result);

      /*
      	System.out.println("getModel");
      	 Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
      	PasswordQuestionsDto dto = new PasswordQuestionsDto();
      	 PrismObjectDefinition objDef =registry.findObjectDefinitionByCompileTimeClass(UserType.class);
      	 Class<? extends ObjectType> type =  UserType.class;

      	 final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
                       CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
      	 SecurityQuestionAnswerType secQuesAnsType= new SecurityQuestionAnswerType();
      	 ProtectedStringType protStrType= new ProtectedStringType();
      	 protStrType.setClearValue("deneme");
      	 secQuesAnsType.setQuestionAnswer(protStrType);
      	 dto.setSecurityAnswers(new ArrayList<SecurityQuestionAnswerType>());
      	 dto.getSecurityAnswers().add(secQuesAnsType);

      	PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, dto.getSecurityAnswers().get(0).getQuestionAnswer());
      //	PropertyDelta delta= PropertyDelta.createModifica

      	 System.out.println("Update Questions3");
      	deltas.add(ObjectDelta.createModifyDelta(useroid, delta, type, getPrismContext()));
      	System.out.println("Update Questions4");
      	getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_QUESTIONS), result);
      	System.out.println("Update Questions5");

      	 */
      success(getString("message.success"));
      target.add(getFeedbackPanel());
    } catch (Exception ex) {

      error(getString("message.error"));
      target.add(getFeedbackPanel());
      ex.printStackTrace();
    }
  }