Filename | /var/www/foswikidev/core/lib/Foswiki/LoginManager/ApacheLogin.pm |
Statements | Executed 24 statements in 577µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 28µs | 117µs | new | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 13µs | 27µs | BEGIN@24 | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 11µs | 15µs | getUser | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 10µs | 14µs | BEGIN@25 | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 10µs | 40µs | BEGIN@26 | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 4µs | 4µs | __ANON__[:53] | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@28 | Foswiki::LoginManager::ApacheLogin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@31 | Foswiki::LoginManager::ApacheLogin::
0 | 0 | 0 | 0s | 0s | forceAuthentication | Foswiki::LoginManager::ApacheLogin::
0 | 0 | 0 | 0s | 0s | login | Foswiki::LoginManager::ApacheLogin::
0 | 0 | 0 | 0s | 0s | loginUrl | 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 | 30µs | 2 | 40µs | # spent 27µs (13+13) within Foswiki::LoginManager::ApacheLogin::BEGIN@24 which was called:
# once (13µs+13µs) by Foswiki::LoginManager::makeLoginManager at line 24 # spent 27µs making 1 call to Foswiki::LoginManager::ApacheLogin::BEGIN@24
# spent 13µs making 1 call to strict::import |
25 | 2 | 24µs | 2 | 18µs | # spent 14µs (10+4) within Foswiki::LoginManager::ApacheLogin::BEGIN@25 which was called:
# once (10µs+4µs) by Foswiki::LoginManager::makeLoginManager at line 25 # spent 14µs making 1 call to Foswiki::LoginManager::ApacheLogin::BEGIN@25
# spent 4µs making 1 call to warnings::import |
26 | 2 | 26µs | 2 | 70µs | # spent 40µs (10+30) within Foswiki::LoginManager::ApacheLogin::BEGIN@26 which was called:
# once (10µs+30µs) by Foswiki::LoginManager::makeLoginManager at line 26 # spent 40µs making 1 call to Foswiki::LoginManager::ApacheLogin::BEGIN@26
# spent 30µs making 1 call to Exporter::import |
27 | |||||
28 | 2 | 57µ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 | 8µs | our @ISA = ('Foswiki::LoginManager'); | ||
30 | |||||
31 | # spent 4µs within Foswiki::LoginManager::ApacheLogin::BEGIN@31 which was called:
# once (4µs+0s) by Foswiki::LoginManager::makeLoginManager at line 36 | ||||
32 | 1 | 5µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
33 | require locale; | ||||
34 | import locale(); | ||||
35 | } | ||||
36 | 1 | 384µs | 1 | 4µs | } # spent 4µs making 1 call to Foswiki::LoginManager::ApacheLogin::BEGIN@31 |
37 | |||||
38 | =begin TML | ||||
39 | |||||
40 | ---++ ClassMethod new ($session) | ||||
41 | |||||
42 | Construct the ApacheLogin object | ||||
43 | |||||
44 | =cut | ||||
45 | |||||
46 | # spent 117µs (28+89) within Foswiki::LoginManager::ApacheLogin::new which was called:
# once (28µs+89µs) by Foswiki::LoginManager::makeLoginManager at line 152 of /var/www/foswikidev/core/lib/Foswiki/LoginManager.pm | ||||
47 | 1 | 800ns | my ( $class, $session ) = @_; | ||
48 | 1 | 16µs | 1 | 83µs | my $this = $class->SUPER::new($session); # spent 83µs making 1 call to Foswiki::LoginManager::new |
49 | |||||
50 | 1 | 2µs | 1 | 4µs | $session->enterContext('can_login'); # spent 4µs making 1 call to Foswiki::enterContext |
51 | |||||
52 | # Can't logout, though | ||||
53 | 2 | 8µs | 1 | 2µs | # spent 4µs within Foswiki::LoginManager::ApacheLogin::__ANON__[/var/www/foswikidev/core/lib/Foswiki/LoginManager/ApacheLogin.pm:53] which was called:
# once (4µs+0s) by Foswiki::_expandMacroOnTopicRendering at line 3435 of /var/www/foswikidev/core/lib/Foswiki.pm # spent 2µs making 1 call to Foswiki::registerTagHandler |
54 | 1 | 3µs | return $this; | ||
55 | } | ||||
56 | |||||
57 | =begin TML | ||||
58 | |||||
59 | ---++ ObjectMethod forceAuthentication () -> boolean | ||||
60 | |||||
61 | method called when authentication is required - redirects to (...|view)auth | ||||
62 | Triggered on auth fail | ||||
63 | |||||
64 | =cut | ||||
65 | |||||
66 | sub forceAuthentication { | ||||
67 | my $this = shift; | ||||
68 | my $session = $this->{session}; | ||||
69 | my $query = $session->{request}; | ||||
70 | |||||
71 | # See if there is an 'auth' version | ||||
72 | # of this script, may be a result of not being logged in. | ||||
73 | my $newAction = $query->action() . 'auth'; | ||||
74 | |||||
75 | if ( !$query->remote_user() | ||||
76 | && exists $Foswiki::cfg{SwitchBoard}{$newAction} ) | ||||
77 | { | ||||
78 | |||||
79 | # Assemble the new URL using the host, the changed script name, | ||||
80 | # and the path info. | ||||
81 | my $url = $session->getScriptUrl( 1, $newAction ); | ||||
82 | if ( $query->path_info() ) { | ||||
83 | $url .= '/' | ||||
84 | unless $url =~ m#/$# || $query->path_info() =~ m#^/#; | ||||
85 | $url .= $query->path_info(); | ||||
86 | } | ||||
87 | |||||
88 | # Redirect with passthrough so we don't lose the original query params | ||||
89 | $session->redirect( $url, 1 ); | ||||
90 | return 1; | ||||
91 | } | ||||
92 | return 0; | ||||
93 | } | ||||
94 | |||||
95 | =begin TML | ||||
96 | |||||
97 | ---++ ObjectMethod loginUrl () -> $loginUrl | ||||
98 | |||||
99 | TODO: why is this not used internally? When is it called, and why | ||||
100 | Content of a login link | ||||
101 | |||||
102 | =cut | ||||
103 | |||||
104 | sub loginUrl { | ||||
105 | my $this = shift; | ||||
106 | my $session = $this->{session}; | ||||
107 | my $topic = $session->{topicName}; | ||||
108 | my $web = $session->{webName}; | ||||
109 | return $session->getScriptUrl( 0, 'logon', $web, $topic, @_ ); | ||||
110 | } | ||||
111 | |||||
112 | =begin TML | ||||
113 | |||||
114 | ---++ ObjectMethod login( $query, $session ) | ||||
115 | |||||
116 | this allows the login and logon cgi-scripts to use the same code. | ||||
117 | all a logon does, is re-direct to viewauth, and apache then figures out | ||||
118 | if it needs to challenge the user | ||||
119 | |||||
120 | =cut | ||||
121 | |||||
122 | sub login { | ||||
123 | my ( $this, $query, $session ) = @_; | ||||
124 | |||||
125 | my $url = | ||||
126 | $session->getScriptUrl( 0, 'viewauth', $session->{webName}, | ||||
127 | $session->{topicName}, t => time() ); | ||||
128 | |||||
129 | $url .= ( ';' . $query->query_string() ) if $query->query_string(); | ||||
130 | |||||
131 | $session->redirect( $url, 1 ); # with passthrough | ||||
132 | } | ||||
133 | |||||
134 | =begin TML | ||||
135 | |||||
136 | ---++ ObjectMethod getUser () -> $authUser | ||||
137 | |||||
138 | returns the userLogin if stored in the apache CGI query (ie session) | ||||
139 | |||||
140 | =cut | ||||
141 | |||||
142 | # spent 15µs (11+4) within Foswiki::LoginManager::ApacheLogin::getUser which was called:
# once (11µs+4µs) by Foswiki::LoginManager::loadSession at line 310 of /var/www/foswikidev/core/lib/Foswiki/LoginManager.pm | ||||
143 | 1 | 300ns | my $this = shift; | ||
144 | |||||
145 | 1 | 400ns | my $query = $this->{session}->{request}; | ||
146 | 1 | 100ns | my $authUser; | ||
147 | |||||
148 | # Ignore remote user if we got here via an error | ||||
149 | # Only useful with CGI engine & Apache webserver | ||||
150 | 1 | 1µs | unless ( ( $ENV{REDIRECT_STATUS} || 0 ) >= 400 ) { | ||
151 | 1 | 3µs | 1 | 3µs | $authUser = $query->remote_user() if $query; # spent 3µs making 1 call to Foswiki::Request::remoteUser |
152 | 1 | 2µs | 1 | 700ns | Foswiki::LoginManager::_trace( $this, # spent 700ns making 1 call to Foswiki::LoginManager::__ANON__[/var/www/foswikidev/core/lib/Foswiki/LoginManager.pm:237] |
153 | "apache getUser says " . ( $authUser || 'undef' ) ); | ||||
154 | } | ||||
155 | 1 | 4µs | return $authUser; | ||
156 | } | ||||
157 | |||||
158 | 1 | 3µs | 1; | ||
159 | __END__ |