Subversion Repositories XServices

Rev

Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/*
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
 *
 *   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 net.brutex.xservices.security;

import org.apache.log4j.Logger;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.util.AntPathMatcher;

/**
 * @author Brian Rosenberger, bru(at)brutex.de
 *
 */
public class XmlServicePermission implements Permission {

        private final Logger logger = Logger.getLogger(XmlServicePermission.class);
        private final String permissionString;

        public XmlServicePermission(String permissionString) {
                logger.debug(String.format("Creating permission for '%s'", permissionString));
                this.permissionString = permissionString;
        }
        
        @Override
        public boolean implies(Permission p) {
                boolean result = false;
                
                /* is of same type */
                if(! (p instanceof XmlServicePermission)) {                     
                        logger.debug(String.format("Testing if permission of type '%s' implies permission of type '%s'. Result was '%s'"  , this.getClass(), p.getClass(), result));
                        return result;
                }
                
                /* comparing to non null directory */
                if( ((XmlServicePermission)p).getPermissionString() == null) {
                        logger.debug(String.format("Testing if DirectoryPermission '%s' implies permission to 'null'. Result was '%s'"  , permissionString, result));
                        return result;
                }
                
                /* directory pattern implies other */
                //TODO
                /*if( (new AntPathMatcher()).matches(permissionString, ((XmlServicePermission)p).getPermissionString())) ) {
                        result = true;
                }
                logger.debug(String.format("Testing if DirectoryPermission '%s' implies permission to '%s'. Result was '%s'"  , permissionString, ((XmlServicePermission) p).getPermissionString(), result));
                */
                return result;
        }
        
        public String getPermissionString() {
                return permissionString;
        }

}