Subversion Repositories XServices

Rev

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

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