Adds an expected challenge answer to collection of answers.

@param answer Answer to add.
@param realm  Authentication realm for the answer.
542577
public void submitAnswer(JSONObject answer, String realm) {
        if (answers == null) {
            answers = new JSONObject();
        }

        try {
            answers.put(realm, answer);
            if (isAnswersFilled()) {
                resendRequest();
            }
        } catch (Throwable t) {
            logger.error("submitAnswer failed with exception: " + t.getLocalizedMessage(), t);
        }
    }
240975
private void processResponse(Response response) {
        // at this point a server response should contain a secure JSON with challenges
        JSONObject jsonResponse = Utils.extractSecureJson(response);
        JSONObject jsonChallenges = (jsonResponse == null) ? null : jsonResponse.optJSONObject(CHALLENGES_VALUE_NAME);

        if (jsonChallenges != null) {
            startHandleChallenges(jsonChallenges, response);
        } else {
            listener.onSuccess(response);
        }
    }
535878
static public void sendAuthRequiredError(HttpServletResponse response, String realm) throws IOException {
		response.setHeader("WWW-Authenticate", "Basic realm=\""+realm+"\"");
		response.setHeader("Cache-Control", "no-cache,must-revalidate");
		response.setDateHeader("Expires", (new Date()).getTime());
		response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
	}
1320273
@Override
	public void onResponse( Object cookie, ResponseJSO response, int msgLevel, String msg )
	{
		PendingRequestInfo info = (PendingRequestInfo) cookie;

		// Store answer in cache
		if( info.fStoreResultInCache )
			cache.put( info.requestKey, response );

		// give the result to all the subscribees
		for( RequestCallInfo call : info.subscriptions )
			call.setResult( msgLevel, msg, null, response );

		// forget this request
		pendingRequests.remove( info );

		// calls back the clients
		checkAnswersToGive();
	}
165700
def addAnswers(self, answers, callback=None, errback=None, **kwargs):
        
        if not self.data:
            raise RecordException('record not loaded')
        orig_answers = self.data['answers']
        new_answers = self._rest._getAnswersForBody(answers)
        orig_answers.extend(new_answers)
        return self.update(answers=orig_answers, callback=callback,
                           errback=errback, **kwargs)
793977
public function checkAnswer(string $remoteip, string $challenge = null, string $response = null) : Response
    {
        if (empty($remoteip)) {
            throw new Exception('For security reasons, you must pass the remote ip to solvemedia');
        }

        //discard spam submissions
        if (empty($challenge) || empty($response)) {
            return new Response(false, 'incorrect-solution');
        }

        $httpResponse = $this->_client->request(
            'POST',
            self::ADCOPY_VERIFY_SERVER,
            [
                'headers' => ['User-Agent' => 'solvemedia/PHP'],
                'form_params' => [
                    'privatekey' => $this->_privkey,
                    'remoteip' => $remoteip,
                    'challenge' => $challenge,
                    'response' => $response,
                ],
            ]
        );

        if ($httpResponse->getStatusCode() !== 200) {
            return new Response(false, $httpResponse->getReasonPhrase());
        }

        $answers = explode("\n", (string)$httpResponse->getBody());

        if (!empty($this->_hashkey)) {
            // validate message authenticator
            $hash = sha1($answers[0] . $challenge . $this->_hashkey);

            if ($hash !== $answers[2]) {
                return new Response(false, 'hash-fail');
            }
        }

        if (trim($answers[0]) !== 'true') {
            return new Response(false, $answers[1]);
        }

        return new Response(true);
    }
1374936
@Incubating
    public static <A> Answer<Void> answerVoid(VoidAnswer1<A> answer) {
        return toAnswer(answer);
    }
1224847
def add_comment(self, answer, content):
        

        from .answer import Answer
        if isinstance(answer, Answer) is False:
            raise ValueError('argument answer need to be Zhihu.Answer object.')
        if not content:
            raise ValueError('answer content cannot be empty')
        data = {
            'method': 'add_comment',
            'params': json.dumps({'answer_id': answer.aid, 'content': content}),
            '_xsrf': answer.xsrf
            }
        res = self._session.post(Answer_Add_Comment_URL,
                                 data=data)
        return res.json()['r'] == 0
