Gets credential from the context.

@param context the context
@return the credential, or null if it cant be found in the context or if it has no id.
163306
public static Credential getCredential(final RequestContext context) {
        val cFromRequest = (Credential) context.getRequestScope().get(PARAMETER_CREDENTIAL);
        val cFromFlow = (Credential) context.getFlowScope().get(PARAMETER_CREDENTIAL);
        val cFromConversation = (Credential) context.getConversationScope().get(PARAMETER_CREDENTIAL);

        var credential = cFromRequest;
        if (credential == null || StringUtils.isBlank(credential.getId())) {
            credential = cFromFlow;
        }
        if (credential == null || StringUtils.isBlank(credential.getId())) {
            credential = cFromConversation;
            if (credential != null && !StringUtils.isBlank(credential.getId())) {
                context.getFlowScope().put(PARAMETER_CREDENTIAL, credential);
            }
        }

        if (credential == null) {
            val session = context.getFlowExecutionContext().getActiveSession();
            credential = session.getScope().get(PARAMETER_CREDENTIAL, Credential.class);
        }
        if (credential != null && StringUtils.isBlank(credential.getId())) {
            return null;
        }
        return credential;
    }
158602
@Override
    public synchronized void authenticate() throws PortalSecurityException {
        int i;
        Enumeration e = mySubContexts.elements();

        while (e.hasMoreElements()) {
            ISecurityContext sctx = ((Entry) e.nextElement()).getCtx();
            // The principal and credential are now set for all subcontexts in Authentication
            try {
                if (sctx instanceof IParentAwareSecurityContext) {
                    ((IParentAwareSecurityContext) sctx).authenticate(this);
                } else {
                    sctx.authenticate();
                }
            } catch (Exception ex) {
                log.error("Exception authenticating subcontext " + sctx, ex);
            }
            // Stop attempting to authenticate if authenticated and if the property flag is set
            if (stopWhenAuthenticated && sctx.isAuthenticated()) {
                break;
            }
        }

        // Zero out the actual credentials if it isn't already null
        if (this.myOpaqueCredentials.credentialstring != null) {
            for (i = 0; i < this.myOpaqueCredentials.credentialstring.length; i++)
                this.myOpaqueCredentials.credentialstring[i] = 0;
            myOpaqueCredentials.credentialstring = null;
        }

        return;
    }
1104511
public OvhApplication api_credential_credentialId_application_GET(Long credentialId) throws IOException {
		String qPath = "/me/api/credential/{credentialId}/application";
		StringBuilder sb = path(qPath, credentialId);
		String resp = exec(qPath, "GET", sb.toString(), null);
		return convertTo(resp, OvhApplication.class);
	}
255830
public Credential getSingleSignOn(HttpRequest request,
                                      HttpResponse response)
    {
        String ssoID = null;
        Cookie[] cookies = request.getCookies();
        for (int i = 0; i < cookies.length; i++)
        {
            if (cookies[i].getName().equals(SSO_COOKIE_NAME))
            {
                ssoID = cookies[i].getValue();
                break;
            }
        }
        if(log.isDebugEnabled())log.debug("get ssoID="+ssoID);
        
        Principal principal=null;
        Credential credential=null;
        synchronized(_ssoId2Principal)
        {
            principal=(Principal)_ssoId2Principal.get(ssoID);
            credential=(Credential)_ssoPrincipal2Credential.get(principal);
        }
        
        if(log.isDebugEnabled())log.debug("SSO principal="+principal);
        
        if (principal!=null && credential!=null)
        {
            if (response.getHttpContext().getRealm().reauthenticate(principal))
            {
                request.setUserPrincipal(principal);
                request.setAuthUser(principal.getName());
                return credential;
            }
            else
            {
                synchronized(_ssoId2Principal)
                {
                    _ssoId2Principal.remove(ssoID);
                    _ssoPrincipal2Credential.remove(principal);
                    _ssoUsername2Id.remove(principal.getName());
                }    
            }
        }
        return null;
    }
164783
protected Service restoreAuthenticationRequestInContext(final RequestContext requestContext,
                                                            final J2EContext webContext,
                                                            final String clientName) {
        val logoutEndpoint = isLogoutRequest(webContext.getRequest());
        if (logoutEndpoint) {
            return null;
        } else {
            try {
                val client = (BaseClient<Credentials, CommonProfile>) this.clients.findClient(clientName);
                return delegatedClientWebflowManager.retrieve(requestContext, webContext, client);
            } catch (final Exception e) {
                LOGGER.error(e.getMessage(), e);
            }
            throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, "Service unauthorized");
        }
    }
