Generate internal.

@param request  the request
@param response the response
@param result   the result
@return the access token response model
505636
protected Map<String, Object> getAccessTokenResponseModel(final HttpServletRequest request,
                                                              final HttpServletResponse response,
                                                              final OAuth20AccessTokenResponseResult result) {
        val model = new LinkedHashMap<String, Object>();
        val generatedToken = result.getGeneratedToken();
        generatedToken.getAccessToken().ifPresent(t -> {
            model.put(OAuth20Constants.ACCESS_TOKEN, encodeAccessToken(t, result));
            model.put(OAuth20Constants.SCOPE, t.getScopes().stream().collect(joining(" ")));
        });
        generatedToken.getRefreshToken().ifPresent(t -> model.put(OAuth20Constants.REFRESH_TOKEN, t.getId()));
        model.put(OAuth20Constants.TOKEN_TYPE, OAuth20Constants.TOKEN_TYPE_BEARER);
        model.put(OAuth20Constants.EXPIRES_IN, result.getAccessTokenTimeout());
        return model;
    }
848672
public CreateOnceOnetimeTokenResult createOnceOnetimeToken(CreateOnceOnetimeTokenRequest request) {

		ObjectNode body = JsonNodeFactory.instance.objectNode()
				.put("scriptName", request.getScriptName());
        if(request.getGrant() != null) body.put("grant", request.getGrant());
        if(request.getArgs() != null) body.put("args", request.getArgs());

		HttpPost post = createHttpPost(
				Gs2Constant.ENDPOINT_HOST + "/onetime/once/token",
				credential,
				ENDPOINT,
				CreateOnceOnetimeTokenRequest.Constant.MODULE,
				CreateOnceOnetimeTokenRequest.Constant.FUNCTION,
				body.toString());
        if(request.getRequestId() != null) {
            post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
        }


		return doRequest(post, CreateOnceOnetimeTokenResult.class);

	}
1071148
public GetImageResponse getImage(GetImageRequest request) {
        checkNotNull(request, "request should not be null.");
        checkStringNotEmpty(request.getImageId(), "request imageId should not be empty.");
        InternalRequest internalRequest =
                this.createRequest(request, HttpMethodName.GET, IMAGE_PREFIX, request.getImageId());
        return invokeHttpClient(internalRequest, GetImageResponse.class);
    }
639725
public Request createGetRequest(String url, String apiKey, String accessToken) {
        HttpUrl.Builder httpBuilder = HttpUrl.parse(url).newBuilder();
        return new Request.Builder().url(httpBuilder.build()).header("User-Agent", USER_AGENT).header("X-Kite-Version", "3").header("Authorization", "token "+apiKey+":"+accessToken).build();
    }
749282
@GetMapping(path = {"/swivel/turingImage"})
    public void generate(final HttpServletResponse response, final HttpServletRequest request) throws Exception {
        response.setContentType("image/png");
        val principal = request.getParameter("principal");
        if (StringUtils.isBlank(principal)) {
            throw new IllegalArgumentException("No principal is specified in the turing image request");
        }
        generateImage(response.getOutputStream(), principal);
    }
1192418
private void generateAuthenticationEvent(HttpServletRequest request, HttpServletResponse response) {
    try {
      Optional<JwtHttpHandler.Token> token = jwtHttpHandler.getToken(request, response);
      String userLogin = token.isPresent() ? token.get().getUserDto().getLogin() : null;
      authenticationEvent.logoutSuccess(request, userLogin);
    } catch (AuthenticationException e) {
      authenticationEvent.logoutFailure(request, e.getMessage());
    }
  }
24996
public static String getToken(HttpServletRequest request, ActionMapping mapping)
    {
        if (mapping instanceof PageFlowActionMapping && ((PageFlowActionMapping) mapping).isPreventDoubleSubmit()) {
            HttpSession session = request.getSession();
            String token = (String) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY);
            if (token != null) return token;
            token = TokenProcessor.getInstance().generateToken(request);
            request.getSession().setAttribute(Globals.TRANSACTION_TOKEN_KEY, token);
            return token;
        }

        return null;
    }
452110
public CreateResponse create(CreateRequest request) {
    return call(
      new PostRequest(path("create"))
        .setParam("name", request.getName())
        .setParam("organization", request.getOrganization()),
      CreateResponse.parser());
  }
256482
@POST
    @Produces(MediaType.TEXT_PLAIN)
    @ApiOperation(
            value = "Assert login credentials",
            notes = "Upon a successful login, a JWT will be returned in the response. This functionality requires authentication to be enabled.",
            response = String.class
    )
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Success"),
            @ApiResponse(code = 401, message = "Unauthorized")
    })
    @AuthenticationNotRequired
    public Response validateCredentials(@FormParam("username") String username, @FormParam("password") String password) {
        final Authenticator auth = new Authenticator(username, password);
        try {
            final Principal principal = auth.authenticate();
            if (principal != null) {
                LOGGER.info(SecurityMarkers.SECURITY_AUDIT, "Login succeeded (username: " + username
                        + " / ip address: " + super.getRemoteAddress()
                        + " / agent: " + super.getUserAgent() + ")");

                final JsonWebToken jwt = new JsonWebToken();
                final String token = jwt.createToken(principal);
                return Response.ok(token).build();
            }
        } catch (AuthenticationException e) {
            LOGGER.warn(SecurityMarkers.SECURITY_AUDIT, "Unauthorized login attempt (username: "
                    + username + " / ip address: " + super.getRemoteAddress()
                    + " / agent: " + super.getUserAgent() + ")");
        }
        return Response.status(Response.Status.UNAUTHORIZED).build();
    }
