Revision history for Perl extension Catalyst::Plugin::Authentication
+ - Add a username_field config item to ::Credential::Remote
+ (Nigel Metheringham)
- Die with a useful error message if we are about to try to restore
a user from a realm which does not exist. (t0m)
use base 'Class::Accessor::Fast';
BEGIN {
- __PACKAGE__->mk_accessors(qw/allow_re deny_re cutname_re source realm/);
+ __PACKAGE__->mk_accessors(
+ qw/allow_re deny_re cutname_re source realm username_field/);
}
sub new {
my $self = { };
bless $self, $class;
-
+
# we are gonna compile regular expresions defined in config parameters
# and explicitly throw an exception saying what parameter was invalid
if (defined($config->{allow_regexp}) && ($config->{allow_regexp} ne "")) {
}
$self->source($config->{source} || 'REMOTE_USER');
$self->realm($realm);
+ $self->username_field($config->{username_field} || 'username');
return $self;
}
}
}
- $authinfo->{id} = $authinfo->{username} = $usr;
+ $authinfo->{id} = $authinfo->{ $self->username_field } = $usr;
$authinfo->{remote_user} = $remuser; # just to keep the original value
my $user_obj = $realm->find_user( $authinfo, $c );
return ref($user_obj) ? $user_obj : undef;
match cutname_regexp at all or if '$1' regexp substring is empty we pass the
original WEBUSER value (without cutting) to Catalyst application.
+=head2 username_field
+
+This config item is B<OPTIONAL> - default is I<username>
+
+The key name in the authinfo hash that the user's username is mapped into.
+This is useful for using a store which requires a specific unusual field name
+for the username. The username is additionally mapped onto the I<id> key.
+
=head1 METHODS
=head2 new ( $config, $app, $realm )
deny_regexp=> 'denied',
cutname_regexp=> 'CN=(.*)/OU=Test',
source => 'SSL_CLIENT_S_DN',
+ username_field => 'my_user_name',
},
store => {
class => 'Null',
sub default : Local {
my ( $self, $c ) = @_;
if ($c->authenticate()) {
- $c->res->body('User:' . $c->user->{id});
+ $c->res->body( 'User:'
+ . $c->user->{id} . "\n"
+ . 'my_user_name:'
+ . $c->user->{my_user_name} );
}
else {
$c->res->body('FAIL');
$RemoteTestEngine::SSL_CLIENT_S_DN = 'CN=namexyz/OU=Test/C=Company';
ok( request('/')->is_success, 'testing "source" + "cutname" 1' );
-is( request('/')->content, 'User:namexyz', 'testing "source" + "cutname" 2' );
+is( request('/')->content, "User:namexyz\nmy_user_name:namexyz",
+ 'testing "source" + "cutname" 2' );