Advertisement
capitannemo

HTTPBasicAuth.pm

Nov 4th, 2012
1,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. # --
  2. # Kernel/System/Auth/HTTPBasicAuth.pm - provides the $ENV authentication
  3. # Copyright (C) 2001-2009 OTRS AG, http://otrs.org/
  4. # --
  5. # $Id: HTTPBasicAuth.pm,v 1.16 2009/09/22 15:19:27 mb Exp $
  6. # --
  7. # This software comes with ABSOLUTELY NO WARRANTY. For details, see
  8. # the enclosed file COPYING for license information (AGPL). If you
  9. # did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
  10. # --
  11. # Note:
  12. #
  13. # If you use this module, you should use as fallback the following
  14. # config settings:
  15. #
  16. # If use isn't login through apache ($ENV{REMOTE_USER} or $ENV{HTTP_REMOTE_USER})
  17. # $Self->{LoginURL} = 'http://host.example.com/not-authorised-for-otrs.html';
  18. #
  19. # $Self->{LogoutURL} = 'http://host.example.com/thanks-for-using-otrs.html';
  20. # --
  21.  
  22. package Kernel::System::Auth::HTTPBasicAuth;
  23.  
  24. use strict;
  25. use warnings;
  26. use Encode;
  27.  
  28. use vars qw($VERSION);
  29. $VERSION = qw($Revision: 1.16 $) [1];
  30.  
  31. sub new {
  32. my ( $Type, %Param ) = @_;
  33.  
  34. # allocate new hash for object
  35. my $Self = {};
  36. bless( $Self, $Type );
  37.  
  38. # check needed objects
  39. for (qw(LogObject ConfigObject DBObject)) {
  40. $Self->{$_} = $Param{$_} || die "No $_!";
  41. }
  42.  
  43. # Debug 0=off 1=on
  44. $Self->{Debug} = 0;
  45.  
  46. $Self->{Count} = $Param{Count} || '';
  47.  
  48. return $Self;
  49. }
  50.  
  51. sub GetOption {
  52. my ( $Self, %Param ) = @_;
  53.  
  54. # check needed stuff
  55. if ( !$Param{What} ) {
  56. $Self->{LogObject}->Log( Priority => 'error', Message => "Need What!" );
  57. return;
  58. }
  59.  
  60. # module options
  61. my %Option = ( PreAuth => 1, );
  62.  
  63. # return option
  64. return $Option{ $Param{What} };
  65. }
  66.  
  67. sub Auth {
  68. my ( $Self, %Param ) = @_;
  69.  
  70. # get params
  71. my $User = decode('cp1251',$ENV{REMOTE_USER} || $ENV{HTTP_REMOTE_USER});
  72. my $RemoteAddr = $ENV{REMOTE_ADDR} || 'Got no REMOTE_ADDR env!';
  73.  
  74. # return on no user
  75. if ( !$User ) {
  76. $Self->{LogObject}->Log(
  77. Priority => 'notice',
  78. Message =>
  79. "User: No \$ENV{REMOTE_USER} or \$ENV{HTTP_REMOTE_USER} !(REMOTE_ADDR: $RemoteAddr).",
  80. );
  81. return;
  82. }
  83.  
  84. # replace login parts
  85. my $Replace = $Self->{ConfigObject}->Get(
  86. 'AuthModule::HTTPBasicAuth::Replace' . $Self->{Count},
  87. );
  88. if ($Replace) {
  89. $User =~ s/^\Q$Replace\E//;
  90. }
  91.  
  92. # regexp on login
  93. my $ReplaceRegExp = $Self->{ConfigObject}->Get(
  94. 'AuthModule::HTTPBasicAuth::ReplaceRegExp' . $Self->{Count},
  95. );
  96. if ($ReplaceRegExp) {
  97. $User =~ s/$ReplaceRegExp/$1/;
  98. }
  99.  
  100. # log
  101. $Self->{LogObject}->Log(
  102. Priority => 'notice',
  103. Message => "User: $User authentication ok (REMOTE_ADDR: $RemoteAddr).",
  104. );
  105.  
  106. # return login
  107. return $User;
  108. }
  109.  
  110. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement