File: | /home/mik/work/module/Tivoli/AccessManager/Admin/Domain.pm |
Coverage: | 99.6% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package Tivoli::AccessManager::Admin::Domain; | ||||||
2 | 15 15 15 | 162 63 346 | use Carp; | ||||
3 | 15 15 15 | 225 69 231 | use strict; | ||||
4 | 15 15 15 | 212 60 224 | use warnings; | ||||
5 | 15 15 15 | 201 63 282 | use Data::Dumper; | ||||
6 | |||||||
7 | #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||||||
8 | # $Id: Domain.pm 305 2006-09-28 19:18:01Z mik $ | ||||||
9 | #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||||||
10 | |||||||
11 | $Tivoli::AccessManager::Admin::Action::VERSION = '0.04'; | ||||||
12 | 15 | 226 | 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::Domain', | ||||||
18 | 15 15 | 217 60 | ); | ||||
19 | 15 15 15 | 210 58 421 | use Tivoli::AccessManager::Admin::Response; | ||||
20 | |||||||
21 | sub new { | ||||||
22 | 11 | 1 | 77 | my $class = shift; | |||
23 | 11 | 50 | my $cont = shift; | ||||
24 | 11 | 115 | my $resp = Tivoli::AccessManager::Admin::Response->new(); | ||||
25 | |||||||
26 | 11 | 220 | unless ( defined($cont) and UNIVERSAL::isa($cont,'Tivoli::AccessManager::Admin::Context' ) ) { | ||||
27 | 2 | 66 | warn "Incorrect syntax -- did you forget the context?\n"; | ||||
28 | 2 | 18 | return undef; | ||||
29 | } | ||||||
30 | |||||||
31 | 9 | 69 | if ( @_ % 2 ) { | ||||
32 | 2 | 41 | warn "Invalid syntax -- you did not send a hash\n"; | ||||
33 | 2 | 16 | return undef; | ||||
34 | } | ||||||
35 | |||||||
36 | 7 | 75 | my %opts = @_; | ||||
37 | 7 | 56 | my $self = bless {}, $class; | ||||
38 | |||||||
39 | 7 | 78 | $self->{name} = $opts{name} || ''; | ||||
40 | 7 | 48 | $self->{admin} = $opts{admin} || ''; | ||||
41 | 7 | 53 | $self->{description} = $opts{description} || ''; | ||||
42 | 7 | 33 | $self->{context} = $cont; | ||||
43 | 7 | 28 | $self->{exist} = 0; | ||||
44 | |||||||
45 | 7 | 32 | if ( $self->{name} ) { | ||||
46 | 6 | 286715 | $self->domain_get($resp); | ||||
47 | 6 | 184 | $self->{exist} = $resp->isok; | ||||
48 | } | ||||||
49 | |||||||
50 | 7 | 78 | return $self; | ||||
51 | } | ||||||
52 | |||||||
53 | sub create { | ||||||
54 | 14 | 1 | 143 | my $self = shift; | |||
55 | 14 | 158 | my $resp = Tivoli::AccessManager::Admin::Response->new(); | ||||
56 | 14 | 47 | my $rc; | ||||
57 | |||||||
58 | 14 | 491 | unless ( ref $self ) { | ||||
59 | 3 | 17 | my $pd = shift; | ||||
60 | |||||||
61 | 3 | 47 | unless ( UNIVERSAL::isa($pd, 'Tivoli::AccessManager::Admin::Context') ) { | ||||
62 | 1 | 11 | $resp->set_message( 'syntax error -- no context' ); | ||||
63 | 1 | 11 | $resp->set_isok(0); | ||||
64 | 1 | 9 | return $resp; | ||||
65 | } | ||||||
66 | |||||||
67 | 2 | 21 | $self = $self->new( $pd, @_ ); | ||||
68 | } | ||||||
69 | |||||||
70 | 13 | 153 | if ( @_ % 2 ) { | ||||
71 | 1 | 11 | $resp->set_message("Invalid syntax -- you did not send a hash"); | ||||
72 | 1 | 25 | $resp->set_isok(0); | ||||
73 | 1 | 14 | return $resp; | ||||
74 | } | ||||||
75 | 12 | 111 | my %opts = @_; | ||||
76 | |||||||
77 | 12 | 81 | if ( $self->{exist} ) { | ||||
78 | 1 | 15 | $resp->set_message("Cannot create a Domain that already exists"); | ||||
79 | 1 | 14 | $resp->set_isok(0); | ||||
80 | 1 | 14 | return $resp; | ||||
81 | } | ||||||
82 | |||||||
83 | 11 | 67 | unless ( $self->{name} ) { | ||||
84 | 2 | 29 | $self->{name} = $opts{name} || ''; | ||||
85 | } | ||||||
86 | |||||||
87 | 11 | 60 | unless ( $self->{admin} ) { | ||||
88 | 2 | 66 | $self->{admin} = $opts{admin} || ''; | ||||
89 | } | ||||||
90 | |||||||
91 | 11 | 92 | unless ( $self->{description} ) { | ||||
92 | 2 | 49 | $self->{description} = $opts{description} || ''; | ||||
93 | } | ||||||
94 | |||||||
95 | 11 | 76 | unless ( defined( $opts{password} ) ) { | ||||
96 | 1 | 12 | $resp->set_message("syntax error: you must provide the domain admin's password" ); | ||||
97 | 1 | 6 | $resp->set_isok(0); | ||||
98 | 1 | 9 | return $resp; | ||||
99 | } | ||||||
100 | |||||||
101 | 10 | 187 | unless ( $self->{name} and $self->{admin} and $self->{description} ) { | ||||
102 | 3 | 36 | $resp->set_message("syntax error: you must provide the domain's name, admin and description" ); | ||||
103 | 3 | 34 | $resp->set_isok(0); | ||||
104 | 3 | 31 | return $resp; | ||||
105 | } | ||||||
106 | |||||||
107 | 7 | 3785883 | $rc = $self->domain_create( $resp, $opts{password} ); | ||||
108 | 7 | 222 | if ( $resp->isok ) { | ||||
109 | 6 | 84 | $resp->set_value($self); | ||||
110 | 6 | 66 | $self->{exist} = 1; | ||||
111 | } | ||||||
112 | 7 | 135 | return $resp; | ||||
113 | } | ||||||
114 | |||||||
115 | sub delete { | ||||||
116 | 8 | 1 | 79 | my $self = shift; | |||
117 | 8 | 102 | my $resp = Tivoli::AccessManager::Admin::Response->new; | ||||
118 | 8 | 32 | my ($rc,$reg); | ||||
119 | |||||||
120 | 8 | 96 | if ( @_ == 1 ) { | ||||
121 | 3 | 14 | $reg = shift; | ||||
122 | } | ||||||
123 | elsif ( @_ % 2 ) { | ||||||
124 | 1 | 27 | $resp->set_message("Invalid syntax"); | ||||
125 | 1 | 18 | $resp->set_isok(0); | ||||
126 | 1 | 12 | return $resp; | ||||
127 | } | ||||||
128 | elsif ( @_ ) { | ||||||
129 | 3 | 21 | my %opts = @_; | ||||
130 | 3 | 35 | $reg = $opts{registry} || 0; | ||||
131 | } | ||||||
132 | else { | ||||||
133 | 1 | 7 | $reg = 0; | ||||
134 | } | ||||||
135 | |||||||
136 | 7 | 65 | unless ( $self->{exist} ) { | ||||
137 | 1 | 15 | $resp->set_message("Cannot delete a Domain that does not exist"); | ||||
138 | 1 | 14 | $resp->set_iswarning(1); | ||||
139 | 1 | 5 | return $resp; | ||||
140 | } | ||||||
141 | |||||||
142 | 6 | 3249433 | $rc = domain_delete( $self, $resp, $reg); | ||||
143 | 6 | 144 | $self->{exist} = ! $rc; | ||||
144 | |||||||
145 | 6 | 114 | return $resp; | ||||
146 | } | ||||||
147 | |||||||
148 | sub description { | ||||||
149 | 9 | 1 | 64 | my $self = shift; | |||
150 | 9 | 122 | my $resp = Tivoli::AccessManager::Admin::Response->new; | ||||
151 | 9 | 41 | my ($rc,$desc); | ||||
152 | |||||||
153 | 9 | 119 | if ( @_ == 1 ) { | ||||
154 | 2 | 14 | $desc = shift; | ||||
155 | } | ||||||
156 | elsif ( @_ % 2 ) { | ||||||
157 | 1 | 23 | $resp->set_message("Invalid syntax"); | ||||
158 | 1 | 19 | $resp->set_isok(0); | ||||
159 | 1 | 16 | return $resp; | ||||
160 | } | ||||||
161 | elsif ( @_ ) { | ||||||
162 | 3 | 41 | my %opts = @_; | ||||
163 | 3 | 53 | $desc = $opts{description} || ''; | ||||
164 | } | ||||||
165 | else { | ||||||
166 | 3 | 16 | $desc = ''; | ||||
167 | } | ||||||
168 | |||||||
169 | 8 | 73 | unless ( $self->{exist} ) { | ||||
170 | 2 | 26 | $resp->set_message("Cannot describe a Domain that does not exist"); | ||||
171 | 2 | 19 | $resp->set_isok(0); | ||||
172 | 2 | 17 | return $resp; | ||||
173 | } | ||||||
174 | 6 | 38 | if ( $desc ) { | ||||
175 | 3 | 135950 | $rc = $self->domain_setdescription($resp, $desc); | ||||
176 | } | ||||||
177 | |||||||
178 | 6 | 112 | if ( $resp->isok ) { | ||||
179 | 5 | 236853 | $self->domain_get($resp); | ||||
180 | 5 | 148 | $resp->isok and $resp->set_value( $self->domain_getdescription ); | ||||
181 | } | ||||||
182 | |||||||
183 | 6 | 72 | return $resp; | ||||
184 | } | ||||||
185 | |||||||
186 | sub list { | ||||||
187 | 3 | 1 | 19 | my $self = shift; | |||
188 | 3 | 41 | my $resp = Tivoli::AccessManager::Admin::Response->new; | ||||
189 | 3 | 18 | my (@rc,$pd); | ||||
190 | |||||||
191 | |||||||
192 | 3 | 26 | if ( ref $self ) { | ||||
193 | 1 | 6 | $pd = $self->{context}; | ||||
194 | } | ||||||
195 | else { | ||||||
196 | 2 | 10 | $pd = shift; | ||||
197 | 2 | 37 | unless ( UNIVERSAL::isa($pd, 'Tivoli::AccessManager::Admin::Context' ) ) { | ||||
198 | 1 | 18 | $resp->set_message( 'syntax error -- no context object' ); | ||||
199 | 1 | 17 | $resp->set_isok(0); | ||||
200 | 1 | 11 | return $resp; | ||||
201 | } | ||||||
202 | } | ||||||
203 | |||||||
204 | 2 | 94895 | @rc = domain_list( $pd, $resp ); | ||||
205 | 2 | 75 | $resp->isok and $resp->set_value(\@rc); | ||||
206 | |||||||
207 | 2 | 26 | return $resp; | ||||
208 | } | ||||||
209 | |||||||
210 | sub DESTROY { | ||||||
211 | 6 | 29 | my $self = shift; | ||||
212 | 6 | 106 | $self->_domainfree; | ||||
213 | } | ||||||
214 | |||||||
215 | 1 | 1 | 86 | sub name { return $_[0]->domain_getid }; | |||
216 | |||||||
217 | 1; | ||||||
218 | |||||||
219 - 462 | =head1 NAME Tivoli::AccessManager::Admin::Domain =head1 SYNOPSIS use Tivoli::AccessManager::Admin; my $pd = Tivoli::AccessManager::Admin->new( password => 'N3ew0nk' ); # Create a domain object my $dom = Tivoli::AccessManager::Admin::Domain->new( $pd, name => 'Test', admin => 'chimchim', description => 'test domain' ); # Create it in TAM my $resp = $dom->create(password => 'n33w0nk'); # Create another domain in a different way $resp = Tivoli::AccessManager::Admin::Domain->create( $pd, name => 'Test1', admin => 'chimchim', description => 'another test domain', password => 'n33w0nk'); my $dom1 = $resp->value; # Delete them both $resp = $dom->delete; # All the info stays in registry $resp = $dom1->delete( 1 ); # Kill everything # Recreate my example :) $resp = $dom->create(password => 'n33w0nk'); # Set the description $resp = $dom->description( 'Speed Racer' ); # Get a list of all the domains $resp = $dom->list; # Or $resp = Tivoli::AccessManager::Admin::Domain->list($pd); print "Domains:\n\t" . join("\n\t", @{$resp->value}); =head1 DESCRIPTION Allows for the creation, deletion and some manipulations of TAM domains. =head1 CONSTRUCTORS =head2 new( PDADMIN[, name =E<gt> NAME, admin =E<gt> ADMINID, description =E<gt> DESC] ); Creates a blessed L<Tivoli::AccessManager::Admin::Domain> object. You will need to destroy this object if you wish to change the context. =head3 Parameters =over 4 =item PDADMIN An initialized L<Tivoli::AccessManager::Admin::Context> object. This is the only required parameter. =item name =E<gt> NAME The name of the domain. =item admin =E<gt> ADMINID The domain administrator's ID. =item description =E<gt> DESC A description of the domain. =back =head3 Returns A blessed L<Tivoli::AccessManager::Admin::Domain> object. =head2 create( PDADMIN, name =E<gt> NAME, admin =E<gt> ADMINID, description =E<gt> DESC, password =E<gt> PASSWORD ) Instantiates a L<Tivoli::AccessManager::Admin::Domain> object and creates the domain in TAM if used as a class method. =head3 Parameters =over 4 =item name =E<gt> NAME =item admin =E<gt> ADMINID =item description =E<gt> DESC The parameters are identical to those for L</"new">. Unlike L</"new">, they are all required. =item password =E<gt> PASSWORD The domain administrator's password. This too is required. =back =head3 Returns A blessed L<Tivoli::AccessManager::Admin::Domain> object, buried in a L<Tivoli::AccessManager::Admin::Response> object. =head1 CLASS METHODS =head2 list(PDADMIN) Generates a list of the names of all the security domains. =head3 Parameters =over 4 =item PDADMIN A fully initialized L<Tivoli::AccessManager::Admin::Context> object. =back =head3 Returns The list of the security domains currently defined. =head1 METHODS =head2 create( name =E<gt> NAME, admin =E<gt> ADMINID, description =E<gt> DESC, password =E<gt> PASSWORD ) Yes, this can called as an instance method if you want. Notice the different signature -- the context object is no longer required. =head3 Parameters =over 4 =item name =E<gt> NAME =item admin =E<gt> ADMINID =item description =E<gt> DESC See L</"new">. Any parameter you did not provide to L</"new"> must be provided to L</"create">. They all must be defined to actually create the domain in TAM =item password =E<gt> PASSWORD The domain administrator's password. This too is required. =back =head3 Returns The results if the create operation =head2 delete([1]) Deletes the domain from TAM. =head3 Parameters =over 4 =item 1 If provided, all of the domain's entries will be deleted from the registry. =back =head3 Returns The results of the delete call. =head2 description([STR]) If the optional parameter is provided, the domain's description will be changed. Either way, the description for the domain is returned. =head3 Parameters =over 4 =item STR Causes the domain's description to be changed to STR =back =head3 Returns The domain's current description. =head2 list() L</"list"> can be called as an instance method as well. Note the diffference in the method's signature -- the L<Tivoli::AccessManager::Admin::Context> object is no longer required. =head3 Parameters None. =head3 Returns The names of all the currently defined TAM domains. =head2 name Returns the domain's name. This is a read-only method. =head3 Parameters None =head3 Returns The domain's name. This is NOT buried in a 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 me. =head1 BUGS =head1 AUTHOR Mik Firestone E<lt>mikfire@gmail.comE<gt> =head1 COPYRIGHT Copyright (c) 2004-2011 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 | ||||||
463 |