/*
(non-Javadoc)
@see
org.modeshape.jcr.security.AuthenticationProvider#authenticate(javax.
jcr.Credentials, java.lang.String, java.lang.String,
org.modeshape.jcr.ExecutionContext, java.util.Map)
492149
@Override
    public ExecutionContext authenticate(final Credentials credentials,
            final String repositoryName, final String workspaceName,
            final ExecutionContext repositoryContext,
            final Map<String, Object> sessionAttributes) {
        if (credentials instanceof ServletCredentials) {
            return repositoryContext
                    .with(new AnonymousAdminSecurityContext("bypassAdmin"));
        }
        return null;

    }
812372
@Override
    public void authenticateWithBlackduck() throws IntegrationException {
        final URL authenticationUrl;
        try {
            authenticationUrl = new URL(getBaseUrl(), "api/tokens/authenticate");
        } catch (final MalformedURLException e) {
            throw new IntegrationException("Error constructing the authentication URL: " + e.getMessage(), e);
        }

        if (StringUtils.isNotBlank(hubApiToken)) {
            final RequestBuilder requestBuilder = createRequestBuilder(HttpMethod.POST, getRequestHeaders());
            requestBuilder.setCharset(Charsets.UTF_8);
            requestBuilder.setUri(authenticationUrl.toString());
            final HttpUriRequest request = requestBuilder.build();
            logRequestHeaders(request);
            try (final CloseableHttpResponse closeableHttpResponse = getClient().execute(request)) {
                logResponseHeaders(closeableHttpResponse);
                final Response response = new Response(closeableHttpResponse);
                final int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
                final String statusMessage = closeableHttpResponse.getStatusLine().getReasonPhrase();
                if (statusCode < RestConstants.OK_200 || statusCode >= RestConstants.MULT_CHOICE_300) {
                    final String httpResponseContent = response.getContentString();
                    throw new IntegrationRestException(statusCode, statusMessage, httpResponseContent, String.format("Connection Error: %s %s", statusCode, statusMessage));
                } else {
                    addCommonRequestHeader(AUTHORIZATION_HEADER, "Bearer " + readBearerToken(closeableHttpResponse));

                    // get the CSRF token
                    final Header csrfToken = closeableHttpResponse.getFirstHeader(RestConstants.X_CSRF_TOKEN);
                    if (csrfToken != null) {
                        addCommonRequestHeader(RestConstants.X_CSRF_TOKEN, csrfToken.getValue());
                    } else {
                        logger.error("No CSRF token found when authenticating");
                    }
                }
            } catch (final IOException e) {
                throw new IntegrationException(e.getMessage(), e);
            }
        }
    }
880397
def authenticate(credentials, sock_info):
    """"""
    mechanism = credentials.mechanism
    auth_func = _AUTH_MAP.get(mechanism)
    auth_func(credentials, sock_info)
1112628
protected void validateCredentials(final UsernamePasswordCredentials credentials,
                                       final OAuthRegisteredService registeredService,
                                       final WebContext context) {
        if (!OAuth20Utils.checkClientSecret(registeredService, credentials.getPassword())) {
            throw new CredentialsException("Bad secret for client identifier: " + credentials.getPassword());
        }
    }
1316055
public void authenticate(String username, String password) {
        ldapTemplate.authenticate(query().where("objectClass").is("simpleSecurityObject").and("cn").is(username), password);
        LOGGER.info("Successfully authenticated " + username);
    }
91144
public static TextAnalyticsAPI authenticate(AzureRegions region, ServiceClientCredentials credentials) {
        return authenticate("https://{AzureRegion}.api.cognitive.microsoft.com/text/analytics/", credentials)
                .withAzureRegion(region);
    }
828008
public static FaceAPI authenticate(String baseUrl, final String subscriptionKey) {
        ServiceClientCredentials serviceClientCredentials = new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(OkHttpClient.Builder builder) {
                builder.addNetworkInterceptor(
                        new Interceptor() {
                            @Override
                            public Response intercept(Chain chain) throws IOException {
                                Request request = null;
                                Request original = chain.request();
                                // Request customization: add request headers
                                Request.Builder requestBuilder = original.newBuilder()
                                        .addHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
                                request = requestBuilder.build();
                                return chain.proceed(request);
                            }
                        });
            }
        };
        return authenticate(baseUrl, serviceClientCredentials);
    }
138097
public ResponseEntity<SimplePrincipal> authenticate(final UsernamePasswordCredential c) {
        val entity = new HttpEntity<Object>(HttpUtils.createBasicAuthHeaders(c.getUsername(), c.getPassword()));
        return restTemplate.exchange(authenticationUri, HttpMethod.POST, entity, SimplePrincipal.class);
    }
940417
public Credential authenticate(String authorizationCode, String userId) throws AuthException {
        Preconditions.checkNotNull(authorizationCode, "Authorization code must not be null");
        AuthorizationCodeTokenRequest tokenRequest = authorizationCodeFlow.newTokenRequest(authorizationCode);

        TokenResponse tokenResponse;
        try {
            tokenResponse = tokenRequest
                    .setRedirectUri(redirectUri)
                    .setScopes(scopes)
                    .execute();
        } catch (IOException e) {
            throw new AuthException("Unable to request token.", e);
        }
        try {
            return authorizationCodeFlow.createAndStoreCredential(tokenResponse, userId);
        } catch (IOException e) {
            throw new AuthException("Unable to create and store credential.", e);
        }
    }
1042216
protected Account authenticate(String username, String password) {
        StandardCredentials authenticationToken = new StandardCredentials(username, password);
        Account account = securityManager.authenticate(authenticationToken);
        return account;
    }
1284800
public void authenticate() {
		log.info("Authenticating user: " + this.name);
		WebSession result = null;
		try {
			result = getContext().getAuthenticationMethod().authenticate(
				getContext().getSessionManagementMethod(), this.authenticationCredentials, this);
		} catch (UnsupportedAuthenticationCredentialsException e) {
			log.error("User does not have the expected type of credentials:", e);
		}
		// no issues appear if a simultaneous call to #queueAuthentication() is made
		synchronized (this) {
			this.lastSuccessfulAuthTime = System.currentTimeMillis();
			this.authenticatedSession = result;
		}
	}
798753
public static ContentModeratorClient authenticate(AzureRegionBaseUrl baseUrl, ServiceClientCredentials credentials) {
        return authenticate("https://{baseUrl}/", credentials)
                .withBaseUrl(baseUrl);
    }
224385
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
		Assert.isInstanceOf(SocialAuthenticationToken.class, authentication, "unsupported authentication type");
		Assert.isTrue(!authentication.isAuthenticated(), "already authenticated");
		SocialAuthenticationToken authToken = (SocialAuthenticationToken) authentication;
		String providerId = authToken.getProviderId();
		Connection<?> connection = authToken.getConnection();

		String userId = toUserId(connection);
		if (userId == null) {
			throw new BadCredentialsException("Unknown access token");
		}

		UserDetails userDetails = userDetailsService.loadUserByUserId(userId);
		if (userDetails == null) {
			throw new UsernameNotFoundException("Unknown connected account id");
		}

		return new SocialAuthenticationToken(connection, userDetails, authToken.getProviderAccountData(), getAuthorities(providerId, userDetails));
	}
96991
@Override
    protected boolean authenticate(final Request request, final Response response)
    {
        // Restore credentials from the cookie
        final Cookie credentialsCookie = request.getCookies().getFirst(this.getCookieName());
        
        if(credentialsCookie != null)
        {
            ChallengeResponse credentials = this.parseCredentials(credentialsCookie.getValue());
            if(credentials == null)
            {
                response.getCookieSettings().removeAll(this.getCookieName());
            }
            else
            {
                request.setChallengeResponse(credentials);
            }
        }
        
        this.log.debug("Calling super.authenticate");
        return super.authenticate(request, response);
    }
1353707
@Override
    void authenticate(Map<String, Object> options) {
        final String current = (String) options.get(AbstractReplicatorConfiguration.REPLICATOR_OPTION_COOKIES);
        final StringBuffer cookieStr = current != null ? new StringBuffer(current) : new StringBuffer();

        if (cookieStr.length() > 0) { cookieStr.append("; "); }
        cookieStr.append(String.format(Locale.ENGLISH, "%s=%s", cookieName, sessionID));

        options.put(AbstractReplicatorConfiguration.REPLICATOR_OPTION_COOKIES, cookieStr.toString());
    }
1099997
public static ComputerVisionClient authenticate(ServiceClientCredentials credentials, String endpoint) {
        return authenticate("https://{endpoint}/vision/v2.0/", credentials)
                .withEndpoint(endpoint);
    }
743826
protected void verifyAuthenticationContextSignature(final MessageContext ctx,
                                                        final HttpServletRequest request,
                                                        final RequestAbstractType authnRequest,
                                                        final SamlRegisteredServiceServiceProviderMetadataFacade adaptor) throws Exception {
        if (!SAMLBindingSupport.isMessageSigned(ctx)) {
            LOGGER.debug("The authentication context is not signed");
            if (adaptor.isAuthnRequestsSigned()) {
                LOGGER.error("Metadata for [{}] says authentication requests are signed, yet authentication request is not", adaptor.getEntityId());
                throw new SAMLException("AuthN request is not signed but should be");
            }
            LOGGER.debug("Authentication request is not signed, so there is no need to verify its signature.");
        } else {
            LOGGER.debug("The authentication context is signed; Proceeding to validate signatures...");
            samlProfileHandlerConfigurationContext.getSamlObjectSignatureValidator().verifySamlProfileRequestIfNeeded(authnRequest, adaptor, request, ctx);
        }
    }