Filename | /var/www/foswikidev/core/lib/Foswiki/Plugins/ModifyLoginPlugin.pm |
Statements | Executed 21 statements in 348µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 14µs | 27µs | BEGIN@42 | Foswiki::Plugins::ModifyLoginPlugin::
1 | 1 | 1 | 12µs | 20µs | initPlugin | Foswiki::Plugins::ModifyLoginPlugin::
1 | 1 | 1 | 12µs | 12µs | initializeUserHandler | Foswiki::Plugins::ModifyLoginPlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@44 | Foswiki::Plugins::ModifyLoginPlugin::
1 | 1 | 1 | 3µs | 3µs | BEGIN@45 | Foswiki::Plugins::ModifyLoginPlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for default license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+ package ModifyLoginPlugin | ||||
6 | |||||
7 | This is a simple plugin that can convert the login provided by the user | ||||
8 | to a the format needed by Foswiki server to identify the user. | ||||
9 | |||||
10 | It is typically used when you have a single sign on scheme like mod_ldap | ||||
11 | where the login name can be authenticated in more than one way. Typically | ||||
12 | ldap servers will authenticate users without paying attention to case. | ||||
13 | |||||
14 | This means that the same user can be authenticated as ABC123 and abc123 | ||||
15 | |||||
16 | Foswiki however is case sensitive. This means that users that sometimes use | ||||
17 | uppercase and sometimes lowercase login will often not be recognized by | ||||
18 | Foswiki but appear with their raw login name and maybe be denied access. | ||||
19 | |||||
20 | Using this plugin you can set | ||||
21 | Foswiki::cfg{Plugins}{ModifyLoginPlugin}{ChangeCase} to 'lower' and the user | ||||
22 | will always have his login name converted to lowercase. | ||||
23 | |||||
24 | Foswiki will then always see the user as his lowercase login. | ||||
25 | |||||
26 | The plugin has one additional independent feature. It can assign a login name | ||||
27 | based on a specific path. This is used to open a controlled backdoor to | ||||
28 | Foswiki via a specific list of topics. This enables creating a special user | ||||
29 | with a carefully assigned set of access rights. A typical use is to create | ||||
30 | a query page that can lookup information within a web without authentication. | ||||
31 | |||||
32 | A plugin may be implemented to look directly at the ENV and use the | ||||
33 | REMOTE_USER directly. This plugin cannot deal with that. But most plugin | ||||
34 | should behave correctly. | ||||
35 | |||||
36 | =cut | ||||
37 | |||||
38 | # change the package name!!! | ||||
39 | package Foswiki::Plugins::ModifyLoginPlugin; | ||||
40 | |||||
41 | # Always use strict to enforce variable scoping | ||||
42 | 2 | 28µs | 2 | 40µs | # spent 27µs (14+13) within Foswiki::Plugins::ModifyLoginPlugin::BEGIN@42 which was called:
# once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.25 at line 42 # spent 27µs making 1 call to Foswiki::Plugins::ModifyLoginPlugin::BEGIN@42
# spent 13µs making 1 call to strict::import |
43 | |||||
44 | 2 | 19µs | 1 | 4µs | # spent 4µs within Foswiki::Plugins::ModifyLoginPlugin::BEGIN@44 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.25 at line 44 # spent 4µs making 1 call to Foswiki::Plugins::ModifyLoginPlugin::BEGIN@44 |
45 | 2 | 265µs | 1 | 3µs | # spent 3µs within Foswiki::Plugins::ModifyLoginPlugin::BEGIN@45 which was called:
# once (3µs+0s) by Foswiki::Plugin::BEGIN@2.25 at line 45 # spent 3µs making 1 call to Foswiki::Plugins::ModifyLoginPlugin::BEGIN@45 |
46 | |||||
47 | # $VERSION is referred to by Foswiki, and is the only global variable that | ||||
48 | # *must* exist in this package. This should always be in the format | ||||
49 | # $Rev: 5771 $ so that Foswiki can determine the checked-in status of the | ||||
50 | # extension. | ||||
51 | 1 | 600ns | our $VERSION = '2.1'; | ||
52 | |||||
53 | # $RELEASE is used in the "Find More Extensions" automation in configure. | ||||
54 | 1 | 100ns | our $RELEASE = '2.1'; | ||
55 | |||||
56 | # Short description of this plugin | ||||
57 | # One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: | ||||
58 | 1 | 100ns | our $SHORTDESCRIPTION = | ||
59 | 'The plugin can modify a login by changing case or stripping all after @'; | ||||
60 | |||||
61 | # You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use | ||||
62 | # preferences set in the plugin topic. This is required for compatibility | ||||
63 | # with older plugins, but imposes a significant performance penalty, and | ||||
64 | # is not recommended. Instead, leave $NO_PREFS_IN_TOPIC at 1 and use | ||||
65 | # =$Foswiki::cfg= entries, or if you want the users | ||||
66 | # to be able to change settings, then use standard Foswiki preferences that | ||||
67 | # can be defined in your %USERSWEB%.SitePreferences and overridden at the web | ||||
68 | # and topic level. | ||||
69 | # | ||||
70 | # %SYSTEMWEB%.DevelopingPlugins has details of how to define =$Foswiki::cfg= | ||||
71 | # entries so they can be used with =configure=. | ||||
72 | 1 | 100ns | our $NO_PREFS_IN_TOPIC = 1; | ||
73 | |||||
74 | =begin TML | ||||
75 | |||||
76 | ---++ initPlugin($topic, $web, $user) -> $boolean | ||||
77 | * =$topic= - the name of the topic in the current CGI query | ||||
78 | * =$web= - the name of the web in the current CGI query | ||||
79 | * =$user= - the login name of the user | ||||
80 | * =$installWeb= - the name of the web the plugin topic is in | ||||
81 | (usually the same as =$Foswiki::cfg{SystemWebName}=) | ||||
82 | |||||
83 | *REQUIRED* | ||||
84 | |||||
85 | Called to initialise the plugin. If everything is OK, should return | ||||
86 | a non-zero value. On non-fatal failure, should write a message | ||||
87 | using =Foswiki::Func::writeWarning= and return 0. In this case | ||||
88 | %<nop>FAILEDPLUGINS% will indicate which plugins failed. | ||||
89 | |||||
90 | In the case of a catastrophic failure that will prevent the whole | ||||
91 | installation from working safely, this handler may use 'die', which | ||||
92 | will be trapped and reported in the browser. | ||||
93 | |||||
94 | __Note:__ Please align macro names with the Plugin name, e.g. if | ||||
95 | your Plugin is called !FooBarPlugin, name macros FOOBAR and/or | ||||
96 | FOOBARSOMETHING. This avoids namespace issues. | ||||
97 | |||||
98 | =cut | ||||
99 | |||||
100 | # spent 20µs (12+8) within Foswiki::Plugins::ModifyLoginPlugin::initPlugin which was called:
# once (12µs+8µs) by Foswiki::Plugin::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Plugin.pm:257] at line 250 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm | ||||
101 | 1 | 2µs | my ( $topic, $web, $user, $installWeb ) = @_; | ||
102 | |||||
103 | # check for Plugins.pm versions | ||||
104 | 1 | 14µs | 1 | 8µs | if ( $Foswiki::Plugins::VERSION < 2.0 ) { # spent 8µs making 1 call to version::vxs::VCMP |
105 | Foswiki::Func::writeWarning( 'Version mismatch between ', | ||||
106 | __PACKAGE__, ' and Plugins.pm' ); | ||||
107 | return 0; | ||||
108 | } | ||||
109 | |||||
110 | # Plugin correctly initialized | ||||
111 | 1 | 4µs | return 1; | ||
112 | } | ||||
113 | |||||
114 | =begin TML | ||||
115 | |||||
116 | ---++ initializeUserHandler( $loginName, $url, $pathInfo ) | ||||
117 | * =$loginName= - login name recovered from $ENV{REMOTE_USER} | ||||
118 | * =$url= - request url | ||||
119 | * =$pathInfo= - pathinfo from the CGI query | ||||
120 | Allows a plugin to set the username. Normally Foswiki gets the username | ||||
121 | from the login manager. This handler gives you a chance to override the | ||||
122 | login manager. | ||||
123 | |||||
124 | Return the *login* name. | ||||
125 | |||||
126 | This handler is called very early, immediately after =earlyInitPlugin=. | ||||
127 | |||||
128 | *Since:* Foswiki::Plugins::VERSION = '2.0' | ||||
129 | |||||
130 | =cut | ||||
131 | |||||
132 | # spent 12µs within Foswiki::Plugins::ModifyLoginPlugin::initializeUserHandler which was called:
# once (12µs+0s) by Foswiki::Plugin::load at line 212 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm | ||||
133 | 1 | 2µs | my ( $loginName, $url, $pathInfo ) = @_; | ||
134 | |||||
135 | # Map path to special users unless you are already authenticated as an | ||||
136 | # AdminGroup member | ||||
137 | 1 | 2µs | if ( | ||
138 | defined $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{MapPathToUser} | ||||
139 | {$pathInfo} | ||||
140 | && !Foswiki::Func::isAnAdmin($loginName) ) | ||||
141 | { | ||||
142 | return $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{MapPathToUser} | ||||
143 | {$pathInfo}; | ||||
144 | } | ||||
145 | |||||
146 | # Change case of login name | ||||
147 | # This plugin assumes {Register}{AllowLoginName}, otherwise it will do nothing | ||||
148 | |||||
149 | 1 | 900ns | return $loginName unless $Foswiki::cfg{Register}{AllowLoginName}; | ||
150 | |||||
151 | 1 | 2µs | if ( $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{ChangeCase} eq 'lowercase' ) | ||
152 | { | ||||
153 | $loginName = lc($loginName); | ||||
154 | } | ||||
155 | elsif ( | ||||
156 | $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{ChangeCase} eq 'uppercase' ) | ||||
157 | { | ||||
158 | $loginName = uc($loginName); | ||||
159 | } | ||||
160 | |||||
161 | # Strip everything from @ till the end of the login incl @ | ||||
162 | 1 | 800ns | if ( $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{StripAfterAtsign} ) { | ||
163 | 1 | 1µs | $loginName =~ s/@.*$//; | ||
164 | } | ||||
165 | |||||
166 | 1 | 4µs | return $loginName; | ||
167 | } | ||||
168 | |||||
169 | 1 | 3µs | 1; | ||
170 | __END__ |