// Path: src/test/java/at/pollux/thymeleaf/shiro/test/ShiroTest.java
// public abstract class ShiroTest {
// 
//     private static ThreadState subjectThreadState;
// 
//     public ShiroTest() {
//     }
// 
//     /**
//      * Allows subclasses to set the currently executing {@link Subject} instance.
//      *
//      * @param subject the Subject instance
//      */
//     protected void setSubject(Subject subject) {
//         clearSubject();
//         subjectThreadState = createThreadState(subject);
//         subjectThreadState.bind();
//     }
// 
//     protected Subject getSubject() {
//         return SecurityUtils.getSubject();
//     }
// 
//     protected ThreadState createThreadState(Subject subject) {
//         return new SubjectThreadState(subject);
//     }
// 
//     /**
//      * Clears Shiro's thread state, ensuring the thread remains clean for future test execution.
//      */
//     protected void clearSubject() {
//         doClearSubject();
//     }
// 
//     private static void doClearSubject() {
//         if (subjectThreadState != null) {
//             subjectThreadState.clear();
//             subjectThreadState = null;
//         }
//     }
// 
//     protected static void setSecurityManager(SecurityManager securityManager) {
//         SecurityUtils.setSecurityManager(securityManager);
//     }
// 
//     protected static SecurityManager getSecurityManager() {
//         return SecurityUtils.getSecurityManager();
//     }
// 
//     @AfterClass
//     public static void tearDownShiro() {
//         doClearSubject();
//         try {
//             SecurityManager securityManager = getSecurityManager();
//             LifecycleUtils.destroy(securityManager);
//         } catch (UnavailableSecurityManagerException e) {
//             //we don't care about this when cleaning up the test environment
//             //(for example, maybe the subclass is a unit test and it didn't
//             // need a SecurityManager instance because it was using only mock Subject instances)
//         }
//         setSecurityManager(null);
//     }
// }
// 
// Path: src/test/java/at/pollux/thymeleaf/shiro/test/TestIniSecurityManagerFactory.java
// public class TestIniSecurityManagerFactory extends IniSecurityManagerFactory {
// 
//     public TestIniSecurityManagerFactory(Ini config) {
//         super(config);
//     }
// 
//     @Override
//     protected Realm createRealm(Ini ini) {
//         //IniRealm realm = new IniRealm(ini); changed to support SHIRO-322
//         IniRealm realm = new TestIniRealm();
//         realm.setName(INI_REALM_NAME);
//         realm.setIni(ini); //added for SHIRO-322
//         return realm;
//     }
// }


import static org.junit.Assert.*;
import at.pollux.thymeleaf.shiro.test.ShiroTest;
import at.pollux.thymeleaf.shiro.test.TestIniSecurityManagerFactory;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.Ini;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
/*
 * Copyright 2013 Art Gramlich.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package at.pollux.thymeleaf.shiro.dialect;



/**
 * @author artgramlich
 */
public class ShiroDialectTest extends ShiroTest {

    private static final String PACKAGE_PATH = "at/pollux/thymeleaf/shiro/dialect/test";
    private static final String TEST_TEMPLATE_PATH = PACKAGE_PATH + "/test.html";
    private static final String USER1 = "u1";
    private static final String PASS1 = "p1";
    private static final String USER2 = "u2";
    private static final String PASS2 = "p2";
    private static final String USER3 = "u3";
    private static final String PASS3 = "p3";

    private static TemplateEngine templateEngine;

