Filename | /var/www/foswiki11/lib/Foswiki/LoginManager/ApacheLogin.pm |
Statements | Executed 33 statements in 548µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 27µs | 120µs | new | Foswiki::LoginManager::ApacheLogin::
2 | 1 | 1 | 22µs | 169µs | loginUrl | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 15µs | 28µs | BEGIN@24 | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 11µs | 13µs | getUser | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 10µs | 15µs | BEGIN@25 | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 9µs | 9µs | __ANON__[:46] | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 8µs | 22µs | BEGIN@26 | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@28 | Foswiki::LoginManager::ApacheLogin::
0 | 0 | 0 | 0s | 0s | forceAuthentication | Foswiki::LoginManager::ApacheLogin::
0 | 0 | 0 | 0s | 0s | login | Foswiki::LoginManager::ApacheLogin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+ package Foswiki::LoginManager::ApacheLogin | ||||
6 | |||||
7 | This is login manager that you can specify in the security setup section of | ||||
8 | [[%SCRIPTURL{"configure"}%][configure]]. It instructs Foswiki to | ||||
9 | cooperate with your web server (typically Apache) to require authentication | ||||
10 | information (username & password) from users. It requires that you configure | ||||
11 | your web server to demand authentication for scripts named "login" and anything | ||||
12 | ending in "auth". The latter should be symlinks to existing scripts; e.g., | ||||
13 | =viewauth -> view=, =editauth -> edit=, and so on. | ||||
14 | |||||
15 | See also UserAuthentication. | ||||
16 | |||||
17 | Subclass of Foswiki::LoginManager; see that class for documentation of the | ||||
18 | methods of this class. | ||||
19 | |||||
20 | =cut | ||||
21 | |||||
22 | package Foswiki::LoginManager::ApacheLogin; | ||||
23 | |||||
24 | 2 | 28µs | 2 | 41µs | # spent 28µs (15+13) within Foswiki::LoginManager::ApacheLogin::BEGIN@24 which was called:
# once (15µs+13µs) by Foswiki::LoginManager::makeLoginManager at line 24 # spent 28µs making 1 call to Foswiki::LoginManager::ApacheLogin::BEGIN@24
# spent 13µs making 1 call to strict::import |
25 | 2 | 28µs | 2 | 20µs | # spent 15µs (10+5) within Foswiki::LoginManager::ApacheLogin::BEGIN@25 which was called:
# once (10µs+5µs) by Foswiki::LoginManager::makeLoginManager at line 25 # spent 15µs making 1 call to Foswiki::LoginManager::ApacheLogin::BEGIN@25
# spent 5µs making 1 call to warnings::import |
26 | 2 | 27µs | 2 | 36µs | # spent 22µs (8+14) within Foswiki::LoginManager::ApacheLogin::BEGIN@26 which was called:
# once (8µs+14µs) by Foswiki::LoginManager::makeLoginManager at line 26 # spent 22µs making 1 call to Foswiki::LoginManager::ApacheLogin::BEGIN@26
# spent 14µs making 1 call to Assert::import |
27 | |||||
28 | 2 | 388µs | 1 | 4µs | # spent 4µs within Foswiki::LoginManager::ApacheLogin::BEGIN@28 which was called:
# once (4µs+0s) by Foswiki::LoginManager::makeLoginManager at line 28 # spent 4µs making 1 call to Foswiki::LoginManager::ApacheLogin::BEGIN@28 |
29 | 1 | 7µs | our @ISA = ('Foswiki::LoginManager'); | ||
30 | |||||
31 | =begin TML | ||||
32 | |||||
33 | ---++ ClassMethod new ($session) | ||||
34 | |||||
35 | Construct the ApacheLogin object | ||||
36 | |||||
37 | =cut | ||||
38 | |||||
39 | # spent 120µs (27+94) within Foswiki::LoginManager::ApacheLogin::new which was called:
# once (27µs+94µs) by Foswiki::LoginManager::makeLoginManager at line 136 of /var/www/foswiki11/lib/Foswiki/LoginManager.pm | ||||
40 | 1 | 800ns | my ( $class, $session ) = @_; | ||
41 | 1 | 15µs | 1 | 88µs | my $this = $class->SUPER::new($session); # spent 88µs making 1 call to Foswiki::LoginManager::new |
42 | |||||
43 | 1 | 2µs | 1 | 4µs | $session->enterContext('can_login'); # spent 4µs making 1 call to Foswiki::enterContext |
44 | |||||
45 | # Can't logout, though | ||||
46 | 2 | 13µs | 1 | 2µs | # spent 9µs within Foswiki::LoginManager::ApacheLogin::__ANON__[/var/www/foswiki11/lib/Foswiki/LoginManager/ApacheLogin.pm:46] which was called:
# once (9µs+0s) by Foswiki::_expandMacroOnTopicRendering at line 3160 of /var/www/foswiki11/lib/Foswiki.pm # spent 2µs making 1 call to Foswiki::registerTagHandler |
47 | 1 | 3µs | return $this; | ||
48 | } | ||||
49 | |||||
50 | =begin TML | ||||
51 | |||||
52 | ---++ ObjectMethod forceAuthentication () -> boolean | ||||
53 | |||||
54 | method called when authentication is required - redirects to (...|view)auth | ||||
55 | Triggered on auth fail | ||||
56 | |||||
57 | =cut | ||||
58 | |||||
59 | sub forceAuthentication { | ||||
60 | my $this = shift; | ||||
61 | my $session = $this->{session}; | ||||
62 | my $query = $session->{request}; | ||||
63 | |||||
64 | # See if there is an 'auth' version | ||||
65 | # of this script, may be a result of not being logged in. | ||||
66 | my $newAction = $query->action() . 'auth'; | ||||
67 | |||||
68 | if ( !$query->remote_user() | ||||
69 | && exists $Foswiki::cfg{SwitchBoard}{$newAction} ) | ||||
70 | { | ||||
71 | |||||
72 | # Assemble the new URL using the host, the changed script name, | ||||
73 | # and the path info. | ||||
74 | my $url = $session->getScriptUrl( 1, $newAction ); | ||||
75 | if ( $query->path_info() ) { | ||||
76 | $url .= '/' | ||||
77 | unless $url =~ m#/$# || $query->path_info() =~ m#^/#; | ||||
78 | $url .= $query->path_info(); | ||||
79 | } | ||||
80 | |||||
81 | # Redirect with passthrough so we don't lose the original query params | ||||
82 | $session->redirect( $url, 1 ); | ||||
83 | return 1; | ||||
84 | } | ||||
85 | return 0; | ||||
86 | } | ||||
87 | |||||
88 | =begin TML | ||||
89 | |||||
90 | ---++ ObjectMethod loginUrl () -> $loginUrl | ||||
91 | |||||
92 | TODO: why is this not used internally? When is it called, and why | ||||
93 | Content of a login link | ||||
94 | |||||
95 | =cut | ||||
96 | |||||
97 | # spent 169µs (22+147) within Foswiki::LoginManager::ApacheLogin::loginUrl which was called 2 times, avg 85µs/call:
# 2 times (22µs+147µs) by Foswiki::LoginManager::_LOGIN at line 1154 of /var/www/foswiki11/lib/Foswiki/LoginManager.pm, avg 85µs/call | ||||
98 | 2 | 1µs | my $this = shift; | ||
99 | 2 | 2µs | my $session = $this->{session}; | ||
100 | 2 | 2µs | my $topic = $session->{topicName}; | ||
101 | 2 | 1µs | my $web = $session->{webName}; | ||
102 | 2 | 17µs | 2 | 147µs | return $session->getScriptUrl( 0, 'logon', $web, $topic, @_ ); # spent 147µs making 2 calls to Foswiki::getScriptUrl, avg 74µs/call |
103 | } | ||||
104 | |||||
105 | =begin TML | ||||
106 | |||||
107 | ---++ ObjectMethod login( $query, $session ) | ||||
108 | |||||
109 | this allows the login and logon cgi-scripts to use the same code. | ||||
110 | all a logon does, is re-direct to viewauth, and apache then figures out | ||||
111 | if it needs to challenge the user | ||||
112 | |||||
113 | =cut | ||||
114 | |||||
115 | sub login { | ||||
116 | my ( $this, $query, $session ) = @_; | ||||
117 | |||||
118 | my $url = | ||||
119 | $session->getScriptUrl( 0, 'viewauth', $session->{webName}, | ||||
120 | $session->{topicName}, t => time() ); | ||||
121 | |||||
122 | $url .= ( ';' . $query->query_string() ) if $query->query_string(); | ||||
123 | |||||
124 | $session->redirect( $url, 1 ); # with passthrough | ||||
125 | } | ||||
126 | |||||
127 | =begin TML | ||||
128 | |||||
129 | ---++ ObjectMethod getUser () -> $authUser | ||||
130 | |||||
131 | returns the userLogin if stored in the apache CGI query (ie session) | ||||
132 | |||||
133 | =cut | ||||
134 | |||||
135 | # spent 13µs (11+3) within Foswiki::LoginManager::ApacheLogin::getUser which was called:
# once (11µs+3µs) by Foswiki::LoginManager::loadSession at line 296 of /var/www/foswiki11/lib/Foswiki/LoginManager.pm | ||||
136 | 1 | 300ns | my $this = shift; | ||
137 | |||||
138 | 1 | 500ns | my $query = $this->{session}->{request}; | ||
139 | 1 | 100ns | my $authUser; | ||
140 | |||||
141 | # Ignore remote user if we got here via an error | ||||
142 | # Only useful with CGI engine & Apache webserver | ||||
143 | 1 | 1µs | unless ( ( $ENV{REDIRECT_STATUS} || 0 ) >= 400 ) { | ||
144 | 1 | 2µs | 1 | 2µs | $authUser = $query->remote_user() if $query; # spent 2µs making 1 call to Foswiki::Request::remoteUser |
145 | 1 | 2µs | 1 | 700ns | Foswiki::LoginManager::_trace( $this, # spent 700ns making 1 call to Foswiki::LoginManager::__ANON__[/var/www/foswiki11/lib/Foswiki/LoginManager.pm:225] |
146 | "apache getUser says " . ( $authUser || 'undef' ) ); | ||||
147 | } | ||||
148 | 1 | 3µs | return $authUser; | ||
149 | } | ||||
150 | |||||
151 | 1 | 3µs | 1; | ||
152 | __END__ |