Skip to content

Commit

Permalink
Update Apache Shiro Example code (eugenp#2453)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SeunMatt authored and zhendrikse committed Aug 16, 2017
1 parent eeb89df commit 491fc88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 6 additions & 5 deletions apache-shiro/src/main/java/com/baeldung/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

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();
Expand Down
10 changes: 8 additions & 2 deletions apache-shiro/src/main/resources/shiro.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 491fc88

Please sign in to comment.