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.samples;
20  
21  import org.apache.shiro.realm.Realm;
22  import org.apache.shiro.realm.text.TextConfigurationRealm;
23  import org.springframework.boot.SpringApplication;
24  import org.springframework.boot.autoconfigure.SpringBootApplication;
25  import org.springframework.context.ConfigurableApplicationContext;
26  import org.springframework.context.annotation.Bean;
27  import org.springframework.context.annotation.Configuration;
28  
29  
30  /**
31   * Spring Boot Application that show the usage of a user login, checking permissions, and annotation protected methods.
32   *
33   * @see QuickStart
34   * @see SimpleService
35   */
36  @Configuration
37  @SpringBootApplication
38  public class CliApp { //NOPMD
39  
40      public static void main(String[] args) {
41  
42          ConfigurableApplicationContext context = SpringApplication.run(CliApp.class, args);
43  
44          // Grab the 'QuickStart' bean, call 'run()' to start the example.
45          context.getBean(QuickStart.class).run();
46      }
47  
48      /**
49       * Example hard coded Realm bean.
50       * @return hard coded Realm bean
51       */
52      @Bean
53      public Realm realm() {
54          TextConfigurationRealmonRealm.html#TextConfigurationRealm">TextConfigurationRealm realm = new TextConfigurationRealm();
55          realm.setUserDefinitions("joe.coder=password,user\n" +
56                                   "jill.coder=password,admin");
57  
58          realm.setRoleDefinitions("admin=read,write\n" +
59                                   "user=read");
60          realm.setCachingEnabled(true);
61          return realm;
62      }
63  
64  }