Update Apache Shiro Example code (#2453)
* added updated example codes * updated example code StringToCharStream * deleted StringToCharStream.java locally * removed redundant file * added code for apache commons collection SetUtils * refactored example code * added example code for bytebuddy * added example code for PCollections * update pom * refactored tests for PCollections * spring security xml config * spring security xml config * remove redundant comment * example code for apache-shiro
This commit is contained in:
parent
eeb89df150
commit
491fc883be
|
@ -2,22 +2,23 @@ package com.baeldung;
|
|||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.config.IniSecurityManagerFactory;
|
||||
import org.apache.shiro.mgt.DefaultSecurityManager;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
import org.apache.shiro.realm.Realm;
|
||||
import org.apache.shiro.realm.text.IniRealm;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.util.Factory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static final transient Logger log = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Factory<SecurityManager> factory
|
||||
= new IniSecurityManagerFactory("classpath:shiro.ini");
|
||||
SecurityManager securityManager = factory.getInstance();
|
||||
Realm realm = new MyCustomRealm();
|
||||
SecurityManager securityManager = new DefaultSecurityManager(realm);
|
||||
|
||||
SecurityUtils.setSecurityManager(securityManager);
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
jdbcRealm = com.baeldung.MyCustomRealm
|
||||
[users]
|
||||
user = password,admin
|
||||
user2 = password2,editor
|
||||
user3 = password3,author
|
||||
|
||||
securityManager.realms = $jdbcRealm
|
||||
[roles]
|
||||
admin = *
|
||||
editor = articles:*
|
||||
author = articles:compose,articles:save
|
Loading…
Reference in New Issue