    private static void setupShiro() {
        Ini ini = new Ini();
        Ini.Section usersSection = ini.addSection("users");
        usersSection.put(USER1, PASS1 + ",rolea,roled");
        usersSection.put(USER2, PASS2 + ",roleb,rolec");
        usersSection.put(USER3, PASS3 + ",rolec,rolee");
        Ini.Section rolesSection = ini.addSection("roles");
        rolesSection.put("rolea", "*");
        rolesSection.put("roleb", "permtype1:permaction1:perminst1");
        rolesSection.put("rolec", "permtype1:permaction2:*");
        rolesSection.put("roled", "permtype3:*");
// Path: src/test/java/at/pollux/thymeleaf/shiro/test/ShiroTest.java
// public abstract class ShiroTest {
// 
//     private static ThreadState subjectThreadState;
// 
//     public ShiroTest() {
//     }
// 
//     /**
//      * Allows subclasses to set the currently executing {@link Subject} instance.
//      *
//      * @param subject the Subject instance
//      */
//     protected void setSubject(Subject subject) {
//         clearSubject();
//         subjectThreadState = createThreadState(subject);
//         subjectThreadState.bind();
//     }
// 
//     protected Subject getSubject() {
//         return SecurityUtils.getSubject();
//     }
// 
//     protected ThreadState createThreadState(Subject subject) {
//         return new SubjectThreadState(subject);
//     }
// 
//     /**
//      * Clears Shiro's thread state, ensuring the thread remains clean for future test execution.
//      */
//     protected void clearSubject() {
//         doClearSubject();
//     }
// 
//     private static void doClearSubject() {
//         if (subjectThreadState != null) {
//             subjectThreadState.clear();
//             subjectThreadState = null;
//         }
//     }
// 
//     protected static void setSecurityManager(SecurityManager securityManager) {
//         SecurityUtils.setSecurityManager(securityManager);
//     }
// 
//     protected static SecurityManager getSecurityManager() {
//         return SecurityUtils.getSecurityManager();
//     }
// 
//     @AfterClass
//     public static void tearDownShiro() {
//         doClearSubject();
//         try {
//             SecurityManager securityManager = getSecurityManager();
//             LifecycleUtils.destroy(securityManager);
//         } catch (UnavailableSecurityManagerException e) {
//             //we don't care about this when cleaning up the test environment
//             //(for example, maybe the subclass is a unit test and it didn't
//             // need a SecurityManager instance because it was using only mock Subject instances)
//         }
//         setSecurityManager(null);
//     }
// }
// 
// Path: src/test/java/at/pollux/thymeleaf/shiro/test/TestIniSecurityManagerFactory.java
// public class TestIniSecurityManagerFactory extends IniSecurityManagerFactory {
// 
//     public TestIniSecurityManagerFactory(Ini config) {
//         super(config);
//     }
// 
//     @Override
//     protected Realm createRealm(Ini ini) {
//         //IniRealm realm = new IniRealm(ini); changed to support SHIRO-322
//         IniRealm realm = new TestIniRealm();
//         realm.setName(INI_REALM_NAME);
//         realm.setIni(ini); //added for SHIRO-322
//         return realm;
//     }
// }


// Path: src/test/java/at/pollux/thymeleaf/shiro/dialect/ShiroDialectTest.java
import static org.junit.Assert.*;
import at.pollux.thymeleaf.shiro.test.ShiroTest;
import at.pollux.thymeleaf.shiro.test.TestIniSecurityManagerFactory;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.Ini;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;

/*
 * Copyright 2013 Art Gramlich.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package at.pollux.thymeleaf.shiro.dialect;



/**
 * @author artgramlich
 */
public class ShiroDialectTest extends ShiroTest {

    private static final String PACKAGE_PATH = "at/pollux/thymeleaf/shiro/dialect/test";
    private static final String TEST_TEMPLATE_PATH = PACKAGE_PATH + "/test.html";
    private static final String USER1 = "u1";
    private static final String PASS1 = "p1";
    private static final String USER2 = "u2";
    private static final String PASS2 = "p2";
    private static final String USER3 = "u3";
    private static final String PASS3 = "p3";

    private static TemplateEngine templateEngine;

    private static void setupShiro() {
        Ini ini = new Ini();
        Ini.Section usersSection = ini.addSection("users");
        usersSection.put(USER1, PASS1 + ",rolea,roled");
        usersSection.put(USER2, PASS2 + ",roleb,rolec");
        usersSection.put(USER3, PASS3 + ",rolec,rolee");
        Ini.Section rolesSection = ini.addSection("roles");
        rolesSection.put("rolea", "*");
        rolesSection.put("roleb", "permtype1:permaction1:perminst1");
        rolesSection.put("rolec", "permtype1:permaction2:*");
        rolesSection.put("roled", "permtype3:*");
        Factory<SecurityManager> factory = new TestIniSecurityManagerFactory(ini);