Saves given creds in jenkins for domain extracted from server api url

@param serverAPIUrl to extract (and create if no any) domain
@param credentials  creds to save

@return saved creds
552421
private StandardCredentials createCredentials(@Nonnull String serverAPIUrl,
                                                  final StandardCredentials credentials) {
        URI serverUri = URI.create(defaultIfBlank(serverAPIUrl, GITHUB_URL));

        List<DomainSpecification> specifications = asList(
                new SchemeSpecification(serverUri.getScheme()),
                new HostnameSpecification(serverUri.getHost(), null)
        );

        final Domain domain = new Domain(serverUri.getHost(), "GitHub domain (autogenerated)", specifications);
        ACL.impersonate(ACL.SYSTEM, new Runnable() { // do it with system rights
            @Override
            public void run() {
                try {
                    new SystemCredentialsProvider.StoreImpl().addDomain(domain, credentials);
                } catch (IOException e) {
                    LOGGER.error("Can't add creds for domain", e);
                }
            }
        });

        return credentials;
    }
1192523
SamlIdentityProviderConfig build(CredentialResolverAdapter credentialResolver) {
        checkState(entityId != null, "entity ID of the identity provider is not set");

        // Use the entityId as a default key name.
        final Credential signing = credentialResolver.apply(firstNonNull(signingKey, entityId));
        final Credential encryption = credentialResolver.apply(firstNonNull(encryptionKey, entityId));

        return new SamlIdentityProviderConfig(entityId,
                                              signing,
                                              encryption,
                                              ssoEndpoint,
                                              sloReqEndpoint,
                                              sloResEndpoint,
                                              acsEndpoint,
                                              nameIdPolicy);
    }
1271754
public static ClientCredentials loadFromMap(Map<String, Object> map) {
        ClientCredentials creds = new ClientCredentials();
        creds.name = (String) map.get("name");
        creds.id = (String) map.get("_id");
        creds.secret = (String) map.get("secret");
        creds.uri = (String) map.get("uri");
        creds.descr = (String) map.get("descr");
        creds.type = ((Integer) map.get("type")).intValue();
        creds.status = ((Integer) map.get("status")).intValue();
        creds.created = (Long) map.get("created");
        creds.scope = (String) map.get("scope");
        if (map.get("applicationDetails") != null) {
            creds.applicationDetails = JsonUtils.convertStringToMap(map.get("applicationDetails").toString());
        }
        return creds;
    }
340637
public CredentialResolver build() throws IOException, GeneralSecurityException {
        final KeyStore ks = KeyStore.getInstance(type);
        try (InputStream is = open()) {
            ks.load(is, password != null ? password.toCharArray() : null);
        }
        return new KeyStoreCredentialResolver(ks, keyPasswords);
    }
889123
private void setCredential(Subject subject, WSPrincipal principal) throws CredentialException {
        String securityName = principal.getName();
        Hashtable<String, ?> customProperties = getUniqueIdHashtableFromSubject(subject);
        if (customProperties == null || customProperties.isEmpty()) {
            UserRegistryService urService = userRegistryServiceRef.getService();
            if (urService != null) {
                String urType = urService.getUserRegistryType();
                if ("WIM".equalsIgnoreCase(urType) || "LDAP".equalsIgnoreCase(urType)) {
                    try {
                        securityName = urService.getUserRegistry().getUserDisplayName(securityName);
                    } catch (Exception e) {
                        //do nothing
                    }
                }
            }
        }
        if (securityName == null || securityName.length() == 0) {
            securityName = principal.getName();
        }
        String accessId = principal.getAccessId();

        String customRealm = null;
        String realm = null;
        String uniqueName = null;

        if (customProperties != null) {
            customRealm = (String) customProperties.get(AttributeNameConstants.WSCREDENTIAL_REALM);
        }

        if (customRealm != null) {
            realm = customRealm;
            String[] parts = accessId.split(realm + "/");
            if (parts != null && parts.length == 2)
                uniqueName = parts[1];
        } else {
            realm = AccessIdUtil.getRealm(accessId);
            uniqueName = AccessIdUtil.getUniqueId(accessId);
        }
        if (AccessIdUtil.isServerAccessId(accessId)) {
            // Create a server WSCredential
            setCredential(null, subject, realm, securityName, uniqueName, null, accessId, null, null);
        } else {
            CredentialsService cs = credentialsServiceRef.getService();
            String unauthenticatedUserid = cs.getUnauthenticatedUserid();

            if (securityName != null && unauthenticatedUserid != null &&
                securityName.equals(unauthenticatedUserid)) {
                // Create an unauthenticated WSCredential
                setCredential(unauthenticatedUserid, subject, realm, securityName, uniqueName, null, null, null, null);
            } else if (AccessIdUtil.isUserAccessId(accessId)) {
                // Create a user WSCredential
                createUserWSCredential(subject, securityName, accessId, realm, uniqueName, unauthenticatedUserid);
            }
        }
    }
1220969
def set_credentials(username, api_key=None, password=None, region=None,
        tenant_id=None, authenticate=True):
    
    global regions, services
    pw_key = password or api_key
    region = _safe_region(region)
    tenant_id = tenant_id or settings.get("tenant_id")
    identity.set_credentials(username=username, password=pw_key,
            tenant_id=tenant_id, region=region, authenticate=authenticate)
    regions = tuple(identity.regions)
    services = tuple(identity.services.keys())
    connect_to_services(region=region)
588585
public static AWSCredentialsProvider getInstance(final String credentialAccessKey, final String credentialSecretKey,
                                                     final Resource credentialPropertiesFile) {
        return getInstance(credentialAccessKey, credentialSecretKey, credentialPropertiesFile, null, null);
    }
1142010
def from_credentials(credentials):
        
        return API(username=credentials.username, password=credentials.password,
                   database=credentials.database, session_id=credentials.session_id,
                   server=credentials.server)
617329
@Nonnull
  public static AuthIdentificationResult validateLoginCredentialsAndCreateToken (@Nonnull final IAuthCredentials aCredentials)
  {
    ValueEnforcer.notNull (aCredentials, "Credentials");

    // validate credentials
    final ICredentialValidationResult aValidationResult = AuthCredentialValidatorManager.validateCredentials (aCredentials);
    if (aValidationResult.isFailure ())
    {
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn ("Credentials have been rejected: " + aCredentials);
      return AuthIdentificationResult.createFailure (aValidationResult);
    }

    if (LOGGER.isDebugEnabled ())
      LOGGER.debug ("Credentials have been accepted: " + aCredentials);

    // try to get AuthSubject from passed credentials
    final IAuthSubject aSubject = AuthCredentialToSubjectResolverManager.getSubjectFromCredentials (aCredentials);
    if (aSubject != null)
    {
      if (LOGGER.isDebugEnabled ())
        LOGGER.debug ("Credentials " + aCredentials + " correspond to subject " + aSubject);
    }
    else
    {
      if (LOGGER.isErrorEnabled ())
        LOGGER.error ("Failed to resolve credentials " + aCredentials + " to an auth subject!");
    }

    // Create the identification element
    final AuthIdentification aIdentification = new AuthIdentification (aSubject);

    // create the token (without expiration seconds)
    final IAuthToken aNewAuthToken = AuthTokenRegistry.createToken (aIdentification,
                                                                    IAuthToken.EXPIRATION_SECONDS_INFINITE);
    return AuthIdentificationResult.createSuccess (aNewAuthToken);
  }
941887
def from_credentials(credentials, loop: asyncio.AbstractEventLoop=asyncio.get_event_loop()):
        
        return API(username=credentials.username, password=credentials.password,
                   database=credentials.database, session_id=credentials.session_id,
                   server=credentials.server, loop=loop)
1138977
def save_password(url, username, password):
    """"""
    if keyring:
        if ":" in username:
            raise RuntimeError(
                "Unable to store credentials if username contains a ':' ({}).".format(
                    username
                )
            )

        try:
            # Note: we pass the url as `username` and username:password as `password`
            if password is None:
                keyring.delete_password("pyftpsync", url)
                write("Delete credentials from keyring ({})".format(url))
            else:
                keyring.set_password(
                    "pyftpsync", url, "{}:{}".format(username, password)
                )
                write(
                    "Store credentials in keyring ({}, {}:***).".format(url, username)
                )
        #        except keyring.errors.TransientKeyringError:
        except Exception as e:
            write("Could not delete/set password {}.".format(e))
            pass  # e.g. user clicked 'no'
    else:
        write("Could not store credentials (missing keyring support).")
    return