833304
public GetWaterMarkResponse getWaterMark(GetWaterMarkRequest request) {
        checkStringNotEmpty(request.getWatermarkId(), "The parameter watermarkId should NOT be null or empty string.");
        InternalRequest internalRequest =
                createRequest(HttpMethodName.GET, request, WATER_MARK, request.getWatermarkId());
        
        return invokeHttpClient(internalRequest, GetWaterMarkResponse.class);
    }
1008393
public GetSessionTokenResponse getSessionToken(GetSessionTokenRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");
        checkIsTrue(request.getDurationSeconds() > 0, "the durationSeconds parameter should be greater than zero");

        InternalRequest internalRequest = new InternalRequest(HttpMethodName.POST,
                HttpUtils.appendUri(this.getEndpoint(), URL_PREFIX, GET_SESSION_TOKEN_PATH));
        if (request.getDurationSeconds() != null) {
            internalRequest.addParameter("durationSeconds", String.valueOf(request.getDurationSeconds()));
        }
        internalRequest.setCredentials(request.getRequestCredentials());
        internalRequest.addHeader(Headers.CONTENT_LENGTH,
                String.valueOf(request.getAcl() == null ? 0 : request.getAcl().length()));
        internalRequest.addHeader(Headers.CONTENT_TYPE, "application/json");
        if (request.getAcl() != null) {
            internalRequest.setContent(RestartableInputStream.wrap(request.getAcl().getBytes()));
        }
        return this.invokeHttpClient(internalRequest, GetSessionTokenResponse.class);
    }
434609
private static Response createResponse(Object object) {
    if (object == null) {
      return Response.ok().build();
    }

    if (object instanceof Response) {
      return (Response) object;
    }

    if (object instanceof Response.Status) {
      Response.Status s = (Response.Status) object;
      switch (s) {
        case OK:
          return Response.ok().build();
        case ACCEPTED:
          return Response.accepted().build();
        case NO_CONTENT:
          return Response.noContent().build();
        default:
          return createErrorResponse(
              new S3Exception("Response status is invalid", S3ErrorCode.INTERNAL_ERROR));
      }
    }

    // Need to explicitly encode the string as XML because Jackson will not do it automatically.
    XmlMapper mapper = new XmlMapper();
    try {
      return Response.ok(mapper.writeValueAsString(object)).build();
    } catch (JsonProcessingException e) {
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
          .entity("Failed to encode XML: " + e.getMessage()).build();
    }
  }
548280
public void generateError(String response) {
        final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true);
        final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false);
        final String errorUriInString = extractParameter(response, ERROR_URI_REGEX_PATTERN, false);
        URI errorUri;
        try {
            errorUri = errorUriInString == null ? null : URI.create(errorUriInString);
        } catch (IllegalArgumentException iae) {
            errorUri = null;
        }

        OAuth2Error errorCode;
        try {
            errorCode = OAuth2Error.parseFrom(errorInString);
        } catch (IllegalArgumentException iaE) {
            //non oauth standard error code
            errorCode = null;
        }

        throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, errorUri, response);
    }
1146413
public CreateSessionResponse createSession(CreateSessionRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");

        if (request.getPreset() == null && request.getPresets() == null) {
            throw new IllegalArgumentException("The parameter preset and presets should NOT both be null or empty.");
        }

        InternalRequest internalRequest = createRequest(HttpMethodName.POST, request, LIVE_SESSION);
        return invokeHttpClient(internalRequest, CreateSessionResponse.class);
    }
615295
def create_token_response(self, uri, http_method='GET', body=None,
                              headers=None, credentials=None, grant_type_for_scope=None,
                              claims=None):
        """"""
        request = Request(
            uri, http_method=http_method, body=body, headers=headers)

        # 'scope' is an allowed Token Request param in both the "Resource Owner Password Credentials Grant"
        # and "Client Credentials Grant" flows
        # https://tools.ietf.org/html/rfc6749#section-4.3.2
        # https://tools.ietf.org/html/rfc6749#section-4.4.2
        request.scopes = utils.scope_to_list(request.scope)

        request.extra_credentials = credentials
        if grant_type_for_scope:
            request.grant_type = grant_type_for_scope

        # OpenID Connect claims, if provided.  The server using oauthlib might choose
        # to implement the claims parameter of the Authorization Request.  In this case
        # it should retrieve those claims and pass them via the claims argument here,
        # as a dict.
        if claims:
            request.claims = claims

        grant_type_handler = self.grant_types.get(request.grant_type,
                                                  self.default_grant_type_handler)
        log.debug('Dispatching grant_type %s request to %r.',
                  request.grant_type, grant_type_handler)
        return grant_type_handler.create_token_response(
            request, self.default_token_type)
498422
public HttpClientResponseBuilder doReturn(String response, Charset charset) {
        newRule.addAction(new StringResponse(response, charset));
        return new HttpClientResponseBuilder(newRule);
    }
711334
protected void buildEcpFaultResponse(final HttpServletResponse response,
                                         final HttpServletRequest request,
                                         final Pair<RequestAbstractType, String> authenticationContext) {
        request.setAttribute(SamlIdPConstants.REQUEST_ATTRIBUTE_ERROR, authenticationContext.getValue());
        getSamlProfileHandlerConfigurationContext().getSamlFaultResponseBuilder()
            .build(authenticationContext.getKey(), request, response,
                null, null, null, SAMLConstants.SAML2_PAOS_BINDING_URI, null);

    }