1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.spring.boot.autoconfigure.web;
20
21
22 import org.apache.shiro.event.EventBus;
23 import org.apache.shiro.event.EventBusAware;
24 import org.apache.shiro.event.Subscribe;
25 import org.apache.shiro.realm.Realm;
26 import org.apache.shiro.realm.text.TextConfigurationRealm;
27 import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
28 import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
29 import org.springframework.boot.SpringApplication;
30 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
31 import org.springframework.context.annotation.Bean;
32 import org.springframework.context.annotation.Configuration;
33
34 @Configuration
35 @EnableAutoConfiguration
36 public class ShiroWebAutoConfigurationTestApplication {
37
38 public static void main(String[] args) {
39 SpringApplication.run(ShiroWebAutoConfigurationTestApplication.class, args);
40 }
41
42 @Bean
43 @SuppressWarnings("Duplicates")
44 Realm getTextConfigurationRealm() {
45
46 TextConfigurationRealm realm = new TextConfigurationRealm();
47 realm.setUserDefinitions("joe.coder=password,user\n" +
48 "jill.coder=password,admin");
49
50 realm.setRoleDefinitions("admin=read,write\n" +
51 "user=read");
52 realm.setCachingEnabled(true);
53 return realm;
54 }
55
56 @Bean
57 ShiroFilterChainDefinition shiroFilterChainDefinition() {
58 return new DefaultShiroFilterChainDefinition();
59 }
60
61 @Bean
62 EventBusAwareObject eventBusAwareObject() {
63 return new EventBusAwareObject();
64 }
65
66 @Bean
67 SubscribedListener subscribedListener() {
68 return new SubscribedListener();
69 }
70
71
72 public static class EventBusAwareObject implements EventBusAware {
73
74 private EventBus eventBus;
75
76 @Override
77 public void setEventBus(EventBus bus) {
78 this.eventBus = bus;
79 }
80
81 public EventBus getEventBus() {
82 return eventBus;
83 }
84 }
85
86 public static class SubscribedListener {
87
88 @Subscribe
89 public void onEvent(Object object) {}
90 }
91 }