File Coverage

File:/home/mik/work/module/Tivoli/AccessManager/Admin/SSO/Web.pm
Coverage:99.5%

linestmtbrancondsubpodtimecode
1package Tivoli::AccessManager::Admin::SSO::Web;
2
15
15
15
173
76
227
use strict;
3
15
15
15
215
58
235
use warnings;
4
15
15
15
207
57
316
use Carp;
5
15
15
15
211
67
297
use Tivoli::AccessManager::Admin::Response;
6
15
15
15
215
61
280
use Data::Dumper;
7
8#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
9# $Id$
10#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
11$Tivoli::AccessManager::Admin::SSO::Web::VERSION = '0.04';
12
15
228
use Inline(C => 'DATA',
13                INC => '-I/opt/PolicyDirector/include',
14                LIBS => ' -lpthread -lpdadminapi -lstdc++',
15                CCFLAGS => '-Wall',
16# VERSION => '0.04',
17                NAME => 'Tivoli::AccessManager::Admin::SSO::Web',
18
15
15
224
60
           );
19
20sub new {
21
29
1
228
    my $class = shift;
22
29
126
    my $cont = shift;
23
29
160
    my $self = {};
24
29
364
    my $resp = Tivoli::AccessManager::Admin::Response->new();
25
29
131
    my ($name,$desc);
26
27
29
642
    unless ( defined($cont) and UNIVERSAL::isa($cont,'Tivoli::AccessManager::Admin::Context' ) ) {
28
3
65
        warn "Incorrect syntax -- did you forget the context?\n";
29
3
26
        return undef;
30    }
31
32
26
221
    bless $self, $class;
33
34
26
293
    if ( @_ == 1 ) {
35
1
12
        $name = shift;
36    }
37    elsif ( @_ % 2 ) {
38
2
28
        warn "Invalid parameter list -- please use a hash\n";
39
2
13
        return undef;
40    }
41    else {
42
23
239
        my %opts = @_;
43
23
190
        $name = $opts{name} || '';
44
23
329
        $desc = $opts{desc} || '';
45    }
46
47
24
202
    $self->{name} = $name;
48
24
204
    $self->{context} = $cont;
49
24
144
    $self->{desc} = $desc;
50
24
388
    $self->_ssoweb_stash();
51
52
24
128
    if ( $name ) {
53
20
1309926
        $self->{exist} = $self->ssoweb_get( $resp );
54    }
55    else {
56
4
19
        $self->{exist} = 0;
57    }
58
59
24
456
    return $self;
60}
61
62sub create {
63
19
1
198
    my $self = shift;
64
19
209
    my $resp = Tivoli::AccessManager::Admin::Response->new();
65
19
81
    my ($name,$desc);
66
67
19
126
    unless ( ref( $self ) ) {
68
12
51
        my $pd = shift;
69
12
998
        $self = $self->new( $pd, @_ );
70
12
348
        unless ( defined $self ) {
71
2
16
            $resp->set_message("Couldn't instatiate the resource");
72
2
14
            $resp->set_isok(0);
73
2
14
            return $resp;
74        }
75    }
76
77
17
175
    if ( @_ == 1 ) {
78
1
5
        $self->{name} = shift;
79    }
80    elsif ( @_ % 2 ) {
81
1
9
        $resp->set_message("Invalid parameter list -- please use a hash");
82
1
10
        $resp->set_isok(0);
83
1
9
        return $resp;
84    }
85    else {
86
15
156
        my %opts = @_;
87
15
172
        $self->{name} = $opts{name} || $self->{name} || '';
88
15
280
        $self->{desc} = $opts{desc} || $self->{desc} || '';
89    }
90
91
16
96
    unless ( $self->{name} ) {
92
1
11
        $resp->set_message("I cannot create an unnamed SSO resource");
93
1
10
        $resp->set_isok(0);
94
1
5
        return $resp;
95    }
96
97
15
174
    if ( $self->exist ) {
98
1
8
        $resp->set_message("The SSO resource " . $self->name . " already exists");
99
1
13
        $resp->set_value($self);
100
1
11
        $resp->set_iswarning(1);
101
1
12
        return $resp;
102    }
103
104
14
951286
    my $rc = $self->ssoweb_create($resp);
105
14
202
    $self->{exist} = $rc;
106
107
14
157
    if ( $rc ) {
108
13
256
        $resp->set_value($self);
109    }
110
111
14
430
    return $resp;
112}
113
114sub delete {
115
15
1
101
    my $self = shift;
116
15
191
    my $resp = Tivoli::AccessManager::Admin::Response->new();
117
118
15
923
    unless ( $self->exist ) {
119
1
8
        $resp->set_message("SSO resource " . $self->name . " doesn't exist");
120
1
11
        $resp->set_isok(0);
121
1
10
        return $resp;
122    }
123
124
14
758416
    my $rc = $self->ssoweb_delete($resp);
125
14
251
    if ($rc) {
126
13
212
        $self->{exist} = 0;
127    }
128
14
258
    $resp->set_value($rc);
129
14
154
    return $resp;
130}
131
132sub list {
133
4
1
47
    my $class = shift;
134
4
38
    my $resp = Tivoli::AccessManager::Admin::Response->new();
135
4
15
    my $pd;
136
137    # I want this to be called as either Tivoli::AccessManager::Admin::User->list or
138    # $self->list
139
4
22
    if ( ref($class) ) {
140
1
5
        $pd = $class->{context};
141    }
142    else {
143
3
21
        $pd = shift;
144    }
145
146
4
63
    unless ( defined($pd) and UNIVERSAL::isa($pd,'Tivoli::AccessManager::Admin::Context' ) ) {
147
2
17
        $resp->set_message("Incorrect syntax -- did you forget the context?");
148
2
15
        $resp->set_isok(0);
149
2
16
        return $resp;
150    }
151
152
2
91072
    my @rc = ssoweb_list($pd,$resp);
153
2
48
    $resp->isok() && $resp->set_value( $rc[0],\@rc );
154
2
23
    return $resp;
155}
156
157sub name {
158
37
1
258
    my $self = shift;
159
37
328
    my $name = $self->{name} || '';
160
161
37
368
    return $name;
162}
163
164sub description {
165
4
1
24
    my $self = shift;
166
4
41
    my $desc = $self->{desc} || '';
167
168
4
38
    return $desc;
169}
170
171
37
1
657
sub exist { return $_[0]->{exist} || 0; }
172
1731;
174
175 - 428
=head1 NAME

