01.12.2012 Views

7 Components: the Function Pages - Developers

7 Components: the Function Pages - Developers

7 Components: the Function Pages - Developers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

14.6<br />

A Mixed Strategy for Au<strong>the</strong>ntication<br />

In <strong>the</strong> following, we will consider <strong>the</strong> question as to how to accomplish<br />

having only certain pages require a login to be edited. It would<br />

seem obvious to use access controls alone to determine authorization<br />

variables. The problem, however, is that web servers only remember<br />

user names if an au<strong>the</strong>ntication is required. Without a user name,<br />

<strong>the</strong>re can be no au<strong>the</strong>ntication. Thus, if you remove <strong>the</strong> Edit script<br />

from au<strong>the</strong>ntication, it cannot determine who is attempting to edit a<br />

topic. Therefore, it assumes that editing is taking place via a guest<br />

account and will never grant access permission to <strong>the</strong> protected<br />

pages.<br />

TWiki offers a preset mechanism that remembers who has logged<br />

in. To activate this, you must go to <strong>the</strong> file Twiki.cfg and set <strong>the</strong> parameter<br />

$doRememberRemoteLogin to <strong>the</strong> value 1. Now TWiki<br />

will save your IP address along with your login name in a file when<br />

an au<strong>the</strong>nticated script is accessed. The next time any script is accessed<br />

via that IP address, <strong>the</strong> corresponding user name is retrieved<br />

from <strong>the</strong> file and is thus also known to non-au<strong>the</strong>nticated scripts. So,<br />

we could conceivably remove <strong>the</strong> .htaccess protection for <strong>the</strong> bin directory.<br />

You can also define <strong>the</strong> storage location for <strong>the</strong> IP addresses<br />

in Twiki.cfg. The respective parameter is $remoteUserFilename<br />

and, by default, leads to <strong>the</strong> file remoteusers.txt in <strong>the</strong> data directory.<br />

That leaves us with two more problems to solve. Firstly, we have<br />

to create a login link that triggers a one-time au<strong>the</strong>ntication, since<br />

<strong>the</strong> Edit script is no longer protected. Secondly, permanent storage<br />

and au<strong>the</strong>ntication via IP is very insecure, since IPs can easily be<br />

forged or, as is frequently <strong>the</strong> case, often change owners.<br />

The first problem is relatively easy to eliminate. In <strong>the</strong> bin directory,<br />

<strong>the</strong>re is a file called viewauth, which is an exact copy of <strong>the</strong><br />

view scripts. You can protect <strong>the</strong> file via .htaccess:<br />

<br />

require valid-user<br />

<br />

You can comment on <strong>the</strong> entries for all o<strong>the</strong>r files with a # at <strong>the</strong><br />

start of <strong>the</strong> line. The file viewauth now takes care of <strong>the</strong> login for us,<br />

since it is protected and thus prompts <strong>the</strong> browser for <strong>the</strong> registration<br />

dialogue. From <strong>the</strong>n on, <strong>the</strong> user is known and is logged in via IP.<br />

However, you still have to insert a login link that will invoke <strong>the</strong><br />

Identifying users<br />

via IP<br />

Problems<br />

Login link<br />

14.6 A Mixed Strategy for Au<strong>the</strong>ntication �<br />

�<br />

�<br />

213

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!