Subversion Repositories XServices

Rev

Rev 198 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
146 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 net.brutex.xservices.ws.XmlService;
21
import net.brutex.xservices.ws.rs.FileInfo;
22
 
199 brianR 23
 
146 brianR 24
import org.apache.shiro.authz.Permission;
177 brianR 25
import org.apache.shiro.authz.permission.InvalidPermissionStringException;
146 brianR 26
 
27
/**
28
 * @author Brian Rosenberger, bru(at)brutex.de
29
 *
30
 */
199 brianR 31
@Slf4j
146 brianR 32
public class PermissionResolver implements org.apache.shiro.authz.permission.PermissionResolver {
199 brianR 33
 
177 brianR 34
	private final String DELIMITER = "||";
146 brianR 35
 
36
	@Override
37
	public Permission resolvePermission(String permissionString) {
199 brianR 38
		log.debug(String.format("Trying to examine new Permission '{}'", permissionString));
177 brianR 39
		if(! permissionString.contains(DELIMITER)) {
199 brianR 40
			log.error(String.format("Permission '{}' is missing permission class.", permissionString));
41
			throw new InvalidPermissionStringException(String.format("Permission '{}' is missing permission class.", permissionString), permissionString);
177 brianR 42
		}
43
		int delimiterIndex = permissionString.indexOf(DELIMITER);
44
		String value = permissionString.substring(0, delimiterIndex);
45
		delimiterIndex = delimiterIndex + DELIMITER.length();
46
		switch (value) {
47
		case XmlService.SERVICE_NAME:
199 brianR 48
			log.debug(String.format("Found '{}' as permission class.", value));
177 brianR 49
			return new XmlServicePermission(permissionString.substring( delimiterIndex ));
50
 
51
		case FileInfo.SERVICE_NAME:
199 brianR 52
			log.debug(String.format("Found '{}' as permission class.", value));
177 brianR 53
			return new DirectoryPermission(permissionString.substring( delimiterIndex ));
54
 
55
 
56
		default:
199 brianR 57
			log.warn(String.format("Permission class '{}' is not defined.", value));
177 brianR 58
			throw new InvalidPermissionStringException(String.format("Permission class '%s' is not defined.", value), permissionString);
59
		}
146 brianR 60
	}
61
}