authentication - How to restrict access some part of module in ZendFramework 2 (i.e. only administrator can do some actions) -


It is!

I have a question: how to permit only access to some part of the module for adminisitrator, for example.

For example, I have a module album. It contains the controller index, delete, add, edit, complete. I need to be complete and available for all roles of the Index controller, but only add, remove and add action for the administrators.

Which module do I use to do this? I got Zend \ Authentification

table: username , password , role .

How to authenticate the user?:

// authentication $ auth = Zend_Auth :: getInstance (); $ Result = $ auth-> Authenticate ($ authAdapter); If ($ result-> gt; isValid ()) {// Success: Store the database in the store's store / system (though no password!) $ Data = $ authAdapter-> GetResultRowObject (empty, 'password'); $ Auth-> GetStorage () - & gt; ($ Data); $ This- & gt; _redirect ('/'); } And {// Failure: clear database row from $ 1 from session-> view-> Message = 'Login failed.'; }

After that, I will have access to user data, for example:

  Zend_Auth :: getInstance () - & gt; GetIdentity () - & gt; User name;  

Therefore, in action, in which I want to restrict access, I just need to use:

  if (Zend_Auth :: getInstance () - & Gt; GetIdentity () - & gt; Role == Administrator) {Redirect ("auth / login"); }  

right?

Question:

  1. Am I suggesting how to fix the user role in each contoller?

  2. Am I properly understanding how working with Zend \ Authentification and access to certain operations is restricted? So in future I will only use one for the same action, right?

Additional questions: Does the ACL module use to manage permissions? Requires ACL with Zend_Auth permissions, okay?

To enable you to create or implement an ACL (Access Control List) you You can also use a third party solution in conjunction with Zend_Auth mentioned earlier (or any other authentication module). You can read more at Zend ACL here:

For example, you can take a look at BjyAuthorize . This ACL module provides complete authorization solutions for your application, but the user depends on ZfcUser for authentication and registration. This can be a good way to get started.

If you are building or implementing Bjyuthorize , then you can easily check your routes (but there are many other ways). You can see how it works

These modules will teach you a lot about how certification and authorization can be made in your Zend Framework 2 application.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -