Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Camilo Arango is currently offline Camilo ArangoFriend
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
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 Go to previous messageGo to next message
Camilo Arango is currently offline Camilo ArangoFriend
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
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 Go to previous messageGo to next message
Camilo Arango is currently offline Camilo ArangoFriend
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 Go to previous messageGo to next message
Tonny Madsen is currently offline Tonny MadsenFriend
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
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.
Re: Enabling and disabling actions according to user priviledges [message #461903 is a reply to message #460951] Thu, 18 January 2007 08:52 Go to previous messageGo to next message
jmi is currently offline jmiFriend
Messages: 84
Registered: July 2009
Member
Hi,

In have exactly the same issue (RCP, Acegi, Spring).

Do you find a solution ?

Is it possible to have your code for logon using Acegi (with HttpInvoker ?)? Same question for Action issue if any.

Thanks
Re: Enabling and disabling actions according to user priviledges [message #461937 is a reply to message #461903] Thu, 18 January 2007 13:11 Go to previous messageGo to next message
Camilo Arango is currently offline Camilo ArangoFriend
Messages: 15
Registered: July 2009
Junior Member
> Is it possible to have your code for logon using
> Acegi (with HttpInvoker ?)? Same question for Action
> issue if any.

By all means. I have my proyect working with Acegi based auth over Eclipse. I solved my problems with actions sets, just like I described previously. What issues do you have?

Regards,

C. A.
Re: Enabling and disabling actions according to user priviledges [message #461938 is a reply to message #461890] Thu, 18 January 2007 13:13 Go to previous messageGo to next message
Camilo Arango is currently offline Camilo ArangoFriend
Messages: 15
Registered: July 2009
Junior Member
> 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.

I believe action sets can disable views, editors and perspectives as well. Take a look at the documentation to check this out.
Re: Enabling and disabling actions according to user priviledges [message #461949 is a reply to message #461937] Thu, 18 January 2007 15:45 Go to previous messageGo to next message
jmi is currently offline jmiFriend
Messages: 84
Registered: July 2009
Member
No issue for the moment.
I have to try first your solution. If i have problems, i come back to you.
Thanks
Re: Enabling and disabling actions according to user priviledges [message #461950 is a reply to message #461937] Thu, 18 January 2007 15:47 Go to previous messageGo to next message
jmi is currently offline jmiFriend
Messages: 84
Registered: July 2009
Member
No issue for the moment.
I have to try first your solution. If i have problems, i come back to you.
Thanks
Re: Enabling and disabling actions according to user priviledges [message #461959 is a reply to message #461950] Thu, 18 January 2007 20:21 Go to previous message
jmi is currently offline jmiFriend
Messages: 84
Registered: July 2009
Member
I just find an IBM article using Activity:

Creating a declarative security model for RCP applications

http://www-128.ibm.com/developerworks/opensource/library/os- ecl-rcpsec/?ca=dgr-jw17RCPbuilding
Previous Topic:Problems with Product Export within Eclipse: wrong content in created jars
Next Topic:Clicking the "X" close button to close the RCP app will not close the application. it leav
Goto Forum:
  


Current Time: Wed Sep 18 04:50:40 GMT 2024

Powered by FUDForum. Page generated in 0.04714 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top