Check if a client is authenticated. If so, return true. Otherwise request authentication and return false;
@param request
@param storage
@param organizationSid
@return
@throws IOException
166511
public static boolean checkAuthentication(SipServletRequest request, DaoManager storage, Sid organizationSid) throws IOException {
        // Make sure we force clients to authenticate.
        final String authorization = request.getHeader("Proxy-Authorization");
        final String method = request.getMethod();
        if (authorization == null || !CallControlHelper.permitted(authorization, method, storage, organizationSid)) {
            if (logger.isDebugEnabled()) {
                String msg = String.format("Either authorization header is null [if(authorization==null) evaluates %s], or CallControlHelper.permitted() method failed, will send \"407 Proxy Authentication required\"", authorization==null);
                logger.debug(msg);
            }
            authenticate(request, storage.getOrganizationsDao().getOrganization(organizationSid).getDomainName());
            return false;
        } else {
            return true;
        }
    }
1094264
public boolean requestShouldBeHandledByTAI(HttpServletRequest request, MicroProfileJwtTaiRequest mpJwtTaiRequest, boolean defaultConfig) {
        String methodName = "requestShouldBeHandledByTAI";
        if (tc.isDebugEnabled()) {
            Tr.entry(tc, methodName, request, mpJwtTaiRequest);
        }

        mpJwtTaiRequest = setTaiRequestConfigInfo(request, mpJwtTaiRequest, defaultConfig);
        boolean result = false;
        boolean ignoreAppAuthMethod = true;

        MicroProfileJwtConfig mpJwtConfig = null;
        try {
            mpJwtConfig = mpJwtTaiRequest.getOnlyMatchingConfig();
        } catch (MpJwtProcessingException e) {

        }
        if (mpJwtConfig != null) {
            if (shouldDeferToJwtSso(request, mpJwtConfig, mpJwtTaiRequest.getJwtSsoConfig())) {
                return false;
            }
            ignoreAppAuthMethod = mpJwtConfig.ignoreApplicationAuthMethod(); // true by default
            if (ignoreAppAuthMethod) {
                result = mpJwtTaiRequest.hasServices();
            } else {
                result = isMpJwtSpecifiedInLoginConfig(request);
            }
        }

        if (tc.isDebugEnabled()) {
            Tr.exit(tc, methodName, result);
        }
        return result;
    }
207049
public void doWithRequest(
                    final ClientHttpRequest request
                    )
    throws IOException
    {
        HttpHeaders  headers = request.getHeaders();
        headers.setContentType( _mediaType );

        long  size = IoUtil.copy( new StringReader( _string.toString() ),
                        new OutputStreamWriter( request.getBody() ) );
        headers.setContentLength( size );
    }
461964
function checkCollabAuthenticated(req, res, next) {
		if (req.user) {
			req.user.workspaceDir = options.workspaceDir + (req.user.workspace ? "/" + req.user.workspace : "");
			next();
		} else if (req.headers['authorization'] && checkCollabServerToken(req.headers['authorization'])){
			next();
		} else {
			api.writeError(401, res, "Not authenticated");
		}
	}
697337
protected boolean locateMatchingHttpRequest(final Authentication authentication, final HttpServletRequest request) {
        if (StringUtils.isNotBlank(bypassProperties.getHttpRequestRemoteAddress())) {
            if (httpRequestRemoteAddressPattern.matcher(request.getRemoteAddr()).find()) {
                LOGGER.debug("Http request remote address [{}] matches [{}]", bypassProperties.getHttpRequestRemoteAddress(), request.getRemoteAddr());
                return true;
            }
            if (httpRequestRemoteAddressPattern.matcher(request.getRemoteHost()).find()) {
                LOGGER.debug("Http request remote host [{}] matches [{}]", bypassProperties.getHttpRequestRemoteAddress(), request.getRemoteHost());
                return true;
            }
        }

        if (StringUtils.isNotBlank(bypassProperties.getHttpRequestHeaders())) {
            val headerNames = Collections.list(request.getHeaderNames());
            val matched = this.httpRequestHeaderPatterns.stream()
                .anyMatch(pattern -> headerNames.stream().anyMatch(name -> pattern.matcher(name).matches()));
            if (matched) {
                LOGGER.debug("Http request remote headers [{}] match [{}]", headerNames, bypassProperties.getHttpRequestHeaders());
                return true;
            }
        }

        return false;
    }
