iiop-openjdk/src/main/java/org/wildfly/iiop/openjdk/csiv2/ElytronSASClientInterceptor.java
private byte[] createInitialContextToken(final URI uri, final CompoundSecMech secMech) throws Exception {

        AuthenticationContext authContext = this.authContext == null ? AuthenticationContext.captureCurrent() : this.authContext;
        // obtain the configuration that matches the URI.
        final AuthenticationConfiguration configuration = AUTH_CONFIG_CLIENT.getAuthenticationConfiguration(uri, authContext, -1, null, null);

        // get the callback handler from the configuration and use it to obtain a username/password pair.
        final CallbackHandler handler = AUTH_CONFIG_CLIENT.getCallbackHandler(configuration);
        final NameCallback nameCallback = new NameCallback("Username: ");
        final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
        try {
            handler.handle(new Callback[]{nameCallback, passwordCallback});
        } catch (UnsupportedCallbackException e) {
            return NO_AUTHENTICATION_TOKEN;
        }

        // if the name callback contains a valid username we create the initial context token.
        if (nameCallback.getName() != null && !nameCallback.getName().equals(AnonymousPrincipal.getInstance().getName())) {
            byte[] encodedTargetName = secMech.as_context_mech.target_name;
            String name = nameCallback.getName();
            if (name.indexOf('@') < 0) {
                byte[] decodedTargetName = CSIv2Util.decodeGssExportedName(encodedTargetName);
                String targetName = new String(decodedTargetName, StandardCharsets.UTF_8);
                name += "@" + targetName; // "@default"
            }
            byte[] username = name.getBytes(StandardCharsets.UTF_8);
            byte[] password = {};
            if (passwordCallback.getPassword() != null)
                password = new String(passwordCallback.getPassword()).getBytes(StandardCharsets.UTF_8);

            // create the initial context token and ASN.1-encode it, as defined in RFC 2743.
            InitialContextToken authenticationToken = new InitialContextToken(username, password, encodedTargetName);
            return CSIv2Util.encodeInitialContextToken(authenticationToken, codec);
        }
        return NO_AUTHENTICATION_TOKEN;
    }
private byte[] createInitialContextToken(final URI uri, final CompoundSecMech secMech) throws Exception {

        AuthenticationContext authContext = this.authContext == null ? AuthenticationContext.captureCurrent() : this.authContext;
        // obtain the configuration that matches the URI.
        final AuthenticationConfiguration configuration = AUTH_CONFIG_CLIENT.getAuthenticationConfiguration(uri, authContext, -1, null, null);

        // get the callback handler from the configuration and use it to obtain a username/password pair.
        final CallbackHandler handler = AUTH_CONFIG_CLIENT.getCallbackHandler(configuration);
        final NameCallback nameCallback = new NameCallback("Username: ");
        final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
        try {
            handler.handle(new Callback[]{nameCallback, passwordCallback});
        } catch (UnsupportedCallbackException e) {
            return NO_AUTHENTICATION_TOKEN;
        }

        // if the name callback contains a valid username we create the initial context token.
        if (nameCallback.getName() != null && !nameCallback.getName().equals(AnonymousPrincipal.getInstance().getName())) {
            byte[] encodedTargetName = secMech.as_context_mech.target_name;
            String name = nameCallback.getName();
            if (name.indexOf('@') < 0) {
                byte[] decodedTargetName = CSIv2Util.decodeGssExportedName(encodedTargetName);
                String targetName = new String(decodedTargetName, StandardCharsets.UTF_8);
                name += "@" + targetName; // "@default"
            }
            byte[] username = name.getBytes(StandardCharsets.UTF_8);
            byte[] password = {};
            if (passwordCallback.getPassword() != null)
                password = new String(passwordCallback.getPassword()).getBytes(StandardCharsets.UTF_8);

            // create the initial context token and ASN.1-encode it, as defined in RFC 2743.
            InitialContextToken authenticationToken = new InitialContextToken(username, password, encodedTargetName);
            return CSIv2Util.encodeInitialContextToken(authenticationToken, codec);
        }
        return NO_AUTHENTICATION_TOKEN;
    }
private byte [ ] createInitialContextToken ( final URI uri , final CompoundSecMech secMech ) throws Exception { AuthenticationContext authContext = this . authContext == null ? AuthenticationContext . captureCurrent ( ) : this . authContext ; // obtain the configuration that matches the URI. final AuthenticationConfiguration configuration = AUTH_CONFIG_CLIENT . getAuthenticationConfiguration ( uri , authContext , - 1 , null , null ) ; // get the callback handler from the configuration and use it to obtain a username/password pair. final CallbackHandler handler = AUTH_CONFIG_CLIENT . getCallbackHandler ( configuration ) ; final NameCallback nameCallback = new NameCallback ( "Username: " ) ; final PasswordCallback passwordCallback = new PasswordCallback ( "Password: " , false ) ; try { handler . handle ( new Callback [ ] { nameCallback , passwordCallback } ) ; } catch ( UnsupportedCallbackException e ) { return NO_AUTHENTICATION_TOKEN ; } // if the name callback contains a valid username we create the initial context token. if ( nameCallback . getName ( ) != null && ! nameCallback . getName ( ) . equals ( AnonymousPrincipal . getInstance ( ) . getName ( ) ) ) { byte [ ] encodedTargetName = secMech . as_context_mech . target_name ; String name = nameCallback . getName ( ) ; if ( name . indexOf ( ' ' ) < 0 ) { byte [ ] decodedTargetName = CSIv2Util . decodeGssExportedName ( encodedTargetName ) ; String targetName = new String ( decodedTargetName , StandardCharsets . UTF_8 ) ; name += "@" + targetName ; // "@default" } byte [ ] username = name . getBytes ( StandardCharsets . UTF_8 ) ; byte [ ] password = { } ; if ( passwordCallback . getPassword ( ) != null ) password = new String ( passwordCallback . getPassword ( ) ) . getBytes ( StandardCharsets . UTF_8 ) ; // create the initial context token and ASN.1-encode it, as defined in RFC 2743. InitialContextToken authenticationToken = new InitialContextToken ( username , password , encodedTargetName ) ; return CSIv2Util . encodeInitialContextToken ( authenticationToken , codec ) ; } return NO_AUTHENTICATION_TOKEN ; }
Create an encoded {@link InitialContextToken} with an username/password pair obtained from an Elytron client configuration
matched by the specified {@link URI}.

@param uri the target {@link URI}.
@param secMech a reference to the {@link CompoundSecMech} that was found in the {@link ClientRequestInfo}.
@return the encoded {@link InitialContextToken}, if a valid username is obtained from the matched configuration;
an empty {@code byte[]} otherwise;
@throws Exception if an error occurs while building the encoded {@link InitialContextToken}.
Create an encoded { @link InitialContextToken } with an username / password pair obtained from an Elytron client configuration matched by the specified { @link URI } .