(no commit message)
[openafs-wiki.git] / TWiki / TWikiLoginManagerDotPm.mdwn
1 # <a name="Package &lt;code&gt;TWiki::_LoginManager="></a> Package =TWiki::LoginManager
2
3 The package is also a Factory for login managers and also the base class for all login managers.
4
5 On it's own, an object of this class is used when you specify 'none' in the security setup section of [configure](http://www.dementia.org/twiki/configure). When it is used, logins are not supported. If you want to authenticate users then you should consider [[TemplateLogin]] or [[ApacheLogin]], which are subclasses of this class.
6
7 If you are building a new login manager, then you should write a new subclass of this class, implementing the methods marked as **VIRTUAL**. There are already examples in the `lib/TWiki/LoginManager` directory.
8
9 The class has extensive tracing, which is enabled by $TWiki::cfg\{Trace\}\{LoginManager.pm\}. The tracing is done in such a way as to let the perl optimiser optimise out the trace function as a no-op if tracing is disabled.
10
11 Here's an overview of how it works:
12
13 Early in TWiki::new, the login manager is created. The creation of the login manager does two things:
14
15 1. If sessions are in use, it loads CGI::Session but doesn't initialise the session yet.
16 2. Creates the login manager object
17
18 Slightly later in TWiki::new, loginManager-&gt;loadSession is called.
19
20 1. Calls loginManager-&gt;getUser to get the username **before** the session is created
21   - TWiki::LoginManager::ApacheLogin looks at REMOTE\_USER (only for authenticated scripts)
22   - TWiki::LoginManager::TemplateLogin just returns undef
23 2. reads the TWIKISID cookie to get the SID (or the TWIKISID parameters in the CGI query if cookies aren't available, or [[IP2SID]] mapping if that's enabled).
24 3. Creates the CGI::Session object, and the session is thereby read.
25 4. If the username still isn't known, reads it from the cookie. Thus TWiki::LoginManager::ApacheLogin overrides the cookie using REMOTE\_USER, and TWiki::LoginManager::TemplateLogin **always** uses the session.
26
27 Later again in TWiki::new, plugins are given a chance to **override** the username found from the loginManager.
28
29 The last step in TWiki::new is to find the user, using whatever user mapping manager is in place.
30
31 ## <a name="ObjectData &lt;code&gt;twiki="></a> [[ObjectData]] =twiki
32
33 The TWiki object this login manager is attached to.
34
35 <div>
36   <ul>
37     <li><a href="#Package =TWiki::_LoginManager="> Package TWiki::LoginManager</a><ul>
38         <li><a href="#ObjectData =twiki="> ObjectData twiki</a></li>
39         <li><a href="#StaticMethod *make_LoginManager*"> StaticMethod makeLoginManager <tt>($twiki) -&gt; $TWiki::LoginManager</tt></a></li>
40         <li><a href="#ClassMethod <strong>new</strong> ($session,$imp"> ClassMethod new <tt>($session,$impl)</tt></a></li>
41         <li><a href="#ObjectMethod <strong>finish</strong> ()"> ObjectMethod finish <tt>()</tt></a></li>
42         <li><a href="#ClassMethod <strong>_real_trace</strong> ($sess"> ClassMethod _real_trace <tt>($session,$impl)</tt></a></li>
43         <li><a href="#ClassMethod <strong>_IP2SID</strong> ($session,"> ClassMethod _IP2SID <tt>($session,$impl)</tt></a></li>
44         <li><a href="#ObjectMethod <strong>loadSession</strong> ($def"> ObjectMethod loadSession <tt>($defaultUser) -&gt; $login</tt></a></li>
45         <li><a href="#ObjectMethod <strong>checkAccess</strong> ()"> ObjectMethod checkAccess <tt>()</tt></a></li>
46         <li><a href="#ObjectMethod <strong>complete</strong> ()"> ObjectMethod complete <tt>()</tt></a></li>
47         <li><a href="#StaticMethod *expire_DeadSession"> StaticMethod expireDeadSessions <tt>()</tt></a></li>
48         <li><a href="#ObjectMethod <strong>user_LoggedIn</strong> ($l"> ObjectMethod userLoggedIn <tt>($login,$wikiname)</tt></a></li>
49         <li><a href="#ObjectMethod <strong>_my_ScriptURLRE</strong> ("> ObjectMethod _myScriptURLRE <tt>($thisl)</tt></a></li>
50         <li><a href="#ObjectMethod <strong>_rewriteURL</strong> ($thi"> ObjectMethod _rewriteURL <tt>($thisl)</tt></a></li>
51         <li><a href="#ObjectMethod <strong>_rewriteFORM</strong> ($th"> ObjectMethod _rewriteFORM <tt>($thisl)</tt></a></li>
52         <li><a href="#ObjectMethod *end_RenderingHandl"> ObjectMethod endRenderingHandler <tt>()</tt></a></li>
53         <li><a href="#ObjectMethod <strong>_pushCookie</strong> ($thi"> ObjectMethod _pushCookie <tt>($thisl)</tt></a></li>
54         <li><a href="#ObjectMethod <strong>addCookie</strong> ($c)"> ObjectMethod addCookie <tt>($c)</tt></a></li>
55         <li><a href="#ObjectMethod <strong>modifyHeader</strong> (\%h"> ObjectMethod modifyHeader <tt>(\%header)</tt></a></li>
56         <li><a href="#ObjectMethod *redirect_CgiQuery*"> ObjectMethod redirectCgiQuery <tt>($url)</tt></a></li>
57         <li><a href="#ObjectMethod *get_SessionValues*"> ObjectMethod getSessionValues <tt>() -&gt; \%values</tt></a></li>
58         <li><a href="#ObjectMethod *get_SessionValue*"> ObjectMethod getSessionValue <tt>($name) -&gt; $value</tt></a></li>
59         <li><a href="#ObjectMethod *set_SessionValue*"> ObjectMethod setSessionValue <tt>($name,$value)</tt></a></li>
60         <li><a href="#ObjectMethod *clear_SessionValue"> ObjectMethod clearSessionValue <tt>($name) -&gt; $boolean</tt></a></li>
61         <li><a href="#ObjectMethod *forceAuthenticatio"> ObjectMethod forceAuthentication <tt>() -&gt; boolean</tt></a></li>
62         <li><a href="#ObjectMethod <strong>loginUrl</strong> (...) ->"> ObjectMethod loginUrl <tt>(...) -&gt; $url</tt></a></li>
63         <li><a href="#ObjectMethod <strong>getUser</strong> ()"> ObjectMethod getUser <tt>()</tt></a></li>
64         <li><a href="#ObjectMethod <strong>_LOGIN</strong> ($thisl)"> ObjectMethod _LOGIN <tt>($thisl)</tt></a></li>
65         <li><a href="#ObjectMethod <strong>_LOGOUTURL</strong> ($this"> ObjectMethod _LOGOUTURL <tt>($thisl)</tt></a></li>
66         <li><a href="#ObjectMethod <strong>_LOGOUT</strong> ($thisl)"> ObjectMethod _LOGOUT <tt>($thisl)</tt></a></li>
67         <li><a href="#ObjectMethod <strong>_AUTHENTICATED</strong> ($"> ObjectMethod _AUTHENTICATED <tt>($thisl)</tt></a></li>
68         <li><a href="#ObjectMethod <strong>_CANLOGIN</strong> ($thisl"> ObjectMethod _CANLOGIN <tt>($thisl)</tt></a></li>
69         <li><a href="#ObjectMethod *_SESSION_VARIABLE*"> ObjectMethod _SESSION_VARIABLE <tt>($thisl)</tt></a></li>
70         <li><a href="#ObjectMethod <strong>_LOGINURL</strong> ($thisl"> ObjectMethod _LOGINURL <tt>($thisl)</tt></a></li>
71         <li><a href="#ObjectMethod <strong>_dispLogon</strong> ($this"> ObjectMethod _dispLogon <tt>($thisl)</tt></a></li>
72         <li><a href="#PrivateMethod _skinSelect ()"> PrivateMethod _skinSelect ()</a></li>
73       </ul>
74     </li>
75   </ul>
76 </div>
77
78 ## <a name="StaticMethod &lt;strong&gt;make_LoginManager*"></a> [[StaticMethod]] \*makeLoginManager `($twiki) -> $TWiki::LoginManager`
79
80 Factory method, used to generate a new TWiki::LoginManager object for the given session.
81
82 ## <a name="ClassMethod &lt;strong&gt;new&lt;/strong&gt; ($session,$imp"></a> [[ClassMethod]] **new** `($session,$impl)`
83
84 Construct the user management object
85
86 ## <a name="ObjectMethod &lt;strong&gt;finish&lt;/strong&gt; ()"></a> [[ObjectMethod]] **finish** `()`
87
88 Break circular references.
89
90 ## <a name="ClassMethod &lt;strong&gt;_real_trace&lt;/strong&gt; ($sess"></a> [[ClassMethod]] **\_real\_trace** `($session,$impl)`
91
92 Construct the user management object
93
94 ## <a name="ClassMethod &lt;strong&gt;_IP2SID&lt;/strong&gt; ($session,"></a> [[ClassMethod]] **\_IP2SID** `($session,$impl)`
95
96 read/write IP to SID map, return SID
97
98 ## <a name="ObjectMethod &lt;strong&gt;loadSession&lt;/strong&gt; ($def"></a> [[ObjectMethod]] **loadSession** `($defaultUser) -> $login`
99
100 Get the client session data, using the cookie and/or the request URL. Set up appropriate session variables in the twiki object and return the login name.
101
102 $defaultUser is a username to use if one is not available from other sources. The username passed when you create a TWiki instance is passed in here.
103
104 ## <a name="ObjectMethod &lt;strong&gt;checkAccess&lt;/strong&gt; ()"></a> [[ObjectMethod]] **checkAccess** `()`
105
106 Check if the script being run in this session is authorised for execution. If not, throw an access control exception.
107
108 ## <a name="ObjectMethod &lt;strong&gt;complete&lt;/strong&gt; ()"></a> [[ObjectMethod]] **complete** `()`
109
110 Complete processing after the client's HTTP request has been responded to. Flush the user's session (if any) to disk.
111
112 ## <a name="StaticMethod &lt;strong&gt;expire_DeadSession"></a> [[StaticMethod]] \*expireDeadSessions `()`
113
114 Delete sessions and passthrough files that are sitting around but are really expired. This **assumes** that the sessions are stored as files.
115
116 This is a static method, but requires TWiki::cfg. It is designed to be run from a session or from a cron job.
117
118 ## <a name="ObjectMethod &lt;strong&gt;user_LoggedIn&lt;/strong&gt; ($l"></a> [[ObjectMethod]] **userLoggedIn** `($login,$wikiname)`
119
120 Called when the user is known. It's invoked from TWiki::UI::Register::finish for instance,
121
122 1. when the user follows the link in their verification email message
123 2. or when the session store is read
124 3. when the user authenticates (via templatelogin / sudo)
125
126 - `$login` - string login name
127 - `$wikiname` - string wikiname
128
129 ## <a name="ObjectMethod &lt;strong&gt;_my_ScriptURLRE&lt;/strong&gt; ("></a> [[ObjectMethod]] **\_myScriptURLRE** `($thisl)`
130
131 ## <a name="ObjectMethod &lt;strong&gt;_rewriteURL&lt;/strong&gt; ($thi"></a> [[ObjectMethod]] **\_rewriteURL** `($thisl)`
132
133 ## <a name="ObjectMethod &lt;strong&gt;_rewriteFORM&lt;/strong&gt; ($th"></a> [[ObjectMethod]] **\_rewriteFORM** `($thisl)`
134
135 ## <a name="ObjectMethod &lt;strong&gt;end_RenderingHandl"></a> [[ObjectMethod]] \*endRenderingHandler `()`
136
137 This handler is called by getRenderedVersion just before the plugins postRenderingHandler. So it is passed all HTML text just before it is printed.
138
139 **DEPRECATED** Use postRenderingHandler instead.
140
141 ## <a name="ObjectMethod &lt;strong&gt;_pushCookie&lt;/strong&gt; ($thi"></a> [[ObjectMethod]] **\_pushCookie** `($thisl)`
142
143 ## <a name="ObjectMethod &lt;strong&gt;addCookie&lt;/strong&gt; ($c)"></a> [[ObjectMethod]] **addCookie** `($c)`
144
145 Add a cookie to the list of cookies for this session.
146
147 - `$c` - a CGI::Cookie
148
149 ## <a name="ObjectMethod &lt;strong&gt;modifyHeader&lt;/strong&gt; (\%h"></a> [[ObjectMethod]] **modifyHeader** `(\%header)`
150
151 Modify a HTTP header
152
153 - `\%header` - header entries
154
155 ## <a name="ObjectMethod &lt;strong&gt;redirect_CgiQuery*"></a> [[ObjectMethod]] \*redirectCgiQuery `($url)`
156
157 Generate an HTTP redirect on STDOUT, if you can. Return 1 if you did.
158
159 - `$url` - target of the redirection.
160
161 ## <a name="ObjectMethod &lt;strong&gt;get_SessionValues*"></a> [[ObjectMethod]] \*getSessionValues `() -> \%values`
162
163 Get a name-&gt;value hash of all the defined session variables
164
165 ## <a name="ObjectMethod &lt;strong&gt;get_SessionValue*"></a><a name="ObjectMethod *get_SessionValue&lt;/strong&gt; "></a> [[ObjectMethod]] **getSessionValue** `($name) -> $value`
166
167 Get the value of a session variable.
168
169 ## <a name="ObjectMethod &lt;strong&gt;set_SessionValue*"></a><a name="ObjectMethod *set_SessionValue&lt;/strong&gt; "></a> [[ObjectMethod]] **setSessionValue** `($name,$value)`
170
171 Set the value of a session variable. We do not allow setting of AUTHUSER.
172
173 ## <a name="ObjectMethod &lt;strong&gt;clear_SessionValue"></a> [[ObjectMethod]] \*clearSessionValue `($name) -> $boolean`
174
175 Clear the value of a session variable. We do not allow setting of AUTHUSER.
176
177 ## <a name="ObjectMethod &lt;strong&gt;forceAuthenticatio"></a> [[ObjectMethod]] \*forceAuthentication `() -> boolean`
178
179 **VIRTUAL METHOD** implemented by subclasses
180
181 Triggered by an access control violation, this method tests to see if the current session is authenticated or not. If not, it does whatever is needed so that the user can log in, and returns 1.
182
183 If the user has an existing authenticated session, the function simply drops though and returns 0.
184
185 ## <a name="ObjectMethod &lt;strong&gt;loginUrl&lt;/strong&gt; (...) -"></a><a name="ObjectMethod &lt;strong&gt;loginUrl&lt;/strong&gt; (...) - "></a> [[ObjectMethod]] **loginUrl** `(...) -> $url`
186
187 **VIRTUAL METHOD** implemented by subclasses
188
189 Return a full URL suitable for logging in.
190
191 - `...` - url parameters to be added to the URL, in the format required by TWiki::getScriptUrl()
192
193 ## <a name="ObjectMethod &lt;strong&gt;getUser&lt;/strong&gt; ()"></a> [[ObjectMethod]] **getUser** `()`
194
195 **VIRTUAL METHOD** implemented by subclasses
196
197 If there is some other means of getting a username - for example, Apache has remote\_user() - then return it. Otherwise, return undef and the username stored in the session will be used.
198
199 ## <a name="ObjectMethod &lt;strong&gt;_LOGIN&lt;/strong&gt; ($thisl)"></a> [[ObjectMethod]] **\_LOGIN** `($thisl)`
200
201 ## <a name="ObjectMethod &lt;strong&gt;_LOGOUTURL&lt;/strong&gt; ($this"></a> [[ObjectMethod]] **\_LOGOUTURL** `($thisl)`
202
203 ## <a name="ObjectMethod &lt;strong&gt;_LOGOUT&lt;/strong&gt; ($thisl)"></a> [[ObjectMethod]] **\_LOGOUT** `($thisl)`
204
205 ## <a name="ObjectMethod &lt;strong&gt;_AUTHENTICATED&lt;/strong&gt; ($"></a> [[ObjectMethod]] **\_AUTHENTICATED** `($thisl)`
206
207 ## <a name="ObjectMethod &lt;strong&gt;_CANLOGIN&lt;/strong&gt; ($thisl"></a> [[ObjectMethod]] **\_CANLOGIN** `($thisl)`
208
209 ## <a name="ObjectMethod &lt;strong&gt;_SESSION_VARIABLE*"></a> [[ObjectMethod]] \*\_SESSION\_VARIABLE `($thisl)`
210
211 ## <a name="ObjectMethod &lt;strong&gt;_LOGINURL&lt;/strong&gt; ($thisl"></a> [[ObjectMethod]] **\_LOGINURL** `($thisl)`
212
213 ## <a name="ObjectMethod &lt;strong&gt;_dispLogon&lt;/strong&gt; ($this"></a> [[ObjectMethod]] **\_dispLogon** `($thisl)`
214
215 ## <a name="PrivateMethod _skinSelect ()"></a> [[PrivateMethod]] \_skinSelect ()
216
217 Internal use only TODO: what does it do?