// Path: src/main/java/com/plexobject/rbac/ServiceFactory.java
// public class ServiceFactory {
//     private static RepositoryFactory REPOSITORY_FACTORY = new RepositoryFactoryImpl();
//     private static PermissionManager PERMISSION_MANAGER = new PermissionManagerImpl(
//             REPOSITORY_FACTORY, new JavascriptEvaluator());
// 
//     public static RepositoryFactory getDefaultFactory() {
//         return REPOSITORY_FACTORY;
//     }
// 
//     public static PermissionManager getPermissionManager() {
//         return PERMISSION_MANAGER;
//     }
// }
// 
// Path: src/main/java/com/plexobject/rbac/repository/RepositoryFactory.java
// public interface RepositoryFactory {
//     /**
//      * 
//      * @return instance of security repository
//      */
//     SecurityMappingRepository getSecurityMappingRepository(String domain);
// 
//     /**
//      * 
//      * @return instance of domain repository to manage domains
//      */
//     DomainRepository getDomainRepository();
// 
//     /**
//      * 
//      * @return high level domain for this application
//      */
//     Subject getSuperAdmin();
// 
//     /**
//      * 
//      * @return high level domain for this application
//      */
//     Domain getDefaultDomain();
// 
//     /**
//      * 
//      * @param domain
//      * @return repository of roles for specific domain
//      */
//     RoleRepository getRoleRepository(String domain);
// 
//     /**
//      * 
//      * @param domain
//      * @return repository of permissions for given domain
//      */
//     PermissionRepository getPermissionRepository(String domain);
// 
//     /**
//      * 
//      * @param domain
//      * @return repository of security errors for given domain
//      */
//     SecurityErrorRepository getSecurityErrorRepository(String domain);
// 
//     /**
//      * 
//      * @param domain
//      * @return repository of subjects for given domain
//      */
//     SubjectRepository getSubjectRepository(String domain);
// 
//     /**
//      * 
//      * @return
//      */
//     SubjectRepository getDefaultSubjectRepository();
// }
// 
// Path: src/main/java/com/plexobject/rbac/utils/CurrentRequest.java
// public class CurrentRequest {
//     private static final ThreadLocal<String> domain = new ThreadLocal<String>();
//     private static final ThreadLocal<String> subjectName = new ThreadLocal<String>();
//     private static final ThreadLocal<String> ipAddress = new ThreadLocal<String>();
// 
//     public static void startRequest(final String domain, final String subjectName,
//             final String ipAddress) {
//         CurrentRequest.domain.set(domain);
//         CurrentRequest.subjectName.set(subjectName);
//         CurrentRequest.ipAddress.set(ipAddress);
//     }
// 
//     public static void setSubjectName(String subjectName) {
//         CurrentRequest.subjectName.set(subjectName);
//     }
// 
//     public static void endRequest() {
//         CurrentRequest.domain.set(null);
//         CurrentRequest.subjectName.set(null);
//         CurrentRequest.ipAddress.set(null);
//     }
// 
//     public static String getDomain() {
//         return domain.get();
//     }
// 
//     public static String getSubjectName() {
//         return subjectName.get();
//     }
// 
//     public static String getIPAddress() {
//         return ipAddress.get();
//     }
// }


import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.plexobject.rbac.ServiceFactory;
import com.plexobject.rbac.repository.RepositoryFactory;
import com.plexobject.rbac.utils.CurrentRequest;
import com.sun.jersey.spi.inject.Inject;
package com.plexobject.rbac.web.filter;





public class DomainOwnerFilter implements Filter {

    private static final Logger LOGGER = Logger
            .getLogger(DomainOwnerFilter.class);
    @Autowired
    @Inject
    RepositoryFactory repositoryFactory = ServiceFactory.getDefaultFactory();
    @SuppressWarnings("unused")
    private FilterConfig filterConfig;

    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    public void destroy() {
        this.filterConfig = null;
    }

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse) response;
        if (repositoryFactory.getDomainRepository().isSubjectOwner(
                CurrentRequest.getDomain(), CurrentRequest.getSubjectName())) {
// Path: src/main/java/com/plexobject/rbac/ServiceFactory.java
// public class ServiceFactory {
//     private static RepositoryFactory REPOSITORY_FACTORY = new RepositoryFactoryImpl();
//     private static PermissionManager PERMISSION_MANAGER = new PermissionManagerImpl(
//             REPOSITORY_FACTORY, new JavascriptEvaluator());
// 
//     public static RepositoryFactory getDefaultFactory() {
//         return REPOSITORY_FACTORY;
//     }
// 
//     public static PermissionManager getPermissionManager() {
//         return PERMISSION_MANAGER;
//     }
// }
// 
// Path: src/main/java/com/plexobject/rbac/repository/RepositoryFactory.java
// public interface RepositoryFactory {
//     /**
//      * 
//      * @return instance of security repository
//      */
//     SecurityMappingRepository getSecurityMappingRepository(String domain);
// 
//     /**
//      * 
//      * @return instance of domain repository to manage domains
//      */
//     DomainRepository getDomainRepository();
// 
//     /**
//      * 
//      * @return high level domain for this application
//      */
//     Subject getSuperAdmin();
// 
//     /**
//      * 
//      * @return high level domain for this application
//      */
//     Domain getDefaultDomain();
// 
//     /**
//      * 
//      * @param domain
//      * @return repository of roles for specific domain
//      */
//     RoleRepository getRoleRepository(String domain);
// 
//     /**
//      * 
//      * @param domain
//      * @return repository of permissions for given domain
//      */
//     PermissionRepository getPermissionRepository(String domain);
// 
//     /**
//      * 
//      * @param domain
//      * @return repository of security errors for given domain
//      */
//     SecurityErrorRepository getSecurityErrorRepository(String domain);
// 
//     /**
//      * 
//      * @param domain
//      * @return repository of subjects for given domain
//      */
//     SubjectRepository getSubjectRepository(String domain);
// 
//     /**
//      * 
//      * @return
//      */
//     SubjectRepository getDefaultSubjectRepository();
// }
// 
// Path: src/main/java/com/plexobject/rbac/utils/CurrentRequest.java
// public class CurrentRequest {
//     private static final ThreadLocal<String> domain = new ThreadLocal<String>();
//     private static final ThreadLocal<String> subjectName = new ThreadLocal<String>();
//     private static final ThreadLocal<String> ipAddress = new ThreadLocal<String>();
// 
//     public static void startRequest(final String domain, final String subjectName,
//             final String ipAddress) {
//         CurrentRequest.domain.set(domain);
//         CurrentRequest.subjectName.set(subjectName);
//         CurrentRequest.ipAddress.set(ipAddress);
//     }
// 
//     public static void setSubjectName(String subjectName) {
//         CurrentRequest.subjectName.set(subjectName);
//     }
// 
//     public static void endRequest() {
//         CurrentRequest.domain.set(null);
//         CurrentRequest.subjectName.set(null);
//         CurrentRequest.ipAddress.set(null);
//     }
// 
//     public static String getDomain() {
//         return domain.get();
//     }
// 
//     public static String getSubjectName() {
//         return subjectName.get();
//     }
// 
//     public static String getIPAddress() {
//         return ipAddress.get();
//     }
// }


// Path: src/main/java/com/plexobject/rbac/web/filter/DomainOwnerFilter.java
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.plexobject.rbac.ServiceFactory;
import com.plexobject.rbac.repository.RepositoryFactory;
import com.plexobject.rbac.utils.CurrentRequest;
import com.sun.jersey.spi.inject.Inject;

package com.plexobject.rbac.web.filter;





public class DomainOwnerFilter implements Filter {

    private static final Logger LOGGER = Logger
            .getLogger(DomainOwnerFilter.class);
    @Autowired
    @Inject
    RepositoryFactory repositoryFactory = ServiceFactory.getDefaultFactory();
    @SuppressWarnings("unused")
    private FilterConfig filterConfig;

    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    public void destroy() {
        this.filterConfig = null;
    }

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse) response;
        if (repositoryFactory.getDomainRepository().isSubjectOwner(
                CurrentRequest.getDomain(), CurrentRequest.getSubjectName())) {
            chain.doFilter(request, response);