How to fix Authorizer issue

Posts   
 
    
Austinn
User
Posts: 38
Joined: 25-Aug-2008
# Posted on: 08-Apr-2011 21:21:11   

I have noticed when ever I am trying to authorize a user against a group. The Authorizer is always executing while Entity.SaveEntity() method is called.

Is there any way that I can Authorize user against a role before executing the save function

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Apr-2011 22:14:37   

The OnCanSaveNewEntity and OnCanSaveExistingEntity are called before the entity is save. It means you call entity.Save, then these methods are internally called from your auditor and if the save is not authorized, no save action occurs (it's ignored).

If you want something like ...

bool authorized = myAuthorizer.Authorize()

... the answer is no, there is no such method in the Authorizer. You can add it to your own Authorizer class.

David Elizondo | LLBLGen Support Team
Austinn
User
Posts: 38
Joined: 25-Aug-2008
# Posted on: 09-Apr-2011 14:02:55   

Thanks friend, will try soon....

Austinn
User
Posts: 38
Joined: 25-Aug-2008
# Posted on: 10-Apr-2011 16:37:26   

The issue is that in my app when a user is clicking the save button I am prompting the user "Are you sure you want to save the record." If user says yes, then I am calling Entity.Save(). So in this case how can I inform the user that he is not allowed to save a new entity because of his user rights, but I want to inform the user before prompting him about the save.

I mean when user selects "Yes" on the prompt then Entity.Save() is called and then we came to know OHHH, this guys is not allowed. I want this authorization to be done before prompting the user. so how can I achive this.....

I hope I am able to describe my issue.

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Apr-2011 00:11:45   

Your issue is more focused on how you want to control the flow of the user messages. If you really want to show an error message before asking the user whether or not to perform the save, then you need to perform the authorization check outside the LLBLGen Authorizer or in a special method you can call from the Authorizer.

If you are ok with the flow: Ask the user, then inform if there is an authorization rule broken, then, in your authorizer implementation you throw exceptions (see examples and docs), then in your GUI you can trap them to show them to the user.

David Elizondo | LLBLGen Support Team