928067
@Override
    public IOpaqueCredentials getOpaqueCredentials() {
        if (parentContext != null && parentContext.isAuthenticated()) {
            NotSoOpaqueCredentials oc = new CacheOpaqueCredentials();
            oc.setCredentials(this.cachedcredentials);
            return oc;
        } else return null;
    }
1092695
@Override
	public SecurityContext getContext(String userName, String password) throws FFMQSecurityException 
	{
		if (userName == null)
			throw new FFMQSecurityException("User name not specified","INVALID_SECURITY_DESCRIPTOR");
		
		// Check user and password
		User user = descriptor.getUser(userName);
        if (user == null || !user.getPassword().equals(password))
            throw new FFMQSecurityException("Invalid user/password","INVALID_SECURITY_DESCRIPTOR");
        
        return user;
	}
991322
public static Span getValue(Context context) {
    @javax.annotation.Nullable
    Span span = CONTEXT_SPAN_KEY.get(Utils.checkNotNull(context, "context"));
    return span == null ? BlankSpan.INSTANCE : span;
  }
1278527
public <R> R accessContext(ContextAccess<C,R> access)
    {
        contextLock.lock();
        try
        {
            return access.access(context);
        }
        finally
        {
            contextLock.unlock();
        }
    }
646108
public URI getLoginRequestURIForContext(Context ctx) {
		if (!(ctx.getAuthenticationMethod() instanceof FormBasedAuthenticationMethod))
			return null;
		FormBasedAuthenticationMethod method = (FormBasedAuthenticationMethod) ctx.getAuthenticationMethod();
		try {
			return new URI(method.getLoginRequestURL(), false);
		} catch (URIException | NullPointerException e) {
			e.printStackTrace();
			return null;
		}
	}
718052
public static Authentication getCurrentAuthentication() {
        RequestContext context = RequestContext.getCurrent();
        if (context != null) {
            return getAuthentication(context.getRequest());
        } else {
            return null;
        }
    }
276228
public synchronized EvaluatorContext getContext(final String contextId) {
    for (final EvaluatorContext context : this.contextStack) {
      if (context.getId().equals(contextId)) {
        return context;
      }
    }
    throw new RuntimeException("Unknown evaluator context " + contextId);
  }
1157884
public Context getContext() {
		if (context == null) {
			context = Model.getSingleton().getSession().getContext(this.contextId);
		}
		return context;
	}
1020443
public static RpcInvokeContext getContext() {
        RpcInvokeContext context = LOCAL.get();
        if (context == null) {
            context = new RpcInvokeContext();
            LOCAL.set(context);
        }
        return context;
    }
267079
public static function get(string $credential, $default=null) {
		// return said credential or default if not authenticated or credential does not exist
		return(
			self::$_account && self::$_account->get($credential) ? 
			self::$_account->get($credential) : $default
		);
	}
779003
public static Credential getServiceAccountCredential(String serviceAccountId,
      String privateKeyFile) throws GeneralSecurityException, IOException {
    return getServiceAccountCredential(serviceAccountId, privateKeyFile, DatastoreOptions.SCOPES);
  }
193495
public InitialContext getInitialContext() throws ControlException {
        if (_initialContext != null) {
            return _initialContext;
        }
        Properties props = (Properties) _context.getControlPropertySet(Properties.class);
        String url = nullIfEmpty(props.url());
        String factory = nullIfEmpty(props.factory());
        if (url == null && factory == null) {
            try {
                return new InitialContext();
            }
            catch (NamingException e) {
                throw new ControlException("Cannot get default JNDI initial context", e);
            }

        }
        if (url == null || factory == null) {
            throw new ControlException("Both the provider-url and jndi factory need to be provided");

        }
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, factory);
        env.put(javax.naming.Context.PROVIDER_URL, url);

        String username = nullIfEmpty(props.jndiSecurityPrincipal());
        if (username != null)
            env.put(javax.naming.Context.SECURITY_PRINCIPAL, username);

        String password = nullIfEmpty(props.jndiSecurityCredentials());
        if (password != null)
            env.put(javax.naming.Context.SECURITY_CREDENTIALS, password);

        try {
            return _initialContext = new InitialContext(env);
        }
        catch (NamingException e) {
            throw new ControlException("Cannot get JNDI initial context at provider '" + url + "' with factory '" + factory + "'", e);
        }
    }