Subversion Repositories XServices

Rev

Rev 197 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/*
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
*/


package net.brutex.xservices.security;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.config.Ini;
import org.apache.shiro.realm.text.IniRealm;
import org.apache.shiro.util.Nameable;

import java.net.URI;
import java.net.URISyntaxException;

// TODO: Auto-generated Javadoc
/* 
 * For later use. A Realm connects to a DS where Users/ Passes are defined
 * and allows Shiro to transparently work against different user/pass stores
 * (i.e. LDAP, Custom, etc.)
 *
 * @author Brian Rosenberger, bru(at)brutex.de
 *
 */
/**
 * The Class XServicesRealm.
 */
public class XServicesRealm extends IniRealm implements Nameable  {

        /** The logger. */
        private final Logger logger = LogManager.getLogger();
        
        /** The name. */
        private String name;
        
        /* (non-Javadoc)
         * @see org.apache.shiro.realm.AuthorizingRealm#setName(java.lang.String)
         */
        @Override
        public void setName(String name) {
                this.name = name;
        }

        
        /**
         * Instantiates a new x services realm with default
         * 'shiro.ini' in classpath and {@link net.brutex.xservices.security.PermissionResolver PermissionResolver}.
         * 
         */
        
        public XServicesRealm() {
                super();
                /* needs review */
                URI classesRootDir;
                try {
                        classesRootDir = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
                        String dir = classesRootDir.toString().replaceAll("%20", " ");
                        dir = dir.substring(0,  dir.lastIndexOf("WEB-INF"));
                this.setIni(Ini.fromResourcePath(dir+"/WEB-INF/shiro.ini"));
                } catch (URISyntaxException e) {
                        logger.error(e.getMessage(), e);
                        e.printStackTrace();
                }
                
                
                this.setPermissionResolver(new net.brutex.xservices.security.PermissionResolver());
        }


        
}