Subversion Repositories XServices

Rev

Rev 198 | Go to most recent revision | Only display areas with differences | Ignore 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
 
17
 
18
package net.brutex.xservices.security;
18
package net.brutex.xservices.security;
19
 
-
 
-
 
19
 
20
import org.apache.logging.log4j.LogManager;
20
 
21
import org.apache.logging.log4j.Logger;
21
import lombok.extern.slf4j.Slf4j;
22
import org.apache.shiro.config.Ini;
22
import org.apache.shiro.config.Ini;
23
import org.apache.shiro.realm.text.IniRealm;
23
import org.apache.shiro.realm.text.IniRealm;
24
import org.apache.shiro.util.Nameable;
24
import org.apache.shiro.util.Nameable;
25
 
25
 
26
import java.net.URI;
26
import java.net.URI;
27
import java.net.URISyntaxException;
27
import java.net.URISyntaxException;
28
 
28
 
29
// TODO: Auto-generated Javadoc
29
// TODO: Auto-generated Javadoc
30
/* 
30
/* 
31
 * For later use. A Realm connects to a DS where Users/ Passes are defined
31
 * For later use. A Realm connects to a DS where Users/ Passes are defined
32
 * and allows Shiro to transparently work against different user/pass stores
32
 * and allows Shiro to transparently work against different user/pass stores
33
 * (i.e. LDAP, Custom, etc.)
33
 * (i.e. LDAP, Custom, etc.)
34
 *
34
 *
35
 * @author Brian Rosenberger, bru(at)brutex.de
35
 * @author Brian Rosenberger, bru(at)brutex.de
36
 *
36
 *
37
 */
37
 */
38
/**
38
/**
39
 * The Class XServicesRealm.
39
 * The Class XServicesRealm.
40
 */
40
 */
-
 
41
@Slf4j
41
public class XServicesRealm extends IniRealm implements Nameable  {
42
public class XServicesRealm extends IniRealm implements Nameable  {
42
 
-
 
43
	/** The logger. */
-
 
44
	private final Logger logger = LogManager.getLogger();
43
 
45
	
44
	
46
	/** The name. */
45
	/** The name. */
47
	private String name;
46
	private String name;
48
	
47
	
49
	/* (non-Javadoc)
48
	/* (non-Javadoc)
50
	 * @see org.apache.shiro.realm.AuthorizingRealm#setName(java.lang.String)
49
	 * @see org.apache.shiro.realm.AuthorizingRealm#setName(java.lang.String)
51
	 */
50
	 */
52
	@Override
51
	@Override
53
	public void setName(String name) {
52
	public void setName(String name) {
54
		this.name = name;
53
		this.name = name;
55
	}
54
	}
56
 
55
 
57
	
56
	
58
	/**
57
	/**
59
	 * Instantiates a new x services realm with default
58
	 * Instantiates a new x services realm with default
60
	 * 'shiro.ini' in classpath and {@link net.brutex.xservices.security.PermissionResolver PermissionResolver}.
59
	 * 'shiro.ini' in classpath and {@link net.brutex.xservices.security.PermissionResolver PermissionResolver}.
61
	 * 
60
	 * 
62
	 */
61
	 */
63
	
62
	
64
	public XServicesRealm() {
63
	public XServicesRealm() {
65
		super();
64
		super();
66
		/* needs review */
65
		/* needs review */
67
		URI classesRootDir;
66
		URI classesRootDir;
68
		try {
67
		try {
69
			classesRootDir = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
68
			classesRootDir = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
70
			String dir = classesRootDir.toString().replaceAll("%20", " ");
69
			String dir = classesRootDir.toString().replaceAll("%20", " ");
71
			dir = dir.substring(0,  dir.lastIndexOf("WEB-INF"));
70
			dir = dir.substring(0,  dir.lastIndexOf("WEB-INF"));
72
		this.setIni(Ini.fromResourcePath(dir+"/WEB-INF/shiro.ini"));
71
		this.setIni(Ini.fromResourcePath(dir+"/WEB-INF/shiro.ini"));
73
		} catch (URISyntaxException e) {
72
		} catch (URISyntaxException e) {
74
			logger.error(e.getMessage(), e);
73
			log.error(e.getMessage(), e);
75
			e.printStackTrace();
74
			e.printStackTrace();
76
		}
75
		}
77
		
76
		
78
		
77
		
79
		this.setPermissionResolver(new net.brutex.xservices.security.PermissionResolver());
78
		this.setPermissionResolver(new net.brutex.xservices.security.PermissionResolver());
80
	}
79
	}
81
 
80
 
82
 
81
 
83
	
82
	
84
}
83
}