| 1 | # Copyrights 2011-2017 by [Mark Overmeer]. | ||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | package XML::Compile::WSS::BasicAuth; | ||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 7 | $VERSION = '1.14'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use base 'XML::Compile::WSS'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Log::Report 'xml-compile-wss'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use XML::Compile::WSS::Util qw/:wss11 :utp11 WSM10_BASE64/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use Digest::SHA qw/sha1_base64/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use Encode qw/encode/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use MIME::Base64 qw/encode_base64/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use POSIX qw/strftime/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 7 | my @nonce_chars = ('A'..'Z', 'a'..'z', '0'..'9'); | |||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub _random_nonce() { join '', map $nonce_chars[rand @nonce_chars], 1..5 } | ||||||||||||||||||||||||||||||
|
Subroutine
_random_nonce: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | sub init($) | ||||||||||||||||||||||||||||||||
| 28 | 15 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 29 | 15 | ▶ | $args->{wss_version} ||= '1.1'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"wss_version"} ||= "1.1"
MC/DC0%0/1
$args->{"wss_version"} ||= "1.1"
$args->{"wss_version"}
Truth table50%1/2
A
A= $args->{"wss_version"}
| |||||||||||||||||||||||||||||||||
| 30 | 15 | $self->SUPER::init($args); | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | $self->{XCWB_username} = $args->{username} | ||||||||||||||||||||||||||||||||
| 33 | 15 | ▶ | or error __"no username provided for basic authentication"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | $self->{XCWB_password} = $args->{password} | ||||||||||||||||||||||||||||||||
| 36 | 15 | ▶ | or error __x"no password provided for basic authentication"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 15 | my $n = $args->{nonce}; | |||||||||||||||||||||||||||||||
| 39 | my $nonce = ref $n eq 'CODE' ? $n | ||||||||||||||||||||||||||||||||
| 40 | : defined $n && $n eq 'RANDOM' ? \&_random_nonce | ||||||||||||||||||||||||||||||||
| 41 | 15 | ▶ | : sub { $n }; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.4
Branch: 2 branches
Condition66%2/3
defined $n and $n eq "RANDOM"
MC/DC0%0/2
defined $n and $n eq "RANDOM"
defined $n
$n eq "RANDOM"
Truth table66%2/3
A and B
A= defined $nB= $n eq "RANDOM"
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 15 | $self->{XCWB_nonce} = $nonce; | |||||||||||||||||||||||||||||||
| 44 | 15 | ▶ | $self->{XCWB_wsu_id} = $args->{wsu_Id} || $args->{wsu_id}; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{'wsu_Id'} || $args->{'wsu_id'}
MC/DC50%1/2
$args->{'wsu_Id'} || $args->{'wsu_id'}
$args->{'wsu_Id'}
$args->{'wsu_id'}
Truth table66%2/3
A || B
A= $args->{'wsu_Id'}B= $args->{'wsu_id'}
| |||||||||||||||||||||||||||||||||
| 45 | 15 | $self->{XCWB_created} = $args->{created}; | |||||||||||||||||||||||||||||||
| 46 | 15 | ▶ | $self->{XCWB_pwformat} = $args->{pwformat} || UTP11_PTEXT; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'pwformat'} || 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
MC/DC0%0/1
$args->{'pwformat'} || 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
$args->{'pwformat'}
Truth table50%1/2
A
A= $args->{'pwformat'}
| |||||||||||||||||||||||||||||||||
| 47 | 15 | $self; | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | #---------------------------------- | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 15 | ▶ | sub username() {shift->{XCWB_username}} | ||||||||||||||||||||||||||||||
|
Subroutine
username: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 53 | 15 | ▶ | sub password() {shift->{XCWB_password}} | ||||||||||||||||||||||||||||||
|
Subroutine
password: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 54 | 15 | ▶ | sub nonce() {shift->{XCWB_nonce}->() } | ||||||||||||||||||||||||||||||
|
Subroutine
nonce: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 55 | 15 | ▶ | sub wsuId() {shift->{XCWB_wsu_id} } | ||||||||||||||||||||||||||||||
|
Subroutine
wsuId: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | sub created() {shift->{XCWB_created} } | ||||||||||||||||||||||||||||||
|
Subroutine
created: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 57 | 15 | ▶ | sub pwformat() {shift->{XCWB_pwformat}} | ||||||||||||||||||||||||||||||
|
Subroutine
pwformat: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | sub prepareWriting($) | ||||||||||||||||||||||||||||||||
| 60 | 15 | ▶ | { my ($self, $schema) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
prepareWriting: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 61 | 15 | $self->SUPER::prepareWriting($schema); | |||||||||||||||||||||||||||||||
| 62 | 15 | ▶ | return if $self->{XCWB_login}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 15 | my $nonce_type = $schema->findName('wsse:Nonce') ; | |||||||||||||||||||||||||||||||
| 65 | 15 | my $w_nonce = $schema->writer($nonce_type, include_namespaces => 0); | |||||||||||||||||||||||||||||||
| 66 | 9 | ▶ | my $make_nonce = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 67 | 9 | my ($doc, $nonce) = @_; | |||||||||||||||||||||||||||||||
| 68 | 9 | my $enc = encode_base64 $nonce; | |||||||||||||||||||||||||||||||
| 69 | 9 | chomp $enc; | |||||||||||||||||||||||||||||||
| 70 | 9 | $w_nonce->($doc, {_ => $enc, EncodingType => WSM10_BASE64}); | |||||||||||||||||||||||||||||||
| 71 | 15 | }; | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 15 | my $created_type = $schema->findName('wsu:Created'); | |||||||||||||||||||||||||||||||
| 74 | 15 | my $w_created = $schema->writer($created_type, include_namespaces => 0); | |||||||||||||||||||||||||||||||
| 75 | 14 | ▶ | my $make_created = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 76 | 14 | my ($doc, $created) = @_; | |||||||||||||||||||||||||||||||
| 77 | 14 | $w_created->($doc, $created); | |||||||||||||||||||||||||||||||
| 78 | 15 | }; | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 15 | my $pw_type = $schema->findName('wsse:Password'); | |||||||||||||||||||||||||||||||
| 81 | 15 | my $w_pw = $schema->writer($pw_type, include_namespaces => 0); | |||||||||||||||||||||||||||||||
| 82 | 15 | ▶ | my $make_pw = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 83 | 15 | my ($doc, $password, $pwformat) = @_; | |||||||||||||||||||||||||||||||
| 84 | 15 | $w_pw->($doc, {_ => $password, Type => $pwformat}); | |||||||||||||||||||||||||||||||
| 85 | 15 | }; | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | # UsernameToken is allowed to have an "wsu:Id" attribute | ||||||||||||||||||||||||||||||||
| 88 | # We set up the writer with a hook to add that particular attribute. | ||||||||||||||||||||||||||||||||
| 89 | 15 | my $un_type = $schema->findName('wsse:UsernameToken'); | |||||||||||||||||||||||||||||||
| 90 | 15 | my $make_un = $schema->writer($un_type, include_namespaces => 1, | |||||||||||||||||||||||||||||||
| 91 | , hook => $self->writerHookWsuId('wsse:UsernameTokenType')); | ||||||||||||||||||||||||||||||||
| 92 | 15 | $schema->prefixFor(WSU_10); # to get ns-decl | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 15 | ▶ | $self->{XCWB_login} = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||
| 95 | 15 | my ($doc, $data) = @_; | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 15 | my %login = | |||||||||||||||||||||||||||||||
| 98 | ( wsu_Id => $self->wsuId | ||||||||||||||||||||||||||||||||
| 99 | , wsse_Username => $self->username | ||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 15 | ▶ | my $now = delete $data->{wsu_Created} || $self->created; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
delete $data->{'wsu_Created'} || $self->created
MC/DC50%1/2
delete $data->{'wsu_Created'} || $self->created
delete $data->{'wsu_Created'}
$self->created
Truth table66%2/3
A || B
A= delete $data->{'wsu_Created'}B= $self->created
| |||||||||||||||||||||||||||||||||
| 103 | 15 | ▶ | my $created = $self->dateTime($now) || ''; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->dateTime($now) || ''
MC/DC100%1/1
$self->dateTime($now) || ''
$self->dateTime($now)
Truth table100%2/2
A
A= $self->dateTime($now)
| |||||||||||||||||||||||||||||||||
| 104 | 15 | ▶ | $login{$created_type} = $make_created->($doc, $created) if $created; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 15 | ▶ | my $nonce = delete $data->{wsse_Nonce} || $self->nonce || ''; | ||||||||||||||||||||||||||||||
|
Condition80%4/5
delete $data->{'wsse_Nonce'} || $self->nonce || ''
delete $data->{"wsse_Nonce"} or $self->nonce
MC/DC50%1/2
delete $data->{'wsse_Nonce'} || $self->nonce || ''
delete $data->{"wsse_Nonce"}
$self->nonce
Truth table66%2/3
A or B
A= delete $data->{"wsse_Nonce"}B= $self->nonce
| |||||||||||||||||||||||||||||||||
| 107 | 15 | ▶ | $login{$nonce_type} = $make_nonce->($doc, $nonce) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | if length $nonce; | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 15 | my $pwformat = $self->pwformat; | |||||||||||||||||||||||||||||||
| 111 | 15 | my $password = $self->password; | |||||||||||||||||||||||||||||||
| 112 | 15 | ▶ | $created = $created->{_} if ref $created eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 15 | ▶ | $password = sha1_base64(encode utf8 => "$nonce$created$password").'=' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | if $pwformat eq UTP11_PDIGEST; | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 15 | $login{$pw_type} = $make_pw->($doc, $password, $pwformat); | |||||||||||||||||||||||||||||||
| 117 | 15 | $data->{$un_type} = $make_un->($doc, \%login); | |||||||||||||||||||||||||||||||
| 118 | 15 | $data; | |||||||||||||||||||||||||||||||
| 119 | 15 | }; | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | sub create($$) | ||||||||||||||||||||||||||||||||
| 123 | 15 | ▶ | { my ($self, $doc, $data) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 124 | 15 | $self->SUPER::create($doc, $data); | |||||||||||||||||||||||||||||||
| 125 | 15 | $self->{XCWB_login}->($doc, $data); | |||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | 7 | 1; | |||||||||||||||||||||||||||||||