View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }