private Credentials getRFC2617Credentials()

in commons-transfer/commons-transfer-http/src/main/java/org/apache/archiva/commons/transfer/http/auth/HttpAuthStore.java [207:273]


    private Credentials getRFC2617Credentials( HttpAuthKey authKey, boolean proxy )
        throws CredentialsNotAvailableException
    {
        try
        {
            if ( getAuths().containsKey( authKey ) )
            {
                Credentials creds = getAuths().get( authKey );

                // Loaded from disk, but type unknown.
                if ( creds instanceof UndefinedCredentials )
                {
                    String storeKey = ( (UndefinedCredentials) creds ).getStoreKey();

                    // Make known.
                    SimpleCredentials simpleCreds = new SimpleCredentials();
                    simpleCreds.setUsername( getTransferStore().getString( NET_AUTH + storeKey + ".username", null ) );
                    simpleCreds.setPassword( getTransferStore().getPassword( NET_AUTH + storeKey + ".password" ) );

                    getAuths().put( authKey, simpleCreds );

                    fireAuthCredentialsProvided( authKey, simpleCreds, true );

                    return simpleCreds.toUsernamePasswordCredentials();
                }
                else if ( creds instanceof SimpleCredentials )
                {
                    fireAuthCredentialsProvided( authKey, creds, true );

                    return ( (SimpleCredentials) creds ).toUsernamePasswordCredentials();
                }
            }
        }
        catch ( ClassCastException e )
        {
            LOG.info( "Unable to use credentials from other auth scheme." );
        }

        if ( getTransferStore().isInteractive() )
        {
            HttpSimpleAuth auth = new HttpSimpleAuth();
            auth.setPersisted( false );
            auth.setKey( authKey );

            // Popup a dialog to gather auth.
            NetworkAuthDialog dialog = new NetworkAuthDialog();

            HttpSimpleAuth useauth = dialog.getAuth( auth );
            if ( useauth == null )
            {
                throw new CredentialsNotAvailableException( "Authentication credentials not provided." );
            }

            fireAuthCredentialsProvided( useauth.getKey(), useauth.getCredentials(), useauth.isPersisted() );

            if ( useauth.isPersisted() )
            {
                addAuth( useauth );
                save();
            }

            SimpleCredentials credentials = useauth.getCredentials();
            return credentials.toUsernamePasswordCredentials();
        }

        throw new CredentialsNotAvailableException( "No Authentication Provided." );
    }