Month: June 2008

Acegi RoleVoter

Adding new role to Acegi secured application may be painful sometime.

Tip of the day: by default RoleVoter is only accepting roles with names starting with prefix ROLE_ (take a look on javadoc here). You easily can change this prefix while defining RoleVoter bean (this is usually configured in file WEB-INF/security.xml)


That’s all for today about Acegi 😉


Eclipse Ganymede

Finally Eclipse 3.4 Ganymede has been officially released! While I’m currently working on Eclipse based product I was monitoring the progress of the platform beginning with Milestone 3. It looks like release 3.4 is moving Eclipse into the right direction. Provisioning mechanism was included into standard distribution, it is called p2. We probably have to wait some time to get more mature version of it – but it’s great that it is in a “main stream” now.

I really enjoy some enhancements that make working with Eclipse IDE more efficient:

  • Automatic updates done in background;
  • Option for determining network proxy settings from system instead of configuring them in preferences;
  • Mylyn extension for search plugin;

Small but annoying issue: Delta Pack is not included into standard distribution for RCP/Plugin development (bugzilla)! Fortunately there is now at least a message in editor for *.product configuration explaining that Delta Pack has to be installed separately (in Eclipse 3.3 you could spent several hours investigating the issue of missing Delta Pack).

Eclipse (anti)patterns (1).

Activator is a class in a Eclipse plugin which controls the plug-in life cycle. It contains methods like start(BundleContext context), stop(BundleContext context) and a static method Activator getDefault() – which returns static field plugin. What is interesting the the static field plugin is set in the non-static public method start(BundleContext context) or in a public constructor.
Such code is generated by Eclipse wizard for creating new plug-in. And this is Eclipse pattern for accessing the shared instance

Actually there are more places where this pattern is used in Eclipse framework and very often it is the only way for obtaining a reference to particular object. Let me discuss those later.

Capturing log-in event in Acegi

Adding some custom code that is supposed to be launched while user logs in it isn’t available out of the box but it can be done easily. In order to do this you have to implement interface org.springframework.context.ApplicationListener.

public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof AuthenticationSuccessEvent) {
        AuthenticationSuccessEvent authEvent = (AuthenticationSuccessEvent) event;
        String username = authEvent.getAuthentication().getName();
        // Any custom logic

Such listener has to be registered. In order to do this – just create a bean in xml configuration file where other Acegi related beans are declared (usually security.xml or applicationContext-security.xml).

<bean class="my.package.SomeExampleListener">
    <property name="someExampleManager" ref="someExampleManager"></property>

You can inject any required dependencies here.

That’s all!