Subversion Repositories XServices

Rev

Rev 177 | Rev 198 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 Rev 185
1
/*
1
/*
2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
*/
15
*/
16
 
16
 
17
package net.brutex.xservices.security;
17
package net.brutex.xservices.security;
-
 
18
 
-
 
19
 
18
 
20
import org.apache.logging.log4j.LogManager;
19
import org.apache.log4j.Logger;
21
import org.apache.logging.log4j.Logger;
20
import org.apache.shiro.authz.Permission;
22
import org.apache.shiro.authz.Permission;
21
import org.apache.shiro.util.AntPathMatcher;
23
import org.apache.shiro.util.AntPathMatcher;
22
 
24
 
23
/**
25
/**
24
 * @author Brian Rosenberger, bru(at)brutex.de
26
 * @author Brian Rosenberger, bru(at)brutex.de
25
 *
27
 *
26
 */
28
 */
27
public class DirectoryPermission implements Permission {
29
public class DirectoryPermission implements Permission {
28
 
30
 
-
 
31
	private final Logger logger = LogManager.getLogger();
29
	private final Logger logger = Logger.getLogger(DirectoryPermission.class);
32
 
30
	private final String path;
33
	private final String path;
31
 
34
 
32
	public DirectoryPermission(String antlikepath) {
35
	public DirectoryPermission(String antlikepath) {
33
		logger.debug(String.format("Creating permission for path '%s'", antlikepath));
36
		logger.debug(String.format("Creating permission for path '%s'", antlikepath));
34
		path = antlikepath;
37
		path = antlikepath;
35
	}
38
	}
36
	
39
	
37
	@Override
40
	@Override
38
	public boolean implies(Permission p) {
41
	public boolean implies(Permission p) {
39
		boolean result = false;
42
		boolean result = false;
40
		
43
		
41
		/* is of same type */
44
		/* is of same type */
42
		if(! (p instanceof DirectoryPermission)) {			
45
		if(! (p instanceof DirectoryPermission)) {			
43
			logger.debug(String.format("Testing if permission of type '%s' implies permission of type '%s'. Result was '%s'"  , this.getClass(), p.getClass(), result));
46
			logger.debug(String.format("Testing if permission of type '%s' implies permission of type '%s'. Result was '%s'"  , this.getClass(), p.getClass(), result));
44
			return result;
47
			return result;
45
		}
48
		}
46
		
49
		
47
		/* comparing to non null directory */
50
		/* comparing to non null directory */
48
		if( ((DirectoryPermission)p).getPath() == null) {
51
		if( ((DirectoryPermission)p).getPath() == null) {
49
			logger.debug(String.format("Testing if DirectoryPermission '%s' implies permission to 'null'. Result was '%s'"  , this.getPath(), result));
52
			logger.debug(String.format("Testing if DirectoryPermission '%s' implies permission to 'null'. Result was '%s'"  , this.getPath(), result));
50
			return result;
53
			return result;
51
		}
54
		}
52
		
55
		
53
		/* directory pattern implies other */
56
		/* directory pattern implies other */
54
		if( (new AntPathMatcher()).matches(path, ((DirectoryPermission)p).getPath()) ) {
57
		if( (new AntPathMatcher()).matches(path, ((DirectoryPermission)p).getPath()) ) {
55
			result = true;
58
			result = true;
56
		}
59
		}
57
		logger.debug(String.format("Testing if DirectoryPermission '%s' implies permission to '%s'. Result was '%s'"  , this.getPath(), ((DirectoryPermission) p).getPath(), result));
60
		logger.debug(String.format("Testing if DirectoryPermission '%s' implies permission to '%s'. Result was '%s'"  , this.getPath(), ((DirectoryPermission) p).getPath(), result));
58
		
61
		
59
		return result;
62
		return result;
60
	}
63
	}
61
	
64
	
62
	public String getPath() {
65
	public String getPath() {
63
		return path;
66
		return path;
64
	}
67
	}
65
 
68
 
66
}
69
}