223494
private function getCorrectAnswerForRowSumMode(AbstractItem $question, $answer)
    {
        $corrected = new CorrectedAnswer();

        if (!is_null($answer)) {
            // correct answers per row
            for ($i = 0; $i < $question->getRows(); ++$i) {
                // get cells where there is at least 1 expected answer for the current row (none possible)
                $rowCellsUuids = [];

                foreach ($question->getCells() as $cell) {
                    if ($cell->getCoordsY() === $i && $cell->isInput()) {
                        $rowCellsUuids[] = $cell->getUuid();
                    }
                }

                // if any answer is needed in this row
                if (!empty($rowCellsUuids)) {
                    // score will be applied only if all expected answers are there and valid
                    $all = true;

                    foreach ($rowCellsUuids as $expectedCellUuid) {
                        // if $expectedCellUuid found in answers
                        $givenAnwser = array_filter($answer, function ($given) use ($expectedCellUuid) {
                            return $given['cellId'] === $expectedCellUuid;
                        });
                        if (empty($givenAnwser)) {
                            $all = false;
                            break;
                        } else {
                            // check answer
                            $cell = $question->getCell($expectedCellUuid);
                            $currentAnswer = reset($givenAnwser);
                            $choice = $cell->getChoice($currentAnswer['text']);
                            // wrong or empty anwser -> score will not be applied
                            if (empty($choice) || (!empty($choice) && !$choice->isExpected())) {
                                $all = false;
                                break;
                            }
                        }
                    }

                    if ($all) {
                        $scoreToApply = $choice->getScore();
                        $corrected->addExpected(new GenericScore($scoreToApply));
                    } else {
                        $corrected->addPenalty(new GenericPenalty($question->getPenalty()));
                    }
                }
            }
        }

        return $corrected;
    }
968994
public boolean add(ConceptMap answer, ConceptMap answerIndex){
        Index ind = Index.of(answerIndex.vars());
        if (ind.equals(index)) {
            return indexedAnswers.put(answerIndex, answer);
        }
        throw new IllegalStateException("Illegal index: " + answerIndex + " indices: " + index);
    }
697725
protected void set(ClientResponse response) {
        if (!this.status.compareAndSet(STATUS_RUNNING, STATUS_SUCCESS))
            return;
        this.response = response;
        this.latch.countDown();
    }
1317018
def check_answer(self, hash_answer):
        
        for challenge in self.challenges:
            if challenge.response == hash_answer:
                # If we don't discard a used challenge then a node
                # could fake having the file because it already
                # knows the proper response
                self.delete_challenge(hash_answer)
                return True
        return False
419641
public static void putAuthenticationResult(final AuthenticationResult authenticationResult, final RequestContext context) {
        context.getConversationScope().put(PARAMETER_AUTHENTICATION_RESULT, authenticationResult);
    }
974590
public RespondToAuthChallengeResult withChallengeParameters(java.util.Map<String, String> challengeParameters) {
        setChallengeParameters(challengeParameters);
        return this;
    }
644025
public function removeAnswer(Answer $answer)
    {
        if ($this->answers->contains($answer)) {
            $this->answers->removeElement($answer);
        }
    }
99841
public void registerAuthenticationListener(String realm, AuthenticationListener listener) {
        if (realm == null || realm.isEmpty()) {
            throw new InvalidParameterException("The realm name can't be null or empty.");
        }

        if (listener == null) {
            throw new InvalidParameterException("The authentication listener object can't be null.");
        }

        ChallengeHandler handler = new ChallengeHandler();
        handler.initialize(realm, listener);
        challengeHandlers.put(realm, handler);
    }
14773
public void addAuthHeader(SipServletResponse challengeResponse,
			String username, String password) {
		addAuthHeader(challengeResponse, username, password, false);
	}