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.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.springframework.boot.SpringApplication;
28 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
29 import org.springframework.context.annotation.Bean;
30 import org.springframework.context.annotation.Configuration;
31
32 @Configuration
33 @EnableAutoConfiguration
34 public class ShiroAutoConfigurationTestApplication {
35
36 public static void main(String[] args) {
37 SpringApplication.run(ShiroAutoConfigurationTestApplication.class, args);
38 }
39
40 @Bean
41 @SuppressWarnings("Duplicates")
42 Realm getTextConfigurationRealm() {
43
44 TextConfigurationRealm realm = new TextConfigurationRealm();
45 realm.setUserDefinitions("joe.coder=password,user\n" +
46 "jill.coder=password,admin");
47
48 realm.setRoleDefinitions("admin=read,write\n" +
49 "user=read");
50 realm.setCachingEnabled(true);
51 return realm;
52 }
53
54 @Bean
55 EventBusAwareObject eventBusAwareObject() {
56 return new EventBusAwareObject();
57 }
58
59 @Bean
60 SubscribedListener subscribedListener() {
61 return new SubscribedListener();
62 }
63
64
65 public static class EventBusAwareObject implements EventBusAware {
66
67 private EventBus eventBus;
68
69 @Override
70 public void setEventBus(EventBus bus) {
71 this.eventBus = bus;
72 }
73
74 public EventBus getEventBus() {
75 return eventBus;
76 }
77 }
78
79 public static class SubscribedListener {
80
81 @Subscribe
82 public void onEvent(Object object) {}
83 }
84 }