thekid/rfc — Issue #161: RFC 0161: Scriptlet Authenticator
Author: thekid
Created: 2011-10-09 15:30:07+00:00
State: open

Scope of Change
====
A getAuthenticator() method will be added to AbstractXMLScriptlet.

Rationale
====
Generalize authentication.

Functionality
====

RequestAuthenticator interface
----

```php

```

Example
----
In the scriptlet class, add the following:

```php
userInfo) return; // OK

// Dispatch - LoginHandler will redirect to original state
$request->session->putValue("target", $request->getStateName());
$request->dispatchTo("login");
}
}');
}

// ...
}
?>
```

Now create a LoginHandler:

```php
getParam('login_username'));
} catch (SQLException $e) {
return $this->addError($e->getClassName());
}

// Check if we can find the user
if (!$user) return $this->addError('doesnotexist');

// Verify password
if (!UnixCrypt::matches($user->getPassword(), $request->getParam('login_password'))) {
return $this->addError('incorrect');
}

// Check if account is active
if (20000 != $user->getBz_id()) {
return $this->addError('inactive');
}

// Authenticated, copy user information to context
$context->userInfo= array(
'user' => $user,
'person' => $user->getPerson()
);
$context->setChanged();
return TRUE;
}

/**
* Finalize this handler
*
* @param scriptlet.xml.workflow.WorkflowScriptletRequest request
* @param scriptlet.xml.XMLScriptletResponse response
* @param scriptlet.xml.Context context
*/
public function finalize($request, $response, $context) {
$request->forwardTo($response, $request->session->getValue('target', 'signup'));
$request->session->removeValue('target');
}
}
?>
```

Then create a LoginState class and add the LoginHandler to it:

```php
addHandler(new LoginHandler());
}
}

?>
```

Security considerations
====
n/a

Speed impact
====
n/a

Dependencies
====
- xp-framework/rfc #157

Related documents
====

Comments
====
- friebe, Wed Apr 16 09:59:16 2008
Current implementations that do not use the new API will work unaffected.