OTRS CVS - Handbuch
Prev | Chapter 23. Entwicklerhandbuch - OTRS Module schreiben | Next

# Module zur Authentifizierung von Agenten

OTRS kommt bereits mit mehreren Module zur Authentifizierung von Agenten (DB, LDAP und HTTPBasicAuth). Darüber hinaus können Sie Ihre eigenen Module entwickeln.

Die Module befinden sich unter "Kernel/System/Auth/*.pm". Schauen Sie in der Konfigurationsdatei unter "User Auth Backend" nach.

Ein Beispiel eines einfachen Ticketnummer-Moduls, speichern Sie es unter Kernel/System/Auth/Simple.pm. Sie benötigen nur drei Funktionen, new(), GetOption() and Auth(). Die Authentifizierung ist erfolgreich, wenn Auth() wahr (also 'true') ist.

    # --
    # Kernel/System/Auth/Simple.pm - provides the db authentification
    # Copyright (C) 2001-2004 Martin Edenhofer martin+code at otrs.org
    # --
    # This software comes with ABSOLUTELY NO WARRANTY. For details, see
    # the enclosed file COPYING for license information (GPL). If you
    # did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
    # --
    # Note:
    # available objects are: ConfigObject, LogObject and DBObject
    # --

    package Kernel::System::Auth::Simple;

    use strict;

    # --
    sub new {
        my $Type = shift;
        my %Param = @_;

        # allocate new hash for object
        my $Self = {};
        bless ($Self, $Type);

        # check needed objects
        foreach (qw(LogObject ConfigObject DBObject)) {
            $Self->{$_} = $Param{$_} || die "No $_!";
        }

        # Debug 0=off 1=on
        $Self->{Debug} = 0;

        return $Self;
    }
    # --
    sub GetOption {
        my $Self = shift;
        my %Param = @_;
        # check needed stuff
        if (!$Param{What}) {
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need What!");
            return;
        }
        # module options
        my %Option = (
            PreAuth => 0,
        );
        # return option
        return $Option{$Param{What}};
    }
    # --
    sub Auth {
        my $Self = shift;
        my %Param = @_;
        # check needed stuff
        if (!$Param{User}) {
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need User!");
            return;
        }
        # get params
        my $User = $Param{User} || '';
        my $Pw = $Param{Pw} || '';
        my $RemoteAddr = $ENV{REMOTE_ADDR} || 'Got no REMOTE_ADDR env!';
        my $UserID = '';
        my $GetPw = '';
        # sql query
        my $SQL = "SELECT pw, user ".
          " FROM ".
          " users ".
          " WHERE ".
          " user = '$User'";
        $Self->{DBObject}->Prepare(SQL => $SQL);
        while (my @RowTmp = $Self->{DBObject}->FetchrowArray()) {
            $GetPw = $RowTmp[0];
            $UserID = $RowTmp[1];
        }

        my $Salt = $GetPw;
        $Salt =~ s/^(..).*/$1/;
        my $CryptedPw = crypt($Pw, $Salt);

        # just a note
        if (!$Pw) {
            $Self->{LogObject}->Log(
              Priority => 'notice',
              Message => "User: $User without Pw!!! (REMOTE_ADDR: $RemoteAddr)",
            );
            return;
        }
        # login note
        elsif ((($GetPw)&&($User)&&($UserID)) && $CryptedPw eq $GetPw) {
            $Self->{LogObject}->Log(
              Priority => 'notice',
              Message => "User: $User logged in (REMOTE_ADDR: $RemoteAddr).",
            );
            return $User;
        }
        # just a note
        elsif (($UserID) && ($GetPw)) {
            $Self->{LogObject}->Log(
              Priority => 'notice',
              Message => "User: $User with wrong Pw!!! (REMOTE_ADDR: $RemoteAddr)"
            );
            return;
        }
        # just a note
        else {
            $Self->{LogObject}->Log(
              Priority => 'notice',
              Message => "User: $User doesn't exist or is invalid!!! (REMOTE_ADDR: $RemoteAddr)"
            );
            return;
        }
    }
    # --

    1;

Prev | Home | Next
Ticketnummer Generator | Up | Module zur Authentifizierung von Kundenbenutzern