| 1 | package W3C::SOAP::Header::Security::Username; | ||
| 2 | |||
| 3 | # Created on: 2012-05-23 14:38:06 | ||
| 4 | # Create by: dev | ||
| 5 | # $Id$ | ||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||
| 7 | # $Revision$, $Source$, $Date$ | ||
| 8 | |||
| 9 | 2 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 2 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 2 | ▶ | use DateTime; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 2 | ▶ | use Time::HiRes qw/gettimeofday/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 2 | ▶ | use English qw/ -no_match_vars /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | |||
| 16 | 2 | extends 'W3C::SOAP::Header::Security'; | |
| 17 | |||
| 18 | 2 | our $VERSION = 0.13; | |
| 19 | 2 | my $id = 0; | |
| 20 | |||
| 21 | 2 | has username => ( | |
| 22 | is => 'rw', | ||
| 23 | isa => 'Str', | ||
| 24 | required => 1, | ||
| 25 | ); | ||
| 26 | 2 | has password => ( | |
| 27 | is => 'rw', | ||
| 28 | isa => 'Str', | ||
| 29 | required => 1, | ||
| 30 | ); | ||
| 31 | |||
| 32 | # Moose 2 | ||
| 33 | #argument to_xml => sub { | ||
| 34 | sub to_xml { | ||
| 35 | 0 | ▶ | my ($self, $xml) = @_; |
|
Subroutine
to_xml: not called CC=2 SCAR=17.9
Pod
documented
| |||
| 36 | 0 | my $uname_token = $xml->createElement('wsse:UsernameToken'); | |
| 37 | 0 | $uname_token->setAttribute('xmlns:wsu' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'); | |
| 38 | 0 | $uname_token->setAttribute('wsu:Id', 'UsernameToken-' . $id++); | |
| 39 | |||
| 40 | 0 | my $username = $xml->createElement('wsse:Username'); | |
| 41 | 0 | $username->appendChild( $xml->createTextNode($self->username) ); | |
| 42 | 0 | $uname_token->appendChild($username); | |
| 43 | |||
| 44 | 0 | my $password = $xml->createElement('wsse:Password'); | |
| 45 | 0 | $password->appendChild( $xml->createTextNode($self->password) ); | |
| 46 | 0 | $password->setAttribute('Type' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'); | |
| 47 | 0 | $uname_token->appendChild($password); | |
| 48 | |||
| 49 | 0 | my $nonce_text = ''; | |
| 50 | 0 | $nonce_text .= ('a'..'z','A'..'Z',0..9)[rand 62] for 1 .. 24; | |
| 51 | 0 | my $nonce = $xml->createElement('wsse:Nonce'); | |
| 52 | 0 | $nonce->appendChild( $xml->createTextNode($nonce_text.'==') ); | |
| 53 | 0 | $nonce->setAttribute('EncodingType' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'); | |
| 54 | 0 | $uname_token->appendChild($nonce); | |
| 55 | |||
| 56 | 0 | my ($seconds, $microseconds) = gettimeofday; | |
| 57 | #TODO is the following nessesary? | ||
| 58 | 0 | $microseconds =~ s{^(\d\d\d).*}{$1}; | |
| 59 | 0 | my $date_text = DateTime->now->set_time_zone("Z") . ".${microseconds}Z"; | |
| 60 | 0 | my $date = $xml->createElement('wsu:Created'); | |
| 61 | 0 | $date->appendChild( $xml->createTextNode($date_text) ); | |
| 62 | 0 | $uname_token->appendChild($date); | |
| 63 | |||
| 64 | # Moose 1 | ||
| 65 | 0 | my $sec = $self->SUPER::to_xml($xml); | |
| 66 | 0 | $sec->appendChild($uname_token); | |
| 67 | |||
| 68 | 0 | return $sec; | |
| 69 | # Moose 2 | ||
| 70 | #return $uname_token; | ||
| 71 | } | ||
| 72 | |||
| 73 | 2 | 1; | |
| 74 | |||
| 75 | __END__ | ||
| 76 | |||
| 77 | =head1 NAME | ||
| 78 | |||
| 79 | W3C::SOAP::Header::Security::Username - Creates a WS-Security User name object | ||
| 80 | |||
| 81 | =head1 VERSION | ||
| 82 | |||
| 83 | This documentation refers to W3C::SOAP::Header::Security::Username version 0.13. | ||
| 84 | |||
| 85 | =head1 SYNOPSIS | ||
| 86 | |||
| 87 | use W3C::SOAP::Header::Security::Username; | ||
| 88 | |||
| 89 | # Brief but working code example(s) here showing the most common usage(s) | ||
| 90 | # This section will be as far as many users bother reading, so make it as | ||
| 91 | # educational and exemplary as possible. | ||
| 92 | |||
| 93 | |||
| 94 | =head1 DESCRIPTION | ||
| 95 | |||
| 96 | |||
| 97 | =head1 SUBROUTINES/METHODS | ||
| 98 | |||
| 99 | =over 4 | ||
| 100 | |||
| 101 | =item C<to_xml ($xml)> | ||
| 102 | |||
| 103 | Coverts this object to XML | ||
| 104 | |||
| 105 | =back | ||
| 106 | |||
| 107 | =head1 DIAGNOSTICS | ||
| 108 | |||
| 109 | =head1 CONFIGURATION AND ENVIRONMENT | ||
| 110 | |||
| 111 | =head1 DEPENDENCIES | ||
| 112 | |||
| 113 | =head1 INCOMPATIBILITIES | ||
| 114 | |||
| 115 | =head1 BUGS AND LIMITATIONS | ||
| 116 | |||
| 117 | There are no known bugs in this module. | ||
| 118 | |||
| 119 | Please report problems to Ivan Wills - (ivan.wills@gmail.com) | ||
| 120 | |||
| 121 | Patches are welcome. | ||
| 122 | |||
| 123 | =head1 AUTHOR | ||
| 124 | |||
| 125 | Ivan Wills - (ivan.wills@gmail.com) | ||
| 126 | |||
| 127 | =head1 LICENSE AND COPYRIGHT | ||
| 128 | |||
| 129 | Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). | ||
| 130 | All rights reserved. | ||
| 131 | |||
| 132 | This module is free software; you can redistribute it and/or modify it under | ||
| 133 | the same terms as Perl itself. See L<perlartistic>. This program is | ||
| 134 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
| 135 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
| 136 | PARTICULAR PURPOSE. | ||
| 137 | |||
| 138 | =cut | ||