Subversion Repositories XServices

Rev

Rev 198 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 198 Rev 199
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
 
18
 
19
import org.apache.logging.log4j.Logger;
-
 
20
import org.apache.logging.log4j.LogManager;
19
import lombok.extern.slf4j.Slf4j;
21
import org.apache.shiro.authz.Permission;
20
import org.apache.shiro.authz.Permission;
22
 
21
 
23
/**
22
/**
24
 * @author Brian Rosenberger, bru(at)brutex.de
23
 * @author Brian Rosenberger, bru(at)brutex.de
25
 *
24
 *
26
 */
25
 */
-
 
26
@Slf4j
27
public class XmlServicePermission implements Permission {
27
public class XmlServicePermission implements Permission {
28
 
-
 
29
	private final Logger logger = LogManager.getLogger();
28
 
30
	private final String permissionString;
29
	private final String permissionString;
31
 
30
 
32
	public XmlServicePermission(String permissionString) {
31
	public XmlServicePermission(String permissionString) {
33
		logger.debug(String.format("Creating permission for '%s'", permissionString));
32
		log.debug(String.format("Creating permission for '{}'", permissionString));
34
		this.permissionString = permissionString;
33
		this.permissionString = permissionString;
35
	}
34
	}
36
	
35
	
37
	@Override
36
	@Override
38
	public boolean implies(Permission p) {
37
	public boolean implies(Permission p) {
39
		boolean result = false;
38
		boolean result = false;
40
		
39
		
41
		/* is of same type */
40
		/* is of same type */
42
		if(! (p instanceof XmlServicePermission)) {			
41
		if(! (p instanceof XmlServicePermission)) {			
43
			logger.debug(String.format("Testing if permission of type '%s' implies permission of type '%s'. Result was '%s'"  , this.getClass(), p.getClass(), result));
42
			log.debug(String.format("Testing if permission of type '{}' implies permission of type '{}'. Result was '{}'"  , this.getClass(), p.getClass(), result));
44
			return result;
43
			return result;
45
		}
44
		}
46
		
45
		
47
		/* comparing to non null directory */
46
		/* comparing to non null directory */
48
		if( ((XmlServicePermission)p).getPermissionString() == null) {
47
		if( ((XmlServicePermission)p).getPermissionString() == null) {
49
			logger.debug(String.format("Testing if DirectoryPermission '%s' implies permission to 'null'. Result was '%s'"  , permissionString, result));
48
			log.debug(String.format("Testing if DirectoryPermission '{}' implies permission to 'null'. Result was '{}'"  , permissionString, result));
50
			return result;
49
			return result;
51
		}
50
		}
52
		
51
		
53
		/* directory pattern implies other */
52
		/* directory pattern implies other */
54
		//TODO
53
		//TODO
55
		/*if( (new AntPathMatcher()).matches(permissionString, ((XmlServicePermission)p).getPermissionString())) ) {
54
		/*if( (new AntPathMatcher()).matches(permissionString, ((XmlServicePermission)p).getPermissionString())) ) {
56
			result = true;
55
			result = true;
57
		}
56
		}
58
		logger.debug(String.format("Testing if DirectoryPermission '%s' implies permission to '%s'. Result was '%s'"  , permissionString, ((XmlServicePermission) p).getPermissionString(), result));
57
		logger.debug(String.format("Testing if DirectoryPermission '%s' implies permission to '%s'. Result was '%s'"  , permissionString, ((XmlServicePermission) p).getPermissionString(), result));
59
		*/
58
		*/
60
		return result;
59
		return result;
61
	}
60
	}
62
	
61
	
63
	public String getPermissionString() {
62
	public String getPermissionString() {
64
		return permissionString;
63
		return permissionString;
65
	}
64
	}
66
 
65
 
67
}
66
}