Rev 198 | 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 lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.util.AntPathMatcher;
/**
* @author Brian Rosenberger, bru(at)brutex.de
*
*/
@Slf4j
public class DirectoryPermission implements Permission {
private final String path;
public DirectoryPermission(String antlikepath) {
log.debug(String.format("Creating permission for path '{}'", antlikepath));
path = antlikepath;
}
@Override
public boolean implies(Permission p) {
boolean result = false;
/* is of same type */
if(! (p instanceof DirectoryPermission)) {
log.debug(String.format("Testing if permission of type '{}' implies permission of type '{}'. Result was '{}'" , this.getClass(), p.getClass(), result));
return result;
}
/* comparing to non null directory */
if( ((DirectoryPermission)p).getPath() == null) {
log.debug(String.format("Testing if DirectoryPermission '{}' implies permission to 'null'. Result was '{}'" , this.getPath(), result));
return result;
}
/* directory pattern implies other */
if( (new AntPathMatcher()).matches(path, ((DirectoryPermission)p).getPath()) ) {
result = true;
}
log.debug(String.format("Testing if DirectoryPermission '{}' implies permission to '{}'. Result was '{}'" , this.getPath(), ((DirectoryPermission) p).getPath(), result));
return result;
}
public String getPath() {
return path;
}
}