######################################################################
#
# EPrints::Apache::Auth
#
######################################################################
=pod

=head1 NAME

B<EPrints::Apache::Auth> - Password authentication & authorisation checking
for EPrints.

=head1 DESCRIPTION

This module corrects the authentication and authorisation of users

=over 4

=cut
######################################################################

package EPrints::Plugin::Auth;

use strict;

our @ISA = ( 'EPrints::Plugin' );

package EPrints::Apache::Auth;
BEGIN { delete $EPrints::Apache::Auth::{authen}; }

sub authen
{
	my( $r, $realm ) = @_;

	$r->user("");

	return OK unless $r->is_initial_req; # only the first internal request
	
	my $repository = $EPrints::HANDLE->current_repository;
	if( !defined $repository )
	{
		return FORBIDDEN;
	}

	my $rc;
	if( !_use_auth_basic( $r, $repository ) )
	{
		$rc = auth_cookie( $r, $repository );
	}
	else
	{
		$rc = auth_basic( $r, $repository, $realm );
	}

	return $rc;
}
