diff --git a/shiro-example-chapter2/pom.xml b/shiro-example-chapter2/pom.xml index 52fca57b..11c377ac 100644 --- a/shiro-example-chapter2/pom.xml +++ b/shiro-example-chapter2/pom.xml @@ -1,46 +1,49 @@ - - - shiro-example - com.github.zhangkaitao - 1.0-SNAPSHOT - - 4.0.0 + + + shiro-example + com.github.zhangkaitao + 1.0-SNAPSHOT + + 4.0.0 - shiro-example-chapter2 - - - junit - junit - 4.9 - test - - - commons-logging - commons-logging - 1.1.3 - - - org.apache.shiro - shiro-core - 1.2.2 - + shiro-example-chapter2 + + + junit + junit + 4.9 + test + + + commons-logging + commons-logging + 1.1.3 + + + org.apache.shiro + shiro-core + 1.2.2 + - - mysql - mysql-connector-java - 5.1.25 - - - com.alibaba - druid - 0.2.23 - + + mysql + mysql-connector-java + 5.1.25 + + + com.alibaba + druid + 0.2.23 + + + org.slf4j + slf4j-log4j12 + 1.7.2 + - - + \ No newline at end of file diff --git a/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm1.java b/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm1.java index f90d5c79..7b17a9c2 100644 --- a/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm1.java +++ b/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm1.java @@ -12,28 +12,25 @@ */ public class MyRealm1 implements Realm { - @Override public String getName() { return "myrealm1"; } - @Override public boolean supports(AuthenticationToken token) { - return token instanceof UsernamePasswordToken; //仅支持UsernamePasswordToken类型的Token + return token instanceof UsernamePasswordToken; //浠呮敮鎸乁sernamePasswordToken绫诲瀷鐨凾oken } - @Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { - String username = (String)token.getPrincipal(); //得到用户名 - String password = new String((char[])token.getCredentials()); //得到密码 + String username = (String)token.getPrincipal(); //寰楀埌鐢ㄦ埛鍚� + String password = new String((char[])token.getCredentials()); //寰楀埌瀵嗙爜 if(!"zhang".equals(username)) { - throw new UnknownAccountException(); //如果用户名错误 + throw new UnknownAccountException(); //濡傛灉鐢ㄦ埛鍚嶉敊璇� } if(!"123".equals(password)) { - throw new IncorrectCredentialsException(); //如果密码错误 + throw new IncorrectCredentialsException(); //濡傛灉瀵嗙爜閿欒 } - //如果身份认证验证成功,返回一个AuthenticationInfo实现; + //濡傛灉韬唤璁よ瘉楠岃瘉鎴愬姛锛岃繑鍥炰竴涓狝uthenticationInfo瀹炵幇锛� return new SimpleAuthenticationInfo(username, password, getName()); } } diff --git a/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm2.java b/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm2.java index 3d2a75a5..f13342f1 100644 --- a/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm2.java +++ b/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm2.java @@ -10,17 +10,14 @@ */ public class MyRealm2 implements Realm { - @Override public String getName() { return "myrealm2"; } - @Override public boolean supports(AuthenticationToken token) { return token instanceof UsernamePasswordToken; //仅支持UsernamePasswordToken类型的Token } - @Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = (String)token.getPrincipal(); //得到用户名 diff --git a/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm3.java b/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm3.java index 8b7d0be8..ae2b167e 100644 --- a/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm3.java +++ b/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm3.java @@ -10,17 +10,14 @@ */ public class MyRealm3 implements Realm { - @Override public String getName() { return "myrealm3"; } - @Override public boolean supports(AuthenticationToken token) { return token instanceof UsernamePasswordToken; //仅支持UsernamePasswordToken类型的Token } - @Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = (String)token.getPrincipal(); //得到用户名 diff --git a/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm4.java b/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm4.java index 5a202765..df8bf16f 100644 --- a/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm4.java +++ b/shiro-example-chapter2/src/test/java/com/github/zhangkaitao/shiro/chapter2/realm/MyRealm4.java @@ -10,17 +10,14 @@ */ public class MyRealm4 implements Realm { - @Override public String getName() { return "myrealm4"; } - @Override public boolean supports(AuthenticationToken token) { return token instanceof UsernamePasswordToken; //仅支持UsernamePasswordToken类型的Token } - @Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = (String)token.getPrincipal(); //得到用户名 diff --git a/shiro-example-chapter2/src/test/resources/log4j.properties b/shiro-example-chapter2/src/test/resources/log4j.properties new file mode 100644 index 00000000..483a2d44 --- /dev/null +++ b/shiro-example-chapter2/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootLogger=DEBUG, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%c{1} - %m%n + +log4j.logger.java.sql.PreparedStatement=DEBUG \ No newline at end of file diff --git a/shiro-example-chapter3/pom.xml b/shiro-example-chapter3/pom.xml index 5deb15de..3f1b87d8 100644 --- a/shiro-example-chapter3/pom.xml +++ b/shiro-example-chapter3/pom.xml @@ -1,45 +1,48 @@ - - - shiro-example - com.github.zhangkaitao - 1.0-SNAPSHOT - - 4.0.0 + + + shiro-example + com.github.zhangkaitao + 1.0-SNAPSHOT + + 4.0.0 - shiro-example-chapter3 + shiro-example-chapter3 - - - junit - junit - 4.9 - test - - - commons-logging - commons-logging - 1.1.3 - - - org.apache.shiro - shiro-core - 1.2.2 - + + + junit + junit + 4.9 + test + + + commons-logging + commons-logging + 1.1.3 + + + org.apache.shiro + shiro-core + 1.2.2 + - - mysql - mysql-connector-java - 5.1.25 - - - com.alibaba - druid - 0.2.23 - - - + + mysql + mysql-connector-java + 5.1.25 + + + com.alibaba + druid + 0.2.23 + + + org.slf4j + slf4j-log4j12 + 1.7.2 + + \ No newline at end of file diff --git a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/PermissionTest.java b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/PermissionTest.java index 36a66268..843cf256 100644 --- a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/PermissionTest.java +++ b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/PermissionTest.java @@ -48,7 +48,7 @@ public void testWildcardPermission1() { @Test public void testWildcardPermission2() { login("classpath:shiro-permission.ini", "li", "123"); - subject().checkPermissions("system:user:create,delete,update:view"); + subject().checkPermissions("system:user:create,delete,update,view"); subject().checkPermissions("system:user:*"); subject().checkPermissions("system:user"); diff --git a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/RoleTest.java b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/RoleTest.java index 9202bbbf..e2d5a37e 100644 --- a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/RoleTest.java +++ b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/RoleTest.java @@ -27,7 +27,7 @@ public void testHasRole() { Assert.assertEquals(false, result[2]); } - @Test(expected = UnauthorizedException.class) + @Test public void testCheckRole() { login("classpath:shiro-role.ini", "zhang", "123"); //断言拥有角色:role1 diff --git a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/BitAndWildPermissionResolver.java b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/BitAndWildPermissionResolver.java index f8b65518..232e5d49 100644 --- a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/BitAndWildPermissionResolver.java +++ b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/BitAndWildPermissionResolver.java @@ -12,7 +12,6 @@ */ public class BitAndWildPermissionResolver implements PermissionResolver { - @Override public Permission resolvePermission(String permissionString) { if(permissionString.startsWith("+")) { return new BitPermission(permissionString); diff --git a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/BitPermission.java b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/BitPermission.java index e066eadb..a0c75cb9 100644 --- a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/BitPermission.java +++ b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/BitPermission.java @@ -56,7 +56,6 @@ public BitPermission(String permissionString) { } - @Override public boolean implies(Permission p) { if(!(p instanceof BitPermission)) { return false; diff --git a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/MyRolePermissionResolver.java b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/MyRolePermissionResolver.java index 083680a2..fb6912ed 100644 --- a/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/MyRolePermissionResolver.java +++ b/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/permission/MyRolePermissionResolver.java @@ -13,7 +13,6 @@ *

Version: 1.0 */ public class MyRolePermissionResolver implements RolePermissionResolver { - @Override public Collection resolvePermissionsInRole(String roleString) { if("role1".equals(roleString)) { return Arrays.asList((Permission)new WildcardPermission("menu:*")); diff --git a/shiro-example-chapter3/src/test/resources/log4j.properties b/shiro-example-chapter3/src/test/resources/log4j.properties new file mode 100644 index 00000000..5f00ad19 --- /dev/null +++ b/shiro-example-chapter3/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootLogger=ALL, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%c{1} - %m%n + +log4j.logger.java.sql.PreparedStatement=DEBUG \ No newline at end of file