Builds JWT object.

@param credential
@return
@throws AuthenticationException
507534
static ClientAssertion buildJwt(final AsymmetricKeyCredential credential,
            final String jwtAudience) throws AuthenticationException {
        if (credential == null) {
            throw new IllegalArgumentException("credential is null");
        }

        final long time = System.currentTimeMillis();

        final JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
                .audience(Collections.singletonList(jwtAudience))
                .issuer(credential.getClientId())
                .jwtID(UUID.randomUUID().toString())
                .notBeforeTime(new Date(time))
                .expirationTime(new Date(time
                                + AuthenticationConstants.AAD_JWT_TOKEN_LIFETIME_SECONDS
                                * 1000))
                .subject(credential.getClientId())
                .build();

        SignedJWT jwt;
        try {
            JWSHeader.Builder builder = new Builder(JWSAlgorithm.RS256);
            List<Base64> certs = new ArrayList<Base64>();
            certs.add(new Base64(credential.getPublicCertificate()));
            builder.x509CertChain(certs);
            builder.x509CertThumbprint(new Base64URL(credential
                    .getPublicCertificateHash()));
            jwt = new SignedJWT(builder.build(), claimsSet);
            final RSASSASigner signer = new RSASSASigner(credential.getKey());

            jwt.sign(signer);
        }
        catch (final Exception e) {
            throw new AuthenticationException(e);
        }

        return new ClientAssertion(jwt.serialize());
    }
716541
public <T extends AbstractGoogleJsonClient.Builder> T fromCredential(T builder, Credential credential) {
    Preconditions.checkNotNull(builder);
    Preconditions.checkNotNull(credential);
    return prepareBuilder(builder, credential, null);
  }
1284308
@Override
    public Subject createHashtableInSubject(String username, @Sensitive String password) throws AuthenticationException {
        UsernamePasswordCredential credential = new UsernamePasswordCredential(username, password);
        return createHashtableInSubject(credential);
    }
282045
@Override
    public Subject authenticate(String username, @Sensitive String password) throws AuthenticationException {
        AuthenticationData authenticationData = createAuthenticationData(username, password);
        return authenticationService.authenticate(jaasEntryName, authenticationData, null);
    }
336199
protected AuthenticationHandlerExecutionResult createAuthenticatedSubjectResult(final Credential credential, final Subject currentUser) {
        val username = currentUser.getPrincipal().toString();
        return createHandlerResult(credential, this.principalFactory.createPrincipal(username));
    }
51391
public String generateJwt() throws NexmoUnacceptableAuthException {
        JWTAuthMethod authMethod = this.httpWrapper.getAuthCollection().getAuth(JWTAuthMethod.class);
        return authMethod.constructToken(System.currentTimeMillis() / 1000L, JWTAuthMethod.constructJTI());
    }
94134
@Nullable
    public final Credentials toCredentials(final AuthScope authscope) {
        try {

            if (!matches(MatchInfo.fromAuthScope(authscope))) {
                return null;
            }
        } catch (UnknownHostException | MalformedURLException | SocketException e) {
            throw new RuntimeException(e);
        }
        if (this.username == null) {
            return null;
        }

        final String passwordString;
        if (this.password != null) {
            passwordString = new String(this.password);
        } else {
            passwordString = null;
        }
        return new UsernamePasswordCredentials(this.username, passwordString);
    }
1043007
@Override
  public boolean canAuthenticate(String resource) {
    if (resource == null) {
      return false;
    }

    ClientCredential credential = getCredentialForResource(resource);
    return credential != null;
  }
1087554
public String login(Authentication authentication) {
		String token = getToken();
		return login(token, authentication);
	}
1429
@Override
    public Subject authenticate(@Sensitive byte[] tokenBytes) throws AuthenticationException {
        AuthenticationData authenticationData = createAuthenticationData(tokenBytes);
        return authenticationService.authenticate(jaasEntryName, authenticationData, null);
    }
1225420
public static DefaultAuthenticationTransaction of(final Service service, final Credential... credentials) {
        val creds = sanitizeCredentials(credentials);
        return new DefaultAuthenticationTransaction(service, creds);
    }
895415
@Override
    public JwtToken buildJwt() throws JwtException, InvalidBuilderException {
        // Create JWT here
        // TODO check for default claims?
        JwtConfig config = getConfig(configId);
        JwtToken jwt = new TokenImpl(this, config);

        return jwt;
    }
824692
private static CredentialsProvider buildCredentialProvider(
      CredentialOptions credentialOptions) throws IOException {
    try {
      final Credentials credentials = CredentialFactory.getCredentials(credentialOptions);
      if (credentials == null) {
        LOG.info("Enabling the use of null credentials. This should not be used in production.");
        return NoCredentialsProvider.create();
      }

      return FixedCredentialsProvider.create(credentials);
    } catch (GeneralSecurityException exception) {
      throw new IOException("Could not initialize credentials.", exception);
    }
  }
568300
public login login(String username, String password) throws Exception
	{
		this.set_credential(username, password);
		return this.login();
	}
334447
@Override
    public void setCredential(Subject subject) throws CredentialException {
        Hashtable<String, ?> customProperties = getBasicAuthHashtableFromSubject(subject);
        try {
            // Hashtable with basic auth information, all properties must be there.
            if (customProperties != null && !customProperties.isEmpty() && customProperties.size() == 3) {
                String realm = getRealm(customProperties);
                String securityName = getSecurityName(customProperties);
                SerializableProtectedString password = getPassword(customProperties);
                setBasicAuthCredential(subject, realm, securityName, password);
            }
        } finally {
            removeBasicAuthHashtable(subject, customProperties);
        }
    }
1340945
public function setCredentialObject(TokenCredential $credential, $userId = null, $default = true)
    {
        $key = $userId == null ? 'default' : $userId;
        $this->credentialHashmap[$key] = $credential;
        if ($default) {
            $this->defaultAccountName = $key;
        }
        return $this;
    }
1035314
public String login(String token, Authentication authentication) {
		if (null == token) {
			return login(authentication);
		}
		tokens.put(token, new TokenContainer(authentication));
		return token;
	}