Skip to content

Instantly share code, notes, and snippets.

@agonist
Created July 24, 2014 07:36
Show Gist options
  • Save agonist/853acbd47f717d23f6ef to your computer and use it in GitHub Desktop.
Save agonist/853acbd47f717d23f6ef to your computer and use it in GitHub Desktop.
shiro activator
@Component
@Instantiate
public class ShiroActivator {
/**
* The famous {@link org.slf4j.Logger}
*/
private static final Logger logger = LoggerFactory.getLogger(ShiroActivator.class);
/**
* initialize shiro, by adding some roles and users
*/
@Validate
private void start() {
Ini ini = new Ini();
Ini.Section usr = ini.addSection(IniRealm.USERS_SECTION_NAME);
Ini.Section roles = ini.addSection(IniRealm.ROLES_SECTION_NAME);
roles.put("ADMIN", "*");
roles.put("GEST", "*");
usr.put("admin", "admin, ADMIN");
usr.put("guest", "guest, GUEST");
org.apache.shiro.mgt.SecurityManager securityManager = new DefaultSecurityManager(new IniRealm(ini));
SecurityUtils.setSecurityManager(securityManager);
}
@Invalidate
private void stop() {
SecurityUtils.setSecurityManager(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment