Jun
30
2008
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)
<bean class="org.acegisecurity.vote.RoleVoter">
<property name="rolePrefix">
<value>YOUR_CUSTOM_PREFIX</value>
</property>
</bean>
That’s all for today about Acegi
Jun
14
2008
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>
</bean>
You can inject any required dependencies here.
That’s all!