Leser: 1
1 Eintrag, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/Perl/bin/perl
package MyAuthorizationTest;
use strict;
use warnings;
use base qw(CGI::Application);
use Data::Dumper qw/Dumper/;
use CGI::Application::Plugin::DBH qw/dbh_config dbh/;
use CGI::Application::Plugin::Authentication;
use CGI::Application::Plugin::Authorization;
=head1 MyAuthorizationTest
Overview Test for CGI::Application::Plugin::Authorization.
=cut
# Configure Authentication
MyAuthorizationTest->authen->config(
DRIVER => [ 'DBI',
TABLE => 'user',
CONSTRAINTS => {
'user.name' => '__CREDENTIAL_1__',
'MD5:user.password' => '__CREDENTIAL_2__'
},
],
STORE => ['Cookie',
SECRET => 'some_secret',
NAME => 'CAPAUTH_DATA',
EXPIRY => '+1y'
],
);
MyAuthorizationTest->authen->protected_runmodes(qr/^admin_/);
# Configure Authorization (manages runmode authorization)
MyAuthorizationTest->authz->config(
DRIVER => [ 'DBI',
TABLES => ['user', 'usergroup', 'group'],
JOIN_ON => 'user.id = usergroup.user_id AND usergroup.group_id = group.id',
CONSTRAINTS => {
'user.username' => '__USERNAME__',
'group.name' => '__GROUP__',
}
],
);
MyAuthorizationTest->authz->authz_runmodes(
[group_restriction => 'user'],
);
=head1 METHODS
=head2 setup()
=cut
sub setup {
my $self = shift;
$self->mode_param('rm');
$self->start_mode('start');
$self->run_modes({
start => 'select_mode_form',
select_mode_form => 'select_mode_form',
no_restriction => 'no_restriction',
group_restriction => 'group_restriction',
privilege_restriction => 'privilege_restriction',
});
} # /setup
=head2 cgiapp_init()
TODO: retrieve database credentials from config file.
=cut
sub cgiapp_init {
my $self = shift;
$self->dbh_config('DBI:mysql:test:localhost', 'test', 'test', {});
} # /cgiapp_init
=head2 select_mode_form()
Show a form where the user may choose a runmode he wants to execute.
=cut
sub select_mode_form {
my $self = shift;
my $t_ref = qq~
<h1>Available runmodes</h1>
<p>Select a runmode and check whenever you can access it or not.</p>
<ul>
<li><a href="<TMPL_VAR ABS_URL>?rm=no_restriction">no_restriction (should always work)</a></li>
<li><a href="<TMPL_VAR ABS_URL>?rm=group_restriction">group_restriction (needs user in a specific group)</a></li>
<li><a href="<TMPL_VAR ABS_URL>?rm=privilege_restriction">privilege_restriction
(needs user in a specific group and the privilege
to access this runmode assigned to the group)</a></li>
</ul>
~;
my $t = $self->load_tmpl( \$t_ref );
$t->param(ABS_URL => $self->query()->url(-absolute => 1,));
return $t->output();
return 'start';
} # /select_mode_form
=head2 no_restriction()
User always gets here.
=cut
sub no_restriction {
my $self = shift;
return 'no_restriction';
} # /no_restriction
=head2 group_restriction()
The user will only get here if they are logged in and belong to the 'user' group.
Fails:
Premature end of script headers: authorization.cgi
referer: http://127.0.0.1/cgi-bin/test/authorization.cgi
Error executing class callback in prerun stage:
Can't locate object method "authen" via package "CGI::Application::Plugin::Authorization::Driver::DBI"
at C:/Perl/site/lib/CGI/Application/Plugin/Authorization/Driver/DBI.pm line 229.
=cut
sub group_restriction {
my $self = shift;
return 'group_restriction';
} # /group_restriction
=head2 privilege_restriction()
TODO: this method
Privilegue for __PACKAGE__ and __RUNMODE__ are assigned to user, if he is able
to execute this runmode.
=cut
sub privilege_restriction {
my $self = shift;
# Can this user access this runmode in this package?
my $runmode = $self->get_current_runmode();
return $self->authz->forbidden() unless $self->authz('dbaccess')->authorize(MyAuthorizationTest => $runmode);
return 'privilege_restriction';
} # /privilege_restriction
1; # /MyCGIApp
use strict;
use warnings;
my $app = MyAuthorizationTest->new();
$app->run();
exit(0);
1 Eintrag, 1 Seite |