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