![]() |
|
sfGuardPlugin - 1.1.13Identity management plugin. |
|
![]() |
560
users
Sign-in
to change your status |
Identity management plugin. |
The sfGuardPlugin is a symfony plugin that provides authentication and authorization features above the standard security feature of symfony.
It gives you the model (user, group and permission objects) and the modules (backend and frontend) to secure your symfony application in a minute in a configurable plugin.
| Name | Status | |
|---|---|---|
|
|
lead | su.pordnips <<ta>> hsad.evad |
|
|
lead | moc.tcejorp-ynofmys <<ta>> reicnetop.neibaf |
|
|
lead | |
|
|
developer | moc.tcejorp-ynofmys <<ta>> ottoninaz.siocnarf |
Copyright (c) 2004-2006 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 4.0.2stable | MIT license | 4.0.0stable | 28/08/2011 |
| 4.0.1stable | MIT license | 4.0.0stable | 16/07/2010 |
| 4.0.0stable | MIT license | 4.0.0stable | 30/11/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 4.0.2stable | MIT license | 4.0.0stable | 28/08/2011 |
| 4.0.1stable | MIT license | 4.0.0stable | 16/07/2010 |
| 4.0.0stable | MIT license | 4.0.0stable | 30/11/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 3.1.3stable | MIT license | 3.0.0stable | 05/12/2008 |
| 3.1.2stable | MIT license | 3.0.0stable | 27/11/2008 |
| 3.1.1stable | MIT license | 3.0.0stable | 18/11/2008 |
| 3.1.0stable | MIT license | 3.0.0stable | 13/11/2008 |
| 3.0.0stable | MIT license | 1.1.0stable | 08/10/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 2.2.0stable | MIT license | 1.1.0stable | 14/08/2008 |
| 2.1.0stable | MIT license | 1.1.0stable | 26/05/2008 |
| 2.0.2stable | MIT license | 1.1.0stable | 02/04/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 1.1.16stable | MIT license | 1.1.0stable | 14/08/2008 |
| 1.1.15stable | MIT license | 1.1.0stable | 26/05/2008 |
| 1.1.14stable | MIT license | 1.1.0stable | 02/04/2008 |
| 1.1.13stable | MIT license | 1.1.0stable | 26/02/2008 |
lib/model/plugin/ classes to make the model truly extensibleguard:promote taskguard:add-permission and guard:add-group taskssf_guard_plugin_signin_form configurationapp_sf_guard_plugin_check_password_callable callable (#3231)isSuperAdmin() method (#2719)app_sf_guard_plugin_check_password_callable callable (#3231)isSuperAdmin() method (#2719)lib/model/plugin/ classes to make the model truly extensibleThe sfGuardPlugin is a symfony plugin that provides authentication and authorization features above the standard security feature of symfony.
It gives you the model (user, group and permission objects) and the modules (backend and frontend) to secure your symfony application in a minute in a configurable plugin.
Install the plugin
symfony plugin-install http://plugins.symfony-project.com/sfGuardPlugin
Rebuild your model
symfony propel-build-model
symfony propel-build-sql
Update you database tables by starting from scratch (it will delete all the existing tables, then re-create them):
symfony propel-insert-sql
or you can just create the new tables by using the generated SQL statements in data/sql/plugins.sfGuardAuth.lib.model.schema.sql
Load default fixtures (optional - it creates a superadmin user)
symfony propel-load-data
Enable one or more modules in your settings.yml (optional)
For your frontend application: sfGuardAuth
all: .settings: enabled_modules: sfGuardGroup, sfGuardUser, sfGuardPermission
Clear you cache
symfony cc
Optionally enable the "Remember Me" filter in filters.yml
security:
class: sfGuardBasicSecurityFilter
To secure a symfony application:
Enable the module sfGuardAuth in settings.yml
all:
.settings:
enabled_modules: [sfGuardAuth](...,)
Change the default login and secure modules in settings.yml
login_module: sfGuardAuth
login_action: signin
secure_module: sfGuardAuth
secure_action: secure
Change the parent class in myUser.class.php
class myUser extends sfGuardSecurityUser
{
}
Optionally add the following routing rules to routing.yml
sf_guard_signin:
url: /login
param: { module: sfGuardAuth, action: signin }
sf_guard_signout:
url: /logout
param: { module: sfGuardAuth, action: signout }
sf_guard_password:
url: /request_password
param: { module: sfGuardAuth, action: password }
You can customize the url parameter of each route.
N.B.: You must have a @homepage routing rule (used when a user sign out)
These routes are automatically registered by the plugin if the module sfGuardAuth is enabled unless you defined sf_guard_plugin_routes_register to false
in the app.yml configuration file:
all:
sf_guard_plugin:
routes_register: false
Secure some modules or your entire application in security.yml
default:
is_secure: on
You're done. Now, if you try to access a secure page, you will be redirected to the login page.
If you have loaded the default fixture file, try to login with admin as username and admin as password.
To be able to manage your users, permissions and groups, sfGuardPlugin comes with 3 modules that can be integrated in your backend application.
These modules are auto-generated thanks to the symfony admin generator.
Enable the modules in settings.yml
all:
.settings:
enabled_modules: [sfGuardGroup, sfGuardPermission, sfGuardUser](...,)
Access the modules with the default route:
http://www.example.com/backend.php/sfGuardUser
By default, sfGuardAuth module comes with 2 very simple templates:
signinSuccess.phpsecureSuccess.phpIf you want to customize one of these templates:
Create a sfGuardAuth module in your application (don't use the init-module task, just create a sfGuardAuth directory)
Create a template with the name of the template you want to customize in the sfGuardAuth/templates directory
symfony now renders your template instead of the default one
sfGuardAuth module actionsIf you want to customize or add methods to the sfGuardAuth:
Create a sfGuardAuth module in your application
Create an actions.class.php file in your actions directory that inherit from BasesfGuardAuthActions
(don't forget to include the BasesfGuardAuthActions as it can't be autoloaded by symfony)
<?php
require_once(sfConfig::get('sf_plugins_dir').'/sfGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php');
class sfGuardAuthActions extends BasesfGuardAuthActions
{
public function executeNewAction()
{
return $this->renderText('This is a new sfGuardAuth action.');
}
}
sfGuardSecurityUser classThis class inherits from the sfBasicSecurityUser class from symfony and is used for the user object in your symfony application.
(because you changed the myUser base class earlier)
So, to access it, you can use the standard $this->getUser() in your actions or $sf_user in your templates.
sfGuardSecurityUser adds some methods:
signIn() and signOut() methodsgetGuardUser() that returns the sfGuardUser objectsfGuardUser objectFor example, to get the current username:
$this->getUser()->getGuardUser()->getUsername()
// or via the proxy method
$this->getUser()->getUsername()
sfGuardPlugin has a notion of super administrator. A user that is a super administrator bypasses all credential checks.
The super administrator flag cannot be set on the web, you must set the flag directly in the database or use the pake task:
symfony promote-super-admin admin
sfGuardPlugin comes with a validator that you can use in your modules: sfGuardUserValidator.
This validator is used by the sfGuardAuth module to validate a user and password and automatically signin the user.
sfAuthUser modelThe sfAuthUser model is quite simple. There is no email or first_name or birthday columns.
As you cannot add methods to the class, the sfAuthPlugin gives you the possibility to define a user profile class.
By default, sfAuthUser looks for a sfGuardUserProfile class.
Here is a simple example of a sfGuardProfile class that you can add to schema.yml:
sf_guard_user_profile:
_attributes: { phpName: sfGuardUserProfile }
id:
user_id: { type: integer, foreignTable: sf_guard_user, foreignReference: id, required: true, onDelete: cascade }
first_name: varchar(20)
last_name: varchar(20)
birthday: date
You can now access the user profile via the user object:
$this->getUser()->getGuardUser()->getProfile()->getFirstName()
// or via the proxy method
$this->getUser()->getProfile()->getFirstName()
The getProfile() method gets the associated user profile object or creates a new one if none already exists.
When you delete a user, the associated profile is also deleted.
You can change the name of the user profile class and the foreign key name in app.yml:
all:
sf_guard_plugin:
profile_class: sfGuardUserProfile
profile_field_name: user_id
If you don't want to store the password in the database because you already have a LDAP server, a .htaccess file or if you store
your passwords in another table, you can provide your own checkPassword callable (static method or function) in app.yml:
all:
sf_guard_plugin:
check_password_callable: [checkPassword](MyLDAPClass,)
When symfony will call the $this->getUser()->checkPassword() method, it will call your method or function. Your function must takes 2 parameters,
the first one is the username and the second one is the password. It must returns true or false. Here is a template for such a function:
function checkLDAPPassword($username, $password)
{
$user = LDAP::getUser($username);
if ($user->checkPassword($password))
{
return true;
}
else
{
return false;
}
}
By default, passwords are stored as a sha1() hash. But you can change this with any callable in app.yml:
all:
sf_guard_plugin:
algorithm_callable: [MyCryptoMethod](MyCryptoClass,)
or
all:
sf_guard_plugin:
algorithm_callable: md5
As the algorithm is stored for each user, you can change your mind later without the need to regenerate all passwords for the current users.
By default, the "Remember Me" feature creates a cookie named sfRemember that will last 15 days. You can change this behavior in app.yml:
all:
sf_guard_plugin:
remember_key_expiration_age: 2592000 # 30 days in seconds
remember_cookie_name: myAppRememberMe
sfGuardAuth redirect handlingIf you want to redirect the user to his profile after a success login or define a logout site.
You can change the redirect values in app.yml:
all:
sf_guard_plugin:
success_signin_url: @my_route?param=value # the plugin use the referer as default
success_signout_url: module/action # the plugin use the referer as default
promote_super_user taskgetPassword methodlib/model/plugin/ classes to make the model truly extensible
