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.SecurityUtils;
|
||||||
import org.apache.shiro.authc.*;
|
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.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.session.Session;
|
||||||
import org.apache.shiro.subject.Subject;
|
import org.apache.shiro.subject.Subject;
|
||||||
import org.apache.shiro.util.Factory;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private static final transient Logger log = LoggerFactory.getLogger(Main.class);
|
private static final transient Logger log = LoggerFactory.getLogger(Main.class);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Factory<SecurityManager> factory
|
Realm realm = new MyCustomRealm();
|
||||||
= new IniSecurityManagerFactory("classpath:shiro.ini");
|
SecurityManager securityManager = new DefaultSecurityManager(realm);
|
||||||
SecurityManager securityManager = factory.getInstance();
|
|
||||||
|
|
||||||
SecurityUtils.setSecurityManager(securityManager);
|
SecurityUtils.setSecurityManager(securityManager);
|
||||||
Subject currentUser = SecurityUtils.getSubject();
|
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…
x
Reference in New Issue
Block a user