766948
protected void verifySadRequest(SignatureActivationDataContext sadRequest, ProfileRequestContext<?, ?> context)
      throws ExternalAutenticationErrorCodeException {

    final AuthnRequest authnRequest = this.getAuthnRequest(context);
    if (authnRequest == null) {
      log.error("No AuthnRequest available [{}]", this.getLogString(context));
      throw new ExternalAutenticationErrorCodeException(AuthnEventIds.INVALID_AUTHN_CTX, "Missing AuthnRequest");
    }

    final SADRequest r = sadRequest.getSadRequest();

    // Verify the version is what we understand ...
    //
    if (r.getRequestedVersion() != null && !supportedSadVersions.contains(r.getRequestedVersion())) {
      final String msg = String.format("Requested SAD version (%s) is not supported by the IdP", r.getRequestedVersion());
      log.info("{} [{}]", msg, this.getLogString(context));
      throw new ExternalAutenticationErrorCodeException(ExtAuthnEventIds.BAD_SAD_REQUEST, msg);
    }

    // Check the RequesterID ...
    //
    if (!StringUtils.hasText(r.getRequesterID())) {
      final String msg = "RequesterID is not present in the SADRequest - invalid";
      log.info("{} [{}]", msg, this.getLogString(context));
      throw new ExternalAutenticationErrorCodeException(ExtAuthnEventIds.BAD_SAD_REQUEST, msg);
    }
    final String issuer = authnRequest.getIssuer().getValue();
    if (!r.getRequesterID().equals(issuer)) {
      final String msg = String.format("Invalid RequestID of SADRequest (%s) - Issuer of AuthnRequest is '%s'", r.getRequesterID(), issuer);
      log.info("{} [{}]", msg, this.getLogString(context));
      throw new ExternalAutenticationErrorCodeException(ExtAuthnEventIds.BAD_SAD_REQUEST, msg);
    }

    // Verify that the SignRequestID is there ...
    //
    if (!StringUtils.hasText(r.getSignRequestID())) {
      final String msg = "SignRequestID is not present in the SADRequest - invalid";
      log.info("{} [{}]", msg, this.getLogString(context));
      throw new ExternalAutenticationErrorCodeException(ExtAuthnEventIds.BAD_SAD_REQUEST, msg);
    }

    // Assert that we have a DocCount element ...
    //
    if (r.getDocCount() == null) {
      final String msg = "DocCount is not present in the SADRequest - invalid";
      log.info("{} [{}]", msg, this.getLogString(context));
      throw new ExternalAutenticationErrorCodeException(ExtAuthnEventIds.BAD_SAD_REQUEST, msg);
    }

    // Assert that we have an ID for the SADRequest ...
    //
    if (!StringUtils.hasText(r.getID())) {
      final String msg = "ID attribute is not present in the SADRequest - invalid";
      log.info("{} [{}]", msg, this.getLogString(context));
      throw new ExternalAutenticationErrorCodeException(ExtAuthnEventIds.BAD_SAD_REQUEST, msg);
    }
  }
668949
public void enableDKIM(EnableDKIMRequest request) {
        checkNotNull(request, "object request should not be null.");
        assertStringNotNullOrEmpty(request.getDomainName(), "object domainName should not be null or empty");

        InternalRequest internalRequest =
                this.createRequest("verifiedDomain", request, HttpMethodName.PUT, request.getDomainName());
        internalRequest.addParameter("enable", "enableDkim");

        this.invokeHttpClient(internalRequest, SesResponse.class);
    }
1001617
public boolean requestShouldBeHandledByTAI(HttpServletRequest request, SocialTaiRequest socialTaiRequest) {
        // 241526 don't process jmx requests with this interceptor
        if (isJmxConnectorRequest(request)) {
            return false;
        }
        String loginHint = webUtils.getLoginHint(request);
        socialTaiRequest = setSocialTaiRequestConfigInfo(request, loginHint, socialTaiRequest);
        return socialTaiRequest.hasServices();
    }
1145332
def _validate_client(self, request, data):
        
        client = self.get_client(data.get('client_id'))

        if client is None:
            raise OAuthError({
                'error': 'unauthorized_client',
                'error_description': _("An unauthorized client tried to access"
                    " your resources.")
            })

        form = self.get_request_form(client, data)

        if not form.is_valid():
            raise OAuthError(form.errors)

        return client, form.cleaned_data
