public abstract class ShiroAuthorizingRealm extends AuthorizingRealm{ private static final String OR_OPERATOR = " or "; private static final String AND_OPERATOR = " and "; private static final String NOT_OPERATOR = "not "; @Override public Boolean isPermitted (PrincipalCollection Principals, String permission) { / * understand the problem: the passed string format: Or format: Permission 1 or 2 Permissions And format: Permission 1 and 2 rights Non-format: not Priv1 */ // the steps of: determining by the operator achieve three IF (permission.contains (OR_OPERATOR)) { // If any permission, returns true, otherwise to false String [] = Permissions permission.split (OR_OPERATOR); for ( P String: permissions) { // long as there is a permissions are authenticated it returns to true IF ( the this .isPermittedWithNotOperator (Principals, P)) { return to true ; } } return false; } The else IF (permission.equals (AND_OPERATOR)) { // must have two privilege, otherwise return true to false. String [] = Permissions permission.split (AND_OPERATOR); for (String P: Permissions) { // long there is a permission is false, we return false IF ( the this .isPermittedWithNotOperator (the Principals are, the p-) == false ) { return false ; } } return true; } The else { // if the key is not performed in the normal manner return the this .isPermittedWithNotOperator (Principals, permission); } } Private boolean isPermittedWithNotOperator (PrincipalCollection the Principals are, String permission) { // determine if there privilege string prefix "not" keyword. IF (permission.startsWith (NOT_OPERATOR)) { // If so, return to the opposite configuration return ! Super .isPermitted (Principals, permission.substring (NOT_OPERATOR.length ())); } else { return super.isPermitted(principals, permission); } } }
<shiro:hasPermission name="modular:to_edit or modular:delete">
</shiro:hasPermission>
<shiro:hasPermission name="modular:to_edit or modular:delete">
</shiro:hasPermission>
<shiro:hasPermission name="modular:to_edit or modular:delete">
</shiro:hasPermission>