Home » Eclipse Projects » Rich Client Platform (RCP) » Enabling and disabling actions according to user priviledges
Enabling and disabling actions according to user priviledges [message #460951] |
Tue, 02 January 2007 21:26 |
Camilo Arango Messages: 15 Registered: July 2009 |
Junior Member |
|
|
Hi,
I am building an Eclipse RCP application using Acegi Security. After
login, I need to show the actions allowed to the user in the coolbar and
menus. However, I am having some trouble figuring out how to enable and
disable actions.
First, I created my action as a subclass of
org.eclipse.jface.action.Action and added to the Coolbar manually in the
Application ActionBarAdvisor. However, I was not able to figure out the
correct way of handling the enable and disable behavior.
Later, I found that I could add actions using the ActionsSet extension
point. To do so, the action must implement
org.eclipse.ui.IWorkbenchWindowActionDelegate. By doing this, I could
define a way to enable and disable actions using the "enablement" and
"visibility" elements of the action set extension point in my plugin.xml.
However, this mechanism is oriented to handle enablement driven by user
selection. The only two options which do not depend on user selection are
"pluginState" and "systemProperty". The former does not apply to this
case, and the latter seems kind of awkward for managing authorization.
I am a little bit confused on how to do this in an elegant way.
Can anyone give me some ideas?
Thanks.
|
|
|
Re: Enabling and disabling actions according to user priviledges [message #460953 is a reply to message #460951] |
Tue, 02 January 2007 21:34 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
The trick is fairly simple. You can access the actions added by plugins
when the workbench starts up and removing those the user is not allowed
to see said enough you can disable them easily as it looks like.
http://www.richclient2.eu/2006_03_20/getting-rid-of-convert- line-delimiters-to/
Tom
Camilo Arango schrieb:
> Hi,
>
> I am building an Eclipse RCP application using Acegi Security. After
> login, I need to show the actions allowed to the user in the coolbar and
> menus. However, I am having some trouble figuring out how to enable and
> disable actions.
>
> First, I created my action as a subclass of
> org.eclipse.jface.action.Action and added to the Coolbar manually in the
> Application ActionBarAdvisor. However, I was not able to figure out the
> correct way of handling the enable and disable behavior.
>
> Later, I found that I could add actions using the ActionsSet extension
> point. To do so, the action must implement
> org.eclipse.ui.IWorkbenchWindowActionDelegate. By doing this, I could
> define a way to enable and disable actions using the "enablement" and
> "visibility" elements of the action set extension point in my
> plugin.xml. However, this mechanism is oriented to handle enablement
> driven by user selection. The only two options which do not depend on
> user selection are "pluginState" and "systemProperty". The former does
> not apply to this case, and the latter seems kind of awkward for
> managing authorization.
> I am a little bit confused on how to do this in an elegant way.
>
> Can anyone give me some ideas?
>
> Thanks.
>
|
|
|
Re: Enabling and disabling actions according to user priviledges [message #460957 is a reply to message #460953] |
Tue, 02 January 2007 21:58 |
Camilo Arango Messages: 15 Registered: July 2009 |
Junior Member |
|
|
Thanks for the reply,
Hmm... as it appears, org.eclipse.ui.internal is not part of the RCP, so I
can't find the WorkbenchPlugin class. Is there any other mechanism to do
this?
Besides, I am not sure that removing the actions is the best choice,
because they would appear behind the login dialog and then disappear.
Any other thoughts?
Thanks,
C. A.
Tom Schindl wrote:
> Hi,
> The trick is fairly simple. You can access the actions added by plugins
> when the workbench starts up and removing those the user is not allowed
> to see said enough you can disable them easily as it looks like.
>
http://www.richclient2.eu/2006_03_20/getting-rid-of-convert- line-delimiters-to/
> Tom
> Camilo Arango schrieb:
>> Hi,
>>
>> I am building an Eclipse RCP application using Acegi Security. After
>> login, I need to show the actions allowed to the user in the coolbar and
>> menus. However, I am having some trouble figuring out how to enable and
>> disable actions.
>>
>> First, I created my action as a subclass of
>> org.eclipse.jface.action.Action and added to the Coolbar manually in the
>> Application ActionBarAdvisor. However, I was not able to figure out the
>> correct way of handling the enable and disable behavior.
>>
>> Later, I found that I could add actions using the ActionsSet extension
>> point. To do so, the action must implement
>> org.eclipse.ui.IWorkbenchWindowActionDelegate. By doing this, I could
>> define a way to enable and disable actions using the "enablement" and
>> "visibility" elements of the action set extension point in my
>> plugin.xml. However, this mechanism is oriented to handle enablement
>> driven by user selection. The only two options which do not depend on
>> user selection are "pluginState" and "systemProperty". The former does
>> not apply to this case, and the latter seems kind of awkward for
>> managing authorization.
>> I am a little bit confused on how to do this in an elegant way.
>>
>> Can anyone give me some ideas?
>>
>> Thanks.
>>
|
|
|
Re: Enabling and disabling actions according to user priviledges [message #461026 is a reply to message #460957] |
Wed, 03 January 2007 21:14 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
after some debuging, ... and digging around in the sources the situation
is fairly easy if you control *all* Action-Delegates.
- do the privileges checks in selectionChanged(IAction action,
ISelection selection) is called directly after the delegate is
created.
- you simply have to implement the IActionDelegate2-Interface and when
the delegate is created the first method called afterwards is
init(IAction action) where you can check the privileges.
If you are interested in the code where I read the behaviour from it is:
org.eclipse.ui.internal.PluginAction
The second solution is the save way if you ask me because
IActionDelegate2#init(IAction)'s javadoc states that it is immediately
called when the delegate is instantiated whereas solution one might be
an implementation detail that can change.
Tom
Camilo Arango schrieb:
> Thanks for the reply,
>
> Hmm... as it appears, org.eclipse.ui.internal is not part of the RCP, so
> I can't find the WorkbenchPlugin class. Is there any other mechanism to
> do this?
>
> Besides, I am not sure that removing the actions is the best choice,
> because they would appear behind the login dialog and then disappear.
>
> Any other thoughts?
>
> Thanks,
>
> C. A.
>
> Tom Schindl wrote:
>
>> Hi,
>
>> The trick is fairly simple. You can access the actions added by plugins
>> when the workbench starts up and removing those the user is not allowed
>> to see said enough you can disable them easily as it looks like.
>
>>
> http://www.richclient2.eu/2006_03_20/getting-rid-of-convert- line-delimiters-to/
>
>
>> Tom
>
>> Camilo Arango schrieb:
>>> Hi,
>>>
>>> I am building an Eclipse RCP application using Acegi Security. After
>>> login, I need to show the actions allowed to the user in the coolbar and
>>> menus. However, I am having some trouble figuring out how to enable and
>>> disable actions.
>>>
>>> First, I created my action as a subclass of
>>> org.eclipse.jface.action.Action and added to the Coolbar manually in the
>>> Application ActionBarAdvisor. However, I was not able to figure out the
>>> correct way of handling the enable and disable behavior.
>>>
>>> Later, I found that I could add actions using the ActionsSet extension
>>> point. To do so, the action must implement
>>> org.eclipse.ui.IWorkbenchWindowActionDelegate. By doing this, I could
>>> define a way to enable and disable actions using the "enablement" and
>>> "visibility" elements of the action set extension point in my
>>> plugin.xml. However, this mechanism is oriented to handle enablement
>>> driven by user selection. The only two options which do not depend on
>>> user selection are "pluginState" and "systemProperty". The former does
>>> not apply to this case, and the latter seems kind of awkward for
>>> managing authorization.
>>> I am a little bit confused on how to do this in an elegant way.
>>>
>>> Can anyone give me some ideas?
>>>
>>> Thanks.
>>>
>
>
|
|
|
Re: Enabling and disabling actions according to user priviledges [message #461075 is a reply to message #461026] |
Thu, 04 January 2007 20:14 |
Camilo Arango Messages: 15 Registered: July 2009 |
Junior Member |
|
|
Hello Tom,
Thanks you for taking some time to answer my question, but I am not quite sure that the solution you proposed is the answer to my problem.
My actions implement IWorkbenchWindowActionDelegate, so according to what you said, that I make the security check in the init method (and throw an Exception if it fails..?). I guess this would prevent the action from initializing if the security check is not passed.
However, what I would like to do is hide and show actions according to the user priviledges. Let me explain this a little bit. I show my login dialog in the WorkbenchAdvisor.postStartup() method, so the user interface is already shown previous to the authentication. When the user has completed the login process, the software retrieves his granted privileges, and I want to populate the toolbars and menus with just the actions available to him, according to those privileges.
I have been digging and reading a lot since yesterday and I think I have found a mechanism that could do the trick nicely: define an Activity for each granted privilege, which would be bounded to the actions. This activities are disabled by default, so initially the interface would appear clean. After a successful login, I could enable the necessary activities by calling PlatformUI.getWorkbench().getActivitySupport().setEnabledAct ivityIds(..).
A nice thing about this solution is that anytime during the application life, I could enable or disable some of the activities again, for example, if the user authenticated again using a higher role.
I would greatly appreciate some opinions on this solution.
Regards,
C.A.
|
|
|
Re: Enabling and disabling actions according to user priviledges [message #461890 is a reply to message #461075] |
Wed, 17 January 2007 20:43 |
Tonny Madsen Messages: 22 Registered: July 2009 |
Junior Member |
|
|
Hi Camilo,
I have had the same problem as you, but I also want to enable/disable
other parts of the interface as well. Especially alot of extension
stuff, such as views, editors, perspecitiveExtensions, etc.
And whereas the solution from Tom address action sets (and other forms
of actions), I cannot see how I can use this to handle the other
extension stuff as well.
The only way, I can think of is via OSGi and enable/disable of the
specific bundles. Of cause that will have to happen before the workbench
is initiated, but that is posible in the ApplicationAdvisor.
Any comments?
Regards,
Tonny Madsen
CEO, The RCP Company
http://rcp-company.com
Camilo Arango wrote:
> Hello Tom,
>
> Thanks you for taking some time to answer my question, but I am not quite sure that the solution you proposed is the answer to my problem.
>
> My actions implement IWorkbenchWindowActionDelegate, so according to what you said, that I make the security check in the init method (and throw an Exception if it fails..?). I guess this would prevent the action from initializing if the security check is not passed.
>
> However, what I would like to do is hide and show actions according to the user priviledges. Let me explain this a little bit. I show my login dialog in the WorkbenchAdvisor.postStartup() method, so the user interface is already shown previous to the authentication. When the user has completed the login process, the software retrieves his granted privileges, and I want to populate the toolbars and menus with just the actions available to him, according to those privileges.
>
> I have been digging and reading a lot since yesterday and I think I have found a mechanism that could do the trick nicely: define an Activity for each granted privilege, which would be bounded to the actions. This activities are disabled by default, so initially the interface would appear clean. After a successful login, I could enable the necessary activities by calling PlatformUI.getWorkbench().getActivitySupport().setEnabledAct ivityIds(..).
>
> A nice thing about this solution is that anytime during the application life, I could enable or disable some of the activities again, for example, if the user authenticated again using a higher role.
>
> I would greatly appreciate some opinions on this solution.
>
> Regards,
>
> C.A.
|
|
|
Re: Enabling and disabling actions according to user priviledges [message #461891 is a reply to message #461890] |
Wed, 17 January 2007 20:59 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
http://wiki.eclipse.org/index.php/Product_Customization
http://wiki.eclipse.org/index.php/Equinox_Transforms
Tom
Tonny Madsen schrieb:
> Hi Camilo,
>
> I have had the same problem as you, but I also want to enable/disable
> other parts of the interface as well. Especially alot of extension
> stuff, such as views, editors, perspecitiveExtensions, etc.
>
> And whereas the solution from Tom address action sets (and other forms
> of actions), I cannot see how I can use this to handle the other
> extension stuff as well.
>
> The only way, I can think of is via OSGi and enable/disable of the
> specific bundles. Of cause that will have to happen before the workbench
> is initiated, but that is posible in the ApplicationAdvisor.
>
> Any comments?
>
> Regards,
>
> Tonny Madsen
> CEO, The RCP Company
> http://rcp-company.com
>
> Camilo Arango wrote:
>> Hello Tom,
>>
>> Thanks you for taking some time to answer my question, but I am not
>> quite sure that the solution you proposed is the answer to my problem.
>> My actions implement IWorkbenchWindowActionDelegate, so according to
>> what you said, that I make the security check in the init method (and
>> throw an Exception if it fails..?). I guess this would prevent the
>> action from initializing if the security check is not passed.
>>
>> However, what I would like to do is hide and show actions according to
>> the user priviledges. Let me explain this a little bit. I show my
>> login dialog in the WorkbenchAdvisor.postStartup() method, so the user
>> interface is already shown previous to the authentication. When the
>> user has completed the login process, the software retrieves his
>> granted privileges, and I want to populate the toolbars and menus with
>> just the actions available to him, according to those privileges.
>>
>> I have been digging and reading a lot since yesterday and I think I
>> have found a mechanism that could do the trick nicely: define an
>> Activity for each granted privilege, which would be bounded to the
>> actions. This activities are disabled by default, so initially the
>> interface would appear clean. After a successful login, I could enable
>> the necessary activities by calling
>> PlatformUI.getWorkbench().getActivitySupport().setEnabledAct ivityIds(..).
>>
>> A nice thing about this solution is that anytime during the
>> application life, I could enable or disable some of the activities
>> again, for example, if the user authenticated again using a higher role.
>>
>> I would greatly appreciate some opinions on this solution.
>>
>> Regards,
>>
>> C.A.
|
|
| | | | | | |
Goto Forum:
Current Time: Wed Jan 15 09:11:21 GMT 2025
Powered by FUDForum. Page generated in 0.03706 seconds
|