1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <?xml version="1.0" encoding="UTF-8"?> <ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"> <info organisation="com.nathanagood.examples" module="shirotest" /> <configurations> <conf name="dist" description="Dependency configuration for distribution." /> </configurations> <dependencies> <dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="dist->default" /> <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.5.8" conf="dist->default" /> <dependency org="org.apache.shiro" name="shiro-core" rev="1.0.0-incubating" conf="dist->default" /> <dependency org="org.apache.shiro" name="shiro-web" rev="1.0.0-incubating" conf="dist->default" /> </dependencies> </ivy-module> <project name="shiroTestApp" default="usage" basedir="." xmlns:ivy="antlibrg.apache.ivy.ant"> <property name="project.lib" value="lib" /> <path id="ivy.task.path"> <fileset dir="${basedir}/ivy-lib"> <include name="**/*.jar" /> </fileset> </path> <target name="resolve"> <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlibrg.apache.ivy.ant" classpathref="ivy.task.path" /> <ivy:resolve /> <ivy:retrieve pattern="${project.lib}/[conf]/[artifact].[ext]" sync="true" /> </target> <target name="usage"> <echo message="Use --projecthelp to learn more about this project" /> </target> </project> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | package com.nathanagood.examples.shirotest; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.config.IniSecurityManagerFactory; import org.apache.shiro.subject.Subject; import org.apache.shiro.util.Factory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ShiroTest { private static Logger logger = LoggerFactory.getLogger(ShiroTest.class); public static void main(String[] args) { // Using the IniSecurityManagerFactory, which will use the an INI file // as the security file. Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory("auth.ini"); // Setting up the SecurityManager... org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); Subject user = SecurityUtils.getSubject(); logger.info("User is authenticated: " + user.isAuthenticated()); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |