Created
July 24, 2014 07:36
-
-
Save agonist/853acbd47f717d23f6ef to your computer and use it in GitHub Desktop.
shiro activator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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