Subversion Repositories XServices

Rev

Details | 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
 
18
package net.brutex.xservices.security;
19
 
185 brianR 20
import org.apache.logging.log4j.Logger;
146 brianR 21
 
185 brianR 22
import java.net.URI;
23
import java.net.URISyntaxException;
24
import java.net.URL;
25
 
26
import javax.servlet.ServletContext;
27
 
28
import org.apache.catalina.core.ApplicationContext;
29
import org.apache.logging.log4j.LogManager;
146 brianR 30
import org.apache.shiro.authc.AuthenticationException;
31
import org.apache.shiro.authc.AuthenticationInfo;
32
import org.apache.shiro.authc.AuthenticationToken;
33
import org.apache.shiro.authz.AuthorizationInfo;
185 brianR 34
import org.apache.shiro.authz.SimpleAuthorizationInfo;
146 brianR 35
import org.apache.shiro.config.Ini;
36
import org.apache.shiro.io.ResourceUtils;
37
import org.apache.shiro.realm.AuthorizingRealm;
38
import org.apache.shiro.realm.text.IniRealm;
185 brianR 39
import org.apache.shiro.realm.text.TextConfigurationRealm;
146 brianR 40
import org.apache.shiro.subject.PrincipalCollection;
41
import org.apache.shiro.util.Nameable;
185 brianR 42
import org.apache.shiro.web.env.IniWebEnvironment;
43
import org.apache.shiro.web.util.WebUtils;
146 brianR 44
 
45
// TODO: Auto-generated Javadoc
46
/*
47
 * For later use. A Realm connects to a DS where Users/ Passes are defined
48
 * and allows Shiro to transparently work against different user/pass stores
49
 * (i.e. LDAP, Custom, etc.)
50
 *
51
 * @author Brian Rosenberger, bru(at)brutex.de
52
 *
53
 */
54
/**
55
 * The Class XServicesRealm.
56
 */
57
public class XServicesRealm extends IniRealm implements Nameable  {
58
 
59
	/** The logger. */
185 brianR 60
	private final Logger logger = LogManager.getLogger();
146 brianR 61
 
62
	/** The name. */
63
	private String name;
64
 
65
	/* (non-Javadoc)
66
	 * @see org.apache.shiro.realm.AuthorizingRealm#setName(java.lang.String)
67
	 */
68
	@Override
69
	public void setName(String name) {
70
		this.name = name;
71
	}
72
 
73
 
74
	/**
75
	 * Instantiates a new x services realm with default
76
	 * 'shiro.ini' in classpath and {@link net.brutex.xservices.security.PermissionResolver PermissionResolver}.
77
	 *
78
	 */
185 brianR 79
 
146 brianR 80
	public XServicesRealm() {
81
		super();
185 brianR 82
		/* needs review */
83
		URI classesRootDir;
84
		try {
85
			classesRootDir = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
86
			String dir = classesRootDir.toString().replaceAll("%20", " ");
87
			dir = dir.substring(0,  dir.lastIndexOf("WEB-INF"));
88
		this.setIni(Ini.fromResourcePath(dir+"/WEB-INF/shiro.ini"));
89
		} catch (URISyntaxException e) {
90
			logger.error(e.getMessage(), e);
91
			e.printStackTrace();
92
		}
93
 
94
 
146 brianR 95
		this.setPermissionResolver(new net.brutex.xservices.security.PermissionResolver());
185 brianR 96
	}
97
 
98
 
99
 
146 brianR 100
}