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.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  }