Class AmfphpAuthentication

Description

Authentication for Amfphp.

This plugin can be deactivated if the project doesn't need to protect access to its services.

On a service object, the plugin looks for a method called _getMethodRoles. If the method exists, the plugin will look for a role in the session that matches the role. If the roles don't match, an Exception is thrown. The _getMethodRoles takes a parameter $methodName, and must return an array of strings containing acceptable roles for the method. If the return value is null, it is considered that that particular method is not protected.

For example:

  1.  public function _getMethodRoles($methodName){
  2.     if($methodName == 'adminMethod'){
  3.         return array('admin');
  4.     }else{
  5.         return null;
  6.     }
  7.  }

To authenticate a user, the plugin looks for a 'login' method. This method can either be called explicitly, or by setting a header with the name 'Credentials', containing {userid: userid, password: password}, as defined by the AS2 NetConnection.setCredentials method. It is considered good practise to have a 'logout' method, though this is optional The login method returns a role in a 'string'. It takes 2 parameters, the user id and the password. The logout method should call AmfphpAuthentication::clearSessionInfo();

See the AuthenticationService class in the test data for an example of an implementation.

Located in /Amfphp/Plugins/AmfphpAuthentication/AmfphpAuthentication.php (line 45)


	
			
Class Constant Summary
 METHOD_GET_METHOD_ROLES = '_getMethodRoles'
 METHOD_LOGIN = 'login'
 SESSION_FIELD_ROLES = 'amfphp_roles'
Variable Summary
Method Summary
static void addRole ( $roleToAdd, String $role)
static void clearSessionInfo ()
AmfphpAuthentication __construct ([ $config = null])
doRolesMatch ( $userRoles,  $acceptedRoles)
AmfphpAuthentication filterAmfRequestHeaderHandler (Object $handler,  $header)
filterServiceObject ( $serviceObject,  $serviceName,  $methodName)
void handleRequestHeader ( $header)
Variables
String $headerPassword (line 71)

the password passed in the credentials header

  • access: protected
String $headerUserId (line 65)

the user id passed in the credentials header

  • access: public
Methods
static method addRole (line 180)
  • access: public
static void addRole ( $roleToAdd, String $role)
  • String $role
  • $roleToAdd
static method clearSessionInfo (line 166)

clears the session info set by the plugin. Use to logout

  • access: public
static void clearSessionInfo ()
Constructor __construct (line 77)

constructor.

  • access: public
AmfphpAuthentication __construct ([ $config = null])
  • array $config: optional key/value pairs in an associative array. Used to override default configuration values.
doRolesMatch (line 149)

looks for a match between the user roles and the accepted roles

  • access: protected
doRolesMatch ( $userRoles,  $acceptedRoles)
  • $userRoles
  • $acceptedRoles
filterAmfRequestHeaderHandler (line 90)
  • access: public
AmfphpAuthentication filterAmfRequestHeaderHandler (Object $handler,  $header)
filterServiceObject (line 108)

called when the service object is created, just before the method call.

Tries to authenticate if a credentials header was sent in the packet. Throws an exception if the roles don't match

  • access: public
filterServiceObject ( $serviceObject,  $serviceName,  $methodName)
  • $serviceObject
  • $serviceName
  • $methodName
  • handleRequestHeader (line 205)

    looks for a 'Credentials' request header. If there is one, uses it to try to authentify the user.

    • access: public
    void handleRequestHeader ( $header)
    Class Constants
    METHOD_GET_METHOD_ROLES = '_getMethodRoles' (line 54)

    the name of the method on the service where the method roles are given

    METHOD_LOGIN = 'login' (line 59)

    the name of the login method

    SESSION_FIELD_ROLES = 'amfphp_roles' (line 49)

    the field in the session where the roles array is stored

    Documentation generated on Mon, 23 Jan 2012 17:22:01 -0300 by phpDocumentor 1.4.3