Filename | /var/www/foswiki11/lib/Foswiki/Plugins/ModifyLoginPlugin.pm |
Statements | Executed 21 statements in 337µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 17µs | 27µs | initPlugin | Foswiki::Plugins::ModifyLoginPlugin::
1 | 1 | 1 | 14µs | 26µs | BEGIN@42 | Foswiki::Plugins::ModifyLoginPlugin::
1 | 1 | 1 | 9µs | 9µs | initializeUserHandler | Foswiki::Plugins::ModifyLoginPlugin::
1 | 1 | 1 | 3µs | 3µ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 | 27µs | 2 | 39µs | # spent 26µs (14+13) within Foswiki::Plugins::ModifyLoginPlugin::BEGIN@42 which was called:
# once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.22 at line 42 # spent 26µ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 | 3µs | # spent 3µs within Foswiki::Plugins::ModifyLoginPlugin::BEGIN@44 which was called:
# once (3µs+0s) by Foswiki::Plugin::BEGIN@2.22 at line 44 # spent 3µs making 1 call to Foswiki::Plugins::ModifyLoginPlugin::BEGIN@44 |
45 | 2 | 252µ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.22 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: 6504 (2010-02-24) $ so that Foswiki can determine the checked-in status of the | ||||
50 | # extension. | ||||
51 | 1 | 500ns | our $VERSION = '$Rev: 6504 (2010-02-24) $'; | ||
52 | |||||
53 | # $RELEASE is used in the "Find More Extensions" automation in configure. | ||||
54 | 1 | 200ns | our $RELEASE = '2.0'; | ||
55 | |||||
56 | # Short description of this plugin | ||||
57 | # One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: | ||||
58 | 1 | 200ns | our $SHORTDESCRIPTION = 'The plugin can modify a login by changing case or stripping all after @'; | ||
59 | |||||
60 | # You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use | ||||
61 | # preferences set in the plugin topic. This is required for compatibility | ||||
62 | # with older plugins, but imposes a significant performance penalty, and | ||||
63 | # is not recommended. Instead, leave $NO_PREFS_IN_TOPIC at 1 and use | ||||
64 | # =$Foswiki::cfg= entries, or if you want the users | ||||
65 | # to be able to change settings, then use standard Foswiki preferences that | ||||
66 | # can be defined in your %USERSWEB%.SitePreferences and overridden at the web | ||||
67 | # and topic level. | ||||
68 | # | ||||
69 | # %SYSTEMWEB%.DevelopingPlugins has details of how to define =$Foswiki::cfg= | ||||
70 | # entries so they can be used with =configure=. | ||||
71 | 1 | 200ns | our $NO_PREFS_IN_TOPIC = 1; | ||
72 | |||||
73 | =begin TML | ||||
74 | |||||
75 | ---++ initPlugin($topic, $web, $user) -> $boolean | ||||
76 | * =$topic= - the name of the topic in the current CGI query | ||||
77 | * =$web= - the name of the web in the current CGI query | ||||
78 | * =$user= - the login name of the user | ||||
79 | * =$installWeb= - the name of the web the plugin topic is in | ||||
80 | (usually the same as =$Foswiki::cfg{SystemWebName}=) | ||||
81 | |||||
82 | *REQUIRED* | ||||
83 | |||||
84 | Called to initialise the plugin. If everything is OK, should return | ||||
85 | a non-zero value. On non-fatal failure, should write a message | ||||
86 | using =Foswiki::Func::writeWarning= and return 0. In this case | ||||
87 | %<nop>FAILEDPLUGINS% will indicate which plugins failed. | ||||
88 | |||||
89 | In the case of a catastrophic failure that will prevent the whole | ||||
90 | installation from working safely, this handler may use 'die', which | ||||
91 | will be trapped and reported in the browser. | ||||
92 | |||||
93 | __Note:__ Please align macro names with the Plugin name, e.g. if | ||||
94 | your Plugin is called !FooBarPlugin, name macros FOOBAR and/or | ||||
95 | FOOBARSOMETHING. This avoids namespace issues. | ||||
96 | |||||
97 | =cut | ||||
98 | |||||
99 | # spent 27µs (17+10) within Foswiki::Plugins::ModifyLoginPlugin::initPlugin which was called:
# once (17µs+10µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm | ||||
100 | 1 | 2µs | my ( $topic, $web, $user, $installWeb ) = @_; | ||
101 | |||||
102 | # check for Plugins.pm versions | ||||
103 | 1 | 17µs | 1 | 10µs | if ( $Foswiki::Plugins::VERSION < 2.0 ) { # spent 10µs making 1 call to version::vxs::VCMP |
104 | Foswiki::Func::writeWarning( 'Version mismatch between ', | ||||
105 | __PACKAGE__, ' and Plugins.pm' ); | ||||
106 | return 0; | ||||
107 | } | ||||
108 | |||||
109 | # Plugin correctly initialized | ||||
110 | 1 | 6µs | return 1; | ||
111 | } | ||||
112 | |||||
113 | =begin TML | ||||
114 | |||||
115 | ---++ initializeUserHandler( $loginName, $url, $pathInfo ) | ||||
116 | * =$loginName= - login name recovered from $ENV{REMOTE_USER} | ||||
117 | * =$url= - request url | ||||
118 | * =$pathInfo= - pathinfo from the CGI query | ||||
119 | Allows a plugin to set the username. Normally Foswiki gets the username | ||||
120 | from the login manager. This handler gives you a chance to override the | ||||
121 | login manager. | ||||
122 | |||||
123 | Return the *login* name. | ||||
124 | |||||
125 | This handler is called very early, immediately after =earlyInitPlugin=. | ||||
126 | |||||
127 | *Since:* Foswiki::Plugins::VERSION = '2.0' | ||||
128 | |||||
129 | =cut | ||||
130 | |||||
131 | # spent 9µs within Foswiki::Plugins::ModifyLoginPlugin::initializeUserHandler which was called:
# once (9µs+0s) by Foswiki::Plugin::load at line 196 of /var/www/foswiki11/lib/Foswiki/Plugin.pm | ||||
132 | 1 | 800ns | my ( $loginName, $url, $pathInfo ) = @_; | ||
133 | |||||
134 | # Map path to special users | ||||
135 | 1 | 2µs | if ( defined $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{MapPathToUser}{$pathInfo} ) { | ||
136 | return $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{MapPathToUser}{$pathInfo}; | ||||
137 | } | ||||
138 | |||||
139 | # Change case of login name | ||||
140 | # This plugin assumes {Register}{AllowLoginName}, otherwise it will do nothing | ||||
141 | |||||
142 | 1 | 1µs | return $loginName unless $Foswiki::cfg{Register}{AllowLoginName}; | ||
143 | |||||
144 | 1 | 1µs | if ( $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{ChangeCase} eq 'lowercase' ) { | ||
145 | $loginName = lc($loginName); | ||||
146 | } | ||||
147 | elsif ( $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{ChangeCase} eq 'uppercase' ) { | ||||
148 | $loginName = uc($loginName); | ||||
149 | } | ||||
150 | |||||
151 | # Strip everything from @ till the end of the login incl @ | ||||
152 | 1 | 600ns | if ( $Foswiki::cfg{Plugins}{ModifyLoginPlugin}{StripAfterAtsign} ) { | ||
153 | 1 | 600ns | $loginName =~ s/@.*$//; | ||
154 | } | ||||
155 | |||||
156 | 1 | 4µs | return $loginName; | ||
157 | } | ||||
158 | |||||
159 | 1 | 3µs | 1; | ||
160 | __END__ |