001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.shiro.samples;
020
021import org.apache.shiro.realm.Realm;
022import org.apache.shiro.realm.text.TextConfigurationRealm;
023import org.springframework.boot.SpringApplication;
024import org.springframework.boot.autoconfigure.SpringBootApplication;
025import org.springframework.context.ConfigurableApplicationContext;
026import org.springframework.context.annotation.Bean;
027import org.springframework.context.annotation.Configuration;
028
029
030/**
031 * Spring Boot Application that show the usage of a user login, checking permissions, and annotation protected methods.
032 *
033 * @see QuickStart
034 * @see SimpleService
035 */
036@Configuration
037@SpringBootApplication
038public class CliApp { //NOPMD
039
040    public static void main(String[] args) {
041
042        ConfigurableApplicationContext context = SpringApplication.run(CliApp.class, args);
043
044        // Grab the 'QuickStart' bean, call 'run()' to start the example.
045        context.getBean(QuickStart.class).run();
046    }
047
048    /**
049     * Example hard coded Realm bean.
050     * @return hard coded Realm bean
051     */
052    @Bean
053    public Realm realm() {
054        TextConfigurationRealm realm = new TextConfigurationRealm();
055        realm.setUserDefinitions("joe.coder=password,user\n" +
056                                 "jill.coder=password,admin");
057
058        realm.setRoleDefinitions("admin=read,write\n" +
059                                 "user=read");
060        realm.setCachingEnabled(true);
061        return realm;
062    }
063
064}