Kernel::System::Credential

NAME

Kernel::System::Credential – Management class for credential entries

ATTRIBUTES

Types

Hash reference with available credential module namespaces.

 Types = {
          'Certificate' => [],
          'BasicAuth' => [],
          'OAuth2' => [
                        'Google',
                        'MicrosoftGraphApp',
                        'MicrosoftGraphUser',
                        'ResourceOwnerPassword',
                        'ResourceOwnerPasswordBasicAuth'
                      ]
        };

and it grows when adding Modules pm files

CacheTTL

Attribute that holds the time to live value for the caching mechanism.

METHODS

MethodParamValidationSchema

Definition of the parameter validation schema.

Lookup()

Lookup the id or name for a credential entry.

    my $Name = $CredentialManager->Lookup(
        ID => $ID,
    );

    my $ID = $CredentialManager->Lookup(
        Name => $Name,
    );

ListTypes()

Get a list of types.

    my $TypeList = $CredentialManager->ListTypes(
        Templates => 0|1 # also list Templates of Types
    );

Returns a array reference if Templates == 0

    $TypeList = [
        { Name => '...', Label => '...', Module => '...', GroupLabel => '...' },
    ];

Returns a hash reference if Template == 1

    $TypeList = {
        'MainTypeName' => [
            # First position corresponds to the main one
            { Name => '...', Label => '...', Module => '...', GroupLabel => '...' },
            { Name => '...', Label => '...', Module => '...', GroupLabel => '...' },
            { Name => '...', Label => '...', Module => '...', GroupLabel => '...' },
        ],
    }

List()

Get a list of credential id's and names.

    my $FieldList = $CredentialManager->FieldList(

        # optional, 'ARRAY' or 'HASH', defaults to 'ARRAY'
        ResultType => 'HASH',

        # optional, filter by field parameters
        Filter => {

            # optional, defaults to 1
            Valid      => 0,

            # optional, can be either a string or an array reference of strings
            Type => 'BasicAuth',
            Type => ['BasicAuth', 'OAuth2', 'OAuth2::Google'],

            # optional, type match
            TypeMatch => 'OAuth2',
        },
    );

Returns either a hash reference:

    $List = {
        123 => 'CredentialsOne',
        234 => 'CredentialsTwo',
        345 => 'CredentialsThree',
        456 => 'CredentialsFour',
    };

or an array reference:

    $List = [
        123,
        234,
        345,
        456
    ];

ListGet()

Get a list of credential objects. This method accepts the same parameters as List, but returns either an array reference or a hash reference of instantiated objects.

    my $Credentials = $CredentialManager->ListGet(

        # optional, 'ARRAY' or 'HASH', defaults to 'ARRAY'
        ResultType => 'HASH',

        # optional, filter by field parameters
        Filter => {

            # optional, defaults to 1
            Valid      => 0,

            # optional, can be either a string or an array reference of strings
            Type => 'BasicAuth',
            Type => ['BasicAuth', 'OAuth2'],
        },
    );

Returns either a hash reference:

    $List = {
        123 => Object1(),
        234 => Object2(),
        345 => Object3(),
        456 => Object4(),
    };

or an array reference:

    $List = [
        Object1(),
        Object2(),
        Object3(),
        Object4()
    ];

Add()

Create a new credential entry.

    my $Credentials = $CredentialManager->Add(
        Name    => 'NameForField', # mandatory
        Type    => 'BasicAuth',    # mandatory
        Config  => $ConfigHashRef, # mandatory
        ValidID => 1,
        UserID  => 123,            # mandatory
    );

or

    my $Credentials = $Credential->Add( Object => $MyCustomCredentials );

Returns an object of the added credentials entry.

Get()

Get a credential object by id or name.

    my $Credentials = $CredentialManager->Get(
        ID   => 123,
        Name => 'MyServiceAuth',
    );

Returns an object of the requested credentials.

Update()

update credential content.

    my $Success = $CredentialManager->Update(
        ID     => 1234,             # mandatory
        Name   => 'CredentialName', # mandatory
        Type   => 'BasicAuth',      # mandatory
        Config => {
            Username => 'myuser',
            Password => 'supersecret',
        },
        ValidID => 1,
        UserID  => 123,
    );

    or

    my $Success = $CredentialManager->Update( Object => $MyCustomCredentialObject );

returns 1 on success or undef on error.

Delete()

Deletes a credentials entry.

    my $Success = $CredentialManager->Delete(
        ID     => 123,
        UserID => 123,
    );

    or

    my $Success = $CredentialManager->Delete( Object => $MyCustomCredentialObject );

returns 1 if successful or undef otherwise.

InUse()

Get the credential IDs which are in use. This means credentials which are associated to a valid mail account or a valid web service.

    my $InUse = $CredentialManager->InUse();

Returns an array reference:

    $InUse = [
        123,
        234,
        345,
        456
    ];

IsInUse

Checks if an account is being used in web services or mail accounts.

    my $Bool = $CredentialManager->IsInUse(
        ID => '...', # required
    );

Returns

    1 - used in other entities
    0 - not used

NameExistsCheck()

    return 1 if credential with this name already exits

        $Exist = $CredentialObject->NameExistsCheck(
            Name => 'Some::Credential',
            ID => 1, # optional
        );

PRIVATE METHODS

Scroll to Top