private void handleKeyfile()

in redback-authentication/redback-authentication-providers/redback-authentication-jwt/src/main/java/org/apache/archiva/redback/authentication/jwt/JwtAuthenticator.java [345:412]


    private void handleKeyfile( )
    {
        if ( !Files.exists( this.keystoreFilePath ) )
        {
            final Long keyId = addNewKey( );
            if ( this.symmetricAlgorithm )
            {
                try
                {
                    writeSecretKey( this.keystoreFilePath, keyId, getSecretKey( keyId ) );
                }
                catch ( IOException e )
                {
                    log.error( "Could not write Jwt key file {}: {}", this.keystoreFilePath, e.getMessage( ), e );
                    log.warn( "Switching to in memory key handling " );
                    this.fileStore = false;
                }
            }
            else
            {
                try
                {
                    writeKeyPair( this.keystoreFilePath, keyId, getKeyPair( keyId ) );
                }
                catch ( IOException e )
                {
                    log.error( "Could not write Jwt key file {}: {}", this.keystoreFilePath, e.getMessage( ), e );
                    log.warn( "Switching to in memory key handling " );
                    this.fileStore = false;
                }
            }
        }
        else
        {
            if ( this.symmetricAlgorithm )
            {
                try
                {
                    final KeyHolder key = loadKeyFromFile( this.keystoreFilePath );
                    keyCounter.set( key.getId() );
                    addNewSecretKey( key.getId(), key.getSecretKey() );
                }
                catch ( IOException e )
                {
                    log.error( "Could not read Jwt key file {}: {}", this.keystoreFilePath, e.getMessage( ), e );
                    log.warn( "Switching to in memory key handling " );
                    this.fileStore = false;
                    addNewKey( );
                }
            }
            else
            {
                try
                {
                    final KeyHolder pair = loadPairFromFile( this.keystoreFilePath );
                    keyCounter.set( pair.getId() );
                    addNewKeyPair( pair.getId(), pair.getKeyPair() );
                }
                catch ( Exception e )
                {
                    log.error( "Could not read Jwt key file {}: {}", this.keystoreFilePath, e.getMessage( ), e );
                    log.warn( "Switching to in memory key handling " );
                    this.fileStore = false;
                    addNewKey( );
                }
            }
        }
    }