711158
@Override
    protected String extractPrincipalId(final Credential credentials, final Optional<Principal> currentPrincipal) {
        val wsFedCredentials = (WsFederationCredential) credentials;
        val attributes = wsFedCredentials.getAttributes();
        LOGGER.debug("Credential attributes provided are: [{}]", attributes);
        val idAttribute = this.configuration.getIdentityAttribute();
        if (attributes.containsKey(idAttribute)) {
            LOGGER.debug("Extracting principal id from attribute [{}]", this.configuration.getIdentityAttribute());
            val idAttributeAsList = CollectionUtils.toCollection(attributes.get(this.configuration.getIdentityAttribute()));
            if (idAttributeAsList.size() > 1) {
                LOGGER.warn("Found multiple values for id attribute [{}].", idAttribute);
            } else {
                LOGGER.debug("Found principal id attribute as [{}]", idAttributeAsList);
            }

            val result = CollectionUtils.firstElement(idAttributeAsList);
            if (result.isPresent()) {
                val principalId = result.get().toString();
                LOGGER.debug("Principal Id extracted from credentials: [{}]", principalId);
                return principalId;
            }
        }
        LOGGER.warn("Credential attributes do not include an attribute for [{}]. "
            + "This will prohibit CAS to construct a meaningful authenticated principal. "
            + "Examine the released claims and ensure [{}] is allowed", idAttribute, idAttribute);
        return null;
    }
996929
protected AuthenticationHandlerExecutionResult createResult(final ClientCredential credentials, final UserProfile profile,
                                                                final BaseClient client) throws GeneralSecurityException {
        if (profile == null) {
            throw new FailedLoginException("Authentication did not produce a user profile for: " + credentials);
        }

        val id = determinePrincipalIdFrom(profile, client);
        if (StringUtils.isBlank(id)) {
            throw new FailedLoginException("No identifier found for this user profile: " + profile);
        }
        credentials.setUserProfile(profile);
        credentials.setTypedIdUsed(isTypedIdUsed);
        val attributes = CoreAuthenticationUtils.convertAttributeValuesToMultiValuedObjects(profile.getAttributes());
        val principal = this.principalFactory.createPrincipal(id, attributes);
        LOGGER.debug("Constructed authenticated principal [{}] based on user profile [{}]", principal, profile);
        return finalizeAuthenticationHandlerResult(credentials, principal, profile, client);
    }
959887
@SuppressWarnings("unchecked")
    protected Credentials getCredentials(Map<String, String> credentials) {
        Credentials credential = null;
        if (credentials != null && credentials.containsKey(getCredentialKey())) {
            try {
                byte[] credBytes = DatatypeConverter.parseBase64Binary(credentials.get(getCredentialKey()));
                ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(credBytes));

                credential = new Credentials();
                credential.readFields(in);
            } catch (Exception e) {
                LOG.error("Could not obtain credentials from credentials map.", e);
            }
        }
        return credential;
    }
1073018
protected AuthenticationHandlerExecutionResult finalizeAuthenticationHandlerResult(final ClientCredential credentials,
                                                                                       final Principal principal,
                                                                                       final UserProfile profile,
                                                                                       final BaseClient client) {
        preFinalizeAuthenticationHandlerResult(credentials, principal, profile, client);
        return createHandlerResult(credentials, principal, new ArrayList<>(0));
    }
279311
public GlobusCredential createCredential(X509Certificate[] certs, PrivateKey privateKey, int bits, int lifetime,
        int delegationMode) throws GeneralSecurityException {
        return createCredential(certs, privateKey, bits, lifetime, delegationMode, (X509ExtensionSet) null, null);
    }
790410
public static Credential credential(
      AccessTokenProvider accessTokenProvider, Collection<String> scopes)
      throws IOException, GeneralSecurityException {
    return getCredentialFromAccessTokenProvider(accessTokenProvider, scopes);
  }