Tivoli::AccessManager::Admin::SSO::Web

=head1 SYNOPSIS

    use Tivoli::AccessManager::Admin;

    my $pd = Tivoli::AccessManager::Admin->new( password => $pswd);
    my $sso = Tivoli::AccessManager::Admin::SSO::Web->new( $pd, name => 'twiki' );
    my $resp;

    # See what web GSO resources exist
    $resp = Tivoli::AccessManager::Admin::SSO::Web->list($pd);
    print join("\n", $resp->value);
    
    # Create the web SSO resource if it doesn't exist
    $sso = Tivoli::AccessManager::Admin::SSO::Web->new($pd) unless $sso->exist;

    my $name = $sso->name;
    my $desc = $sso->description

    $resp = $sso->delete;


=head1 DESCRIPTION

L<Tivoli::AccessManager::Admin::SSO::Web> provides the interface to create and manage web GSO
resources.

=head1 CONSTRUCTOR

=head2 new(PDADMIN[, name => STRING, desc => STRING])

Creates a blessed L<Tivoli::AccessManager::Admin::SSO::Web> object and returns it.

=head3 Parameters

=over 4

=item PDADMIN

An initialized L<Tivoli::AccessManager::Admin::Context> object.  As with every other class, the
only way to change the context is to destroy the L<Tivoli::AccessManager::Admin::SSO::Web>
object and recreate it with the new context.  This parameter is required.

=item name =E<gt> STRING

The name of the SSO web resource.  If this is the only other parameter
provided, you do not need to use a named parameter.  I.e., new($pd,"name")
will assume "name" is the name of the resource.  This parameter is optional.

=item desc =E<gt> STRING

A description of the resource.  This is an optional parameter.

=back

=head3 Returns

A blessed L<Tivoli::AccessManager::Admin::SSO::Web> object if things worked.  undef will be
returned otherwise, along with a nasty warning to STDERR.

=head2 create(PDADMIN, <NAME|name =E<gt>  name, desc =E<gt>  STRING>)

Creates a new web GSO resource.

=head3 Parameters

=over 4

=item PDADMIN

An initialized L<Tivoli::AccessManager::Admin::Context> object.  As with every other class, the
only way to change the context is to destroy the L<Tivoli::AccessManager::Admin::SSO::Web>
object and recreate it with the new context.  This parameter is required.

=item NAME

If only one parameter provided other than PDADMIN is provided, it will be
interpreted as the name of the GSO web resource.  You must provide the name of
the resource to create -- either this way or the next way.

=item name =E<gt> NAME

An alternate way to provide the reource's name.

=item desc =E<gt> STRING

Provide a description for the GSO resource.  The only way to provide this to
create is to use the full named parameter call.  It is an optional parameter.

I should also note that this is the only way to set the description -- the API
provides no way to change the description after the resource is created.

=back

=head3 Returns

A L<Tivoli::AccessManager::Admin::Response> object, containing the L<Tivoli::AccessManager::Admin::SSO::Web>
object if the create was successful.  Otherwise you will get an error message.

=head1 CLASS METHODS

The standard disclaimer.  All the class methods will return a
L<Tivoli::AccessManager::Admin::Response> object unless specifically stated otherwise.  See the
documentation for that module on how to coax the values out.

=head2 list

Lists all the defined web resources.

=head3 Parameters

None.

=head3 Returns

A list of the defined web GSO resources.

=head1 METHODS

The standard disclaimer.  All the methods will return a
L<Tivoli::AccessManager::Admin::Response> object unless specifically stated otherwise.  See the
documentation for that module on how to coax the values out.

The methods also follow the same basic pattern.  If an optional parameter is
provided, it will have the affect of setting the attribute.  All method calls
will embed the results of a 'get' in the L<Tivoli::AccessManager::Admin::Response> object.

=head2 create( [NAME|name =E<gt> NAME[, desc =E<gt> STRING]] )

As you might expect, create can also be used as a method call.

=head3 Parameters

=over 4

=item NAME

The name of the resource.  This is only required if you did not provide the
name of the resource when you created the object and if you are not using the
named parameter call.

If you provide the name to both L</"new"> and L</"create">, the name given to
L</"create"> will be the one used.

=item name =E<gt> NAME

An alternate way to provide the name of the resource.  If you want to provide
a description of the resource, you must use this form.

=item desc =E<gt> STRING

A description of the resource.  This is optional.  If you provide a
description to both L</"new"> and L</"create">, the description given to
L</"create"> will be the one used.

I should also note that this is the only way to set the description -- the API
provides no way to change the description after the resource is created.

=back

=head3 Returns

The success or failure of the operation.

=head2 delete

Deletes the web resource.

=head3 Parameters

None.

=head3 Returns

The success of failure of the operation.

=head2 list

As should be no surprise, L</"list"> can be used as an instance method as
well.  I don't think it makes any sense, but you can do it.

=head3 Parameters

None

=head3 Returns

A list of the defined web GSO resources.

=head2 name

Gets the name of the web resource.

=head3 Parameters

None.

=head3 Returns

The name of the resource.  This is returned as a string -- it is not embedded
in an L<Tivoli::AccessManager::Admin::Response> object.

=head2 description

Gets the web resource's description, if set.

=head3 Parameters

None.

=head3 Returns

The resource's description, if set.  This is returned as a string -- it is not
embedded in an L<Tivoli::AccessManager::Admin::Response> object.  You will get
an empty string if the description is not set.

=head2 exist

Determines if the web resource object exists.

=head3 Parameters

None.

=head3 Returns

True if the resource exists, false otherwise.  Again, this is not embedded in an L<Tivoli::AccessManager::Admin::Response> object.

=head1 ACKNOWLEDGEMENTS

See L<Tivoli::AccessManager::Admin> for the list.  This was not possible without the help of a
bunch of people smarter than I.

=head1 BUGS

None known.

=head1 AUTHOR

Mik Firestone E<lt>mikfire@gmail.comE<gt>

=head1 COPYRIGHT

Copyright (c) 2006-2013 Mik Firestone.  All rights reserved.  This program is
free software; you can redistibute it and/or modify it under the same terms as
Perl itself.

All references to TAM, Tivoli Access Manager, etc are copyrighted, trademarked
and otherwise patented by IBM.

=cut
429