306527
protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request)
            throws IOException, InterruptedException, ExecutionException {
        return api.getAccessTokenExtractor().extract(execute(request));
    }
1025691
public void filter(ClientRequestContext request) throws IOException
    {
        if(!request.getHeaders().containsKey("X-Api-Key"))
            request.getHeaders().add("X-Api-Key", this.apikey);
    }
973550
protected boolean isDeviceTokenRequest(final HttpServletRequest request, final HttpServletResponse response) {
        val requestPath = request.getRequestURI();
        val pattern = String.format("(%s)", OAuth20Constants.DEVICE_AUTHZ_URL);
        return doesUriMatchPattern(requestPath, pattern);
    }
169326
public void checkAuthorization(Action action, ContainerRequestContext requestContext) throws NotAuthorizedException {
		String clientApplicationName = (String)requestContext.getProperty(RequestHandler.APPSENSOR_CLIENT_APPLICATION_IDENTIFIER_ATTR);

		ClientApplication clientApplication = appSensorServer.getConfiguration().findClientApplication(clientApplicationName);
		
		appSensorServer.getAccessController().assertAuthorized(clientApplication, action, new Context());
	}
409236
@Override
    protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException {
        super.onUnsuccessfulAuthentication(request, response, failed);
        LOGGER.log(Level.FINE, "Login attempt failed", failed);
        Authentication auth = failed.getAuthentication();
        if (auth != null) {
            SecurityListener.fireFailedToLogIn(auth.getName());
        }
    }
1323960
private void sendAuthResponse(HttpServletResponse response) throws IOException {
        response.setHeader("WWW-Authenticate", String.format("Basic realm=\"%1$s\"", realm)); //$NON-NLS-1$ //$NON-NLS-2$
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }
1355851
protected boolean isAuthorizationRequest(final HttpServletRequest request, final HttpServletResponse response) {
        val requestPath = request.getRequestURI();
        return doesUriMatchPattern(requestPath, OAuth20Constants.AUTHORIZE_URL);
    }
122422
@Override
	public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		final String requestURI = request.getRequestURI();
		UserAuthentication userAuth = null;

		String appid;
		if (requestURI.startsWith(SAML_ACTION)) {
			appid = Config.getRootAppIdentifier();
			if (requestURI.startsWith(SAML_ACTION + "/")) {
				String id = Utils.urlDecode(StringUtils.removeStart(requestURI, SAML_ACTION + "/"));
				if (!id.isEmpty()) {
					appid = id;
				} else {
					appid = Config.getRootAppIdentifier();
				}
			}
			try {
				App app = Para.getDAO().read(App.id(appid == null ? Config.getRootAppIdentifier() : appid));
				if (app != null) {
					SettingsBuilder builder = new SettingsBuilder();
					Map<String, Object> samlSettings;
					String idpMetaUrl = SecurityUtils.getSettingForApp(app, "security.saml.idp.metadata_url", "");

					if (StringUtils.isBlank(idpMetaUrl)) {
						samlSettings = getSAMLSettings(app);
					} else {
						samlSettings = parseRemoteXML(new URL(idpMetaUrl), request.getParameter("entityid"));
						samlSettings.putAll(getSAMLSettings(app)); // override IDP meta with config values
					}

					Saml2Settings settings = builder.fromValues(samlSettings).build();

					Auth auth = new Auth(settings, request, response);

					if (request.getParameter("SAMLResponse") != null) {
						auth.processResponse();
						if (auth.isAuthenticated()) {
							List<String> errors = auth.getErrors();
							if (errors.isEmpty()) {
								userAuth = getOrCreateUser(app, auth.getAttributes());
							} else {
								throw new AuthenticationServiceException(StringUtils.join(errors, "; "));
							}
						}
					} else {
						auth.login(settings.getSpAssertionConsumerServiceUrl().toString());
						return null; // redirect to IDP
					}
				}
			} catch (SettingsException ex) {
				LOG.error("Failed to authenticate app '{}' with SAML: {}", appid, ex.getMessage());
			} catch (Exception ex) {
				LOG.error(null, ex);
			}
		}

		return SecurityUtils.checkIfActive(userAuth, SecurityUtils.getAuthenticatedUser(userAuth), true);
	}