Reputation: 23
I have a xml based Apache Shiro SecurityManager and few custom realms (They extend build in realms). I am trying to migrate to Spring Boot, which is mostly annotation based.
I want to configure ALL realms into the security manager easily.Currently, I am able to do it by creating a ShiroConfig.java (annotated by @Configuration) , manually creating the object of each realm in the ShiroConfig and adding it under DefaultWebSecurityManager.setRealms(Collection).
Is there any other way, by which same thing can be achieved by annotation, where I annotate each Realm ,saying it's a realm and all of them will be added under security manager at runtime ?
Current xml configuration
<bean id="securityManager" class="com.abc.xyz.SecurityManager">
<property name="realms">
<set>
<ref component-id="Realm_1”/>
<ref component-id="Realm_2” />
<ref component-id="Realm_3” />
<ref component-id="Realm_4” />
</set>
</property>
</bean>
<bean id="Realm_1" class="com.abc.xyz.Realm_1”>
</bean>
<bean id="Realm_2" class="com.abc.xyz.Realm_2”>
</bean>
<bean id="Realm_3” class="com.abc.xyz.Realm_3”>
</bean>
<bean id="Realm_4” class="com.abc.xyz.Realm_4”>
</bean>
@Bean(name="securityManager")
public DefaultWebSecurityManager securityManager() {
DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
manager.setRealm(userRealm());
manager.setSessionManager(defaultWebSessionManager());
return manager;
}
@Bean @DependsOn(value="lifecycleBeanPostProcessor")
public Realm_1 userRealm() {
Realm_1 userRealm = new Realm_1();
return userRealm;
}
Upvotes: 1
Views: 941
Reputation: 2080
Shiro 1.4 is hot off the presses, we are working on getting the site updated now. But take a look at the examples, you can just inject your Realms in Spring and Spring-Boot.
Upvotes: 0