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.application;
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 DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();
59 chainDefinition.addPathDefinition("/login.html", "authc");
60 return chainDefinition;
61 }
62
63 @Bean
64 EventBusAwareObject eventBusAwareObject() {
65 return new EventBusAwareObject();
66 }
67
68 @Bean
69 SubscribedListener subscribedListener() {
70 return new SubscribedListener();
71 }
72
73
74 public static class EventBusAwareObject implements EventBusAware {
75
76 private EventBus eventBus;
77
78 @Override
79 public void setEventBus(EventBus bus) {
80 this.eventBus = bus;
81 }
82
83 public EventBus getEventBus() {
84 return eventBus;
85 }
86 }
87
88 public static class SubscribedListener {
89
90 @Subscribe
91 public void onEvent(Object object) {}
92 }
93 }