Security.pm untested

filter: Statementstmt 0.0% 0 / 92 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 139 CC 11 SCAR 29.8
CC
11
Cov
0%
fromWSXMLNode
56.0
toWebserviceXML
20.0
fromWSXMLListNode
6.0
CRAP 19.6
1 # ------------------------------------------------------------------------------------------
2 package CaCORE::Security::SecurityToken;
3
4 use 5.005;
5 #use strict;
6 use warnings;
7
8 require Exporter;
9
10 use XML::DOM;
11
12 ## begin import objects ##
13 use CaCORE::ApplicationService;
14 ## end import objects ##
15
16 $VERSION = '3.2';
17
18 @ISA = qw(CaCORE::DomainObjectI);
19
20 our %EXPORT_TAGS = ( 'all' => [ qw(
21
22 ) ] );
23
24 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
25
26 our @EXPORT = qw(
27 );
28
29 # create an instance of the SecurityToken object
30 # returns: a SecurityToken object
31 sub new {
32 my $class = shift;
33 my $self = {};
34 bless($self, $class);
35 #print "new SecurityToken\n";
36 return $self;
37 }
38
39 # Construct the specific section of the WSDL request corresponding
40 # to this SecurityToken intance
41 # returns: XML in string format
42 sub toWebserviceXML {
43 my $self = shift;
44 my $result = shift;
45 my $assigned_id = shift;
46 my $current_id = shift;
47 my $l = shift;
48 my %worklist = %$l;
49
50 # prefix portion of the xml
51 $result .= "<multiRef id=\"id" . $assigned_id ."\" soapenc:root=\"0\" soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xsi:type=\"ns" . $current_id . ":SecurityToken\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns" . $current_id . "=\"urn:ws.security.evs.nci.nih.gov\">";
52 my $tmpstr = "";
53 $current_id ++;
54
55 ## begin attribute to XML ##
56 # accessToken;
57 if( defined( $self->getAccessToken ) ) {
58 $tmpstr = "<accessToken xsi:type=\"xsd:string\">" . $self->getAccessToken . "</accessToken>";
59 } else {
60 $tmpstr = "<accessToken xsi:type=\"xsd:string\" xsi:nil=\"true\" />";
61 }
62 $result .= $tmpstr;
63  
64 # password;
65 if( defined( $self->getPassword ) ) {
66 $tmpstr = "<password xsi:type=\"xsd:string\">" . $self->getPassword . "</password>";
67 } else {
68 $tmpstr = "<password xsi:type=\"xsd:string\" xsi:nil=\"true\" />";
69 }
70 $result .= $tmpstr;
71  
72 # userName;
73 if( defined( $self->getUserName ) ) {
74 $tmpstr = "<userName xsi:type=\"xsd:string\">" . $self->getUserName . "</userName>";
75 } else {
76 $tmpstr = "<userName xsi:type=\"xsd:string\" xsi:nil=\"true\" />";
77 }
78 $result .= $tmpstr;
79  
80 ## end attribute to XML ##
81
82 ## begin association to XML ##
83 ## end association to XML ##
84
85 # add trailing close tags
86 $result .= "</multiRef>";
87
88 return ($result, $current_id, %worklist);
89 }
90
91 # parse a given webservice response xml, construct a list of SecurityToken objects
92 # param: xml doc
93 # returns: list of SecurityToken objects
94 sub fromWebserviceXML {
95 my $self = shift;
96 my $parser = new XML::DOM::Parser;
97 my $docnode = $parser->parse(shift);
98 my $root = $docnode->getFirstChild->getFirstChild->getFirstChild->getFirstChild;
99
100 return $self->fromWSXMLListNode($root);
101 }
102
103 # parse a given xml node, construct a list of SecurityToken objects
104 # param: xml node
105 # returns: a list of SecurityToken objects
106 sub fromWSXMLListNode {
107 my $self = shift;
108 my $listNode = shift;
109 my @obj_list = ();
110
111 # get all children for this node
112 for my $childrenNode ($listNode->getChildNodes) {
113 if ($childrenNode->getNodeType == XML::DOM::ELEMENT_NODE()) {
114 my $newobj = $self->fromWSXMLNode($childrenNode);
115 push @obj_list, $newobj;
116 }
117 }
118
119 return @obj_list;
120 }
121
122 # parse a given xml node, construct one SecurityToken object
123 # param: xml node
124 # returns: one SecurityToken object
125 sub fromWSXMLNode {
126 my $SecurityTokenNode = $_[1];
127
128 ## begin ELEMENT_NODE children ##
129 my $accessToken;
130 my $password;
131 my $userName;
132 ## end ELEMENT_NODE children ##
133
134 # get all children for this node
135 for my $childrenNode ($SecurityTokenNode->getChildNodes) {
136 if ($childrenNode->getNodeType == XML::DOM::ELEMENT_NODE()) {
137 if( ! defined($childrenNode->getFirstChild) ){ next; };
138 my $textNode = $childrenNode->getFirstChild;
139 ## begin iterate ELEMENT_NODE ##
140 if (0) {
141 # do nothing, just a place holder for "if" component
142 }
143 elsif ($childrenNode->getNodeName eq "accessToken") {
144 $accessToken=$textNode->getNodeValue;
145 }
146 elsif ($childrenNode->getNodeName eq "password") {
147 $password=$textNode->getNodeValue;
148 }
149 elsif ($childrenNode->getNodeName eq "userName") {
150 $userName=$textNode->getNodeValue;
151 }
152 ## end iterate ELEMENT_NODE ##
153 }
154 }
155 my $newobj = new CaCORE::Security::SecurityToken;
156 ## begin set attr ##
157 $newobj->setAccessToken($accessToken);
158 $newobj->setPassword($password);
159 $newobj->setUserName($userName);
160 ## end set attr ##
161
162 return $newobj;
163 }
164
165 ## begin getters and setters ##
166
167 sub getAccessToken {
168 my $self = shift;
169 return $self->{accessToken};
170 }
171  
172 sub setAccessToken {
173 my $self = shift;
174 $self->{accessToken} = shift;
175 }
176  
177 sub getPassword {
178 my $self = shift;
179 return $self->{password};
180 }
181  
182 sub setPassword {
183 my $self = shift;
184 $self->{password} = shift;
185 }
186  
187 sub getUserName {
188 my $self = shift;
189 return $self->{userName};
190 }
191  
192 sub setUserName {
193 my $self = shift;
194 $self->{userName} = shift;
195 }
196  
197 ## end getters and setters ##
198
199 ## begin bean association methods ##
200
201 ## end bean association methods ##
202
203 1;
204 #end
205 # Below is module documentation for SecurityToken
206
207 =pod
208
209 =head1 SecurityToken
210
211 CaCORE::Security::SecurityToken - Perl extension for SecurityToken.
212
213 =head2 ABSTRACT
214
215 The CaCORE::Security::SecurityToken is a Perl object representation of the
216 CaCORE SecurityToken object.
217
218
219 =head2 SYNOPSIS
220
221 See L<CaCORE::ApplicationService>.
222
223 =head2 DESCRIPTION
224
225
226
227 =head2 ATTRIBUTES of SecurityToken
228
229 The following are all the attributes of the SecurityToken object and their data types:
230
231 =over 4
232
233 =item accessToken
234  
235 data type: C<string>
236  
237 =item password
238  
239 data type: C<string>
240  
241 =item userName
242  
243 data type: C<string>
244  
245
246 =back
247
248 Note: Although you can also use the corresponding setter methods to set the
249 attribute values, it is not recommended to do so unless you absolutely have
250 to change the object's attributes.
251
252 =head2 ASSOCIATIONS of SecurityToken
253
254 The following are all the objects that are associated with the SecurityToken:
255
256 =over 4
257
258
259 =back
260
261 =cut
262
263
264 =pod
265
266 =head1 SUPPORT
267
268 Please do not contact author directly. Send email to ncicb@pop.nci.nih.gov to request
269 support or report a bug.
270
271 =head1 AUTHOR
272
273 Shan Jiang <jiangs@mail.nih.gov>
274
275 =head1 COPYRIGHT AND LICENSE
276
277 The CaCORE Software License, Version 1.0
278
279 Copyright 2001-2005 SAIC. This software was developed in conjunction with the National Cancer Institute, and so to the extent government employees are co-authors, any rights in such works shall be subject to Title 17 of the United States Code, section 105. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
280
281 =over 1
282
283 =item 1
284
285 Redistributions of source code must retain the above copyright notice, this list of conditions and the disclaimer of Article 5, below. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the disclaimer of Article 5 in the documentation and/or other materials provided with the distribution.
286
287 =item 2
288
289 The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by SAIC and the National Cancer Institute." If no such end-user documentation is to be included, this acknowledgment shall appear in the software itself, wherever such third-party acknowledgments normally appear.
290
291 =item 3
292
293 The names "The National Cancer Institute", "NCI" and "SAIC" must not be used to endorse or promote products derived from this software. This license does not authorize the licensee to use any trademarks owned by either NCI or SAIC.
294
295 =item 4
296
297 This license does not authorize or prohibit the incorporation of this software into any third party proprietary programs. Licensee is expressly made responsible for obtaining any permission required to incorporate this software into third party proprietary programs and for informing licensee's end-users of their obligation to secure any required permissions before incorporating this software into third party proprietary software programs.
298
299 =item 5
300
301 THIS SOFTWARE IS PROVIDED "AS IS," AND ANY EXPRESSED OR IMPLIED WARRANTIES, (INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE) ARE DISCLAIMED. IN NO EVENT SHALL THE NATIONAL CANCER INSTITUTE, SAIC, OR THEIR AFFILIATES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
302
303 =back
304
305 =cut
306
307