public AuthInfo getSecurityToken()

in src/main/java/com/amazonaws/kinesisvideo/auth/DefaultAuthCallbacks.java [72:127]


    public AuthInfo getSecurityToken() {
        final Runnable task = new Runnable() {
            @Override
            public void run() {
                // Get the updated credentials and serialize it

                final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                try {
                    final KinesisVideoCredentials credentials = credentialsProvider.getUpdatedCredentials();
                    expiration = credentials.getExpiration().getTime() * Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;

                    final ObjectOutput outputStream = new ObjectOutputStream(byteArrayOutputStream);
                    outputStream.writeObject(credentials);
                    outputStream.flush();
                    serializedCredentials = byteArrayOutputStream.toByteArray();
                    outputStream.close();
                } catch (final IOException e) {
                    // return null
                    serializedCredentials = null;
                    expiration = 0;
                    log.exception(e, "Exception was thrown trying to get updated credentials");
                } catch (final KinesisVideoException e) {
                    // return null
                    serializedCredentials = null;
                    expiration = 0;
                    log.exception(e, "Exception was thrown trying to get updated credentials");
                } finally {
                    try {
                        byteArrayOutputStream.close();
                    }
                    catch(final IOException e) {
                        // Do nothing
                        log.exception(e, "Closing the byte array stream threw an exception");
                    }
                }
            }
        };

        final ScheduledFuture<?> future = executor.schedule(task, 0, TimeUnit.NANOSECONDS);

        // Await for the future to complete
        try {
            future.get(CREDENTIALS_UPDATE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        } catch (final InterruptedException e) {
            log.exception(e, "Awaiting for the credentials update threw an exception");
        } catch (final ExecutionException e) {
            log.exception(e, "Awaiting for the credentials update threw an exception");
        } catch (final TimeoutException e) {
            log.exception(e, "Awaiting for the credentials update threw an exception");
        }

        return new AuthInfo(
                AuthInfoType.SECURITY_TOKEN,
                serializedCredentials,
                expiration);
    }