Spring-mvc

Spring MVC与权限管理整合技术
<beans:import resource="classpath:spring/root-webmvc.xml"/>
    
    <beans:bean id="jspViewResolver" class="com.ccesun.framework.core.spring.RequestHistoryJspViewResolver" >
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>
    
    <context:component-scan base-package="
             com.ccesun.society.web.controller
            ,com.ccesun.society.admin.web.controller
            ,com.ccesun.society.security.web.controller
            ,com.ccesun.society.resource.web.controller
            ,com.ccesun.society.flow.web.controller
            ,com.ccesun.society.work.web.controller
            ,com.ccesun.society.kh.web.controller
            ,com.ccesun.society.share.web.controller
            ,com.ccesun.society.stat.web.controller
            ,com.ccesun.society.zdrq.web.controller
            ,com.ccesun.society.spec.web.controller
            ,com.ccesun.society.zhihzx.web.controller
            ,com.ccesun.society.flow.rpc
            ,com.ccesun.society.esungis.web.controller
            ,com.ccesun.society.hprose.server.web.controller
            ,com.ccesun.society.demand.web.controller
            " />
    
    <interceptors>
        <!--
        <beans:bean class="com.ccesun.framework.plugins.security.web.interceptor.SecurityInterceptor">
        -->
        <beans:bean class="com.ccesun.society.admin.web.controller.SecurityInterceptorImpl">
            <beans:property name="loginUrl" value="/login" />
            <beans:property name="noPermUrl" value="/login" />
            <beans:property name="excludesPath">
                <beans:list>
                    <!--
                        <beans:value type="java.lang.String">/</beans:value>
                        <beans:value type="java.lang.String">/admin</beans:value>
                        <beans:value type="java.lang.String">/resource</beans:value>
                        <beans:value type="java.lang.String">/admin/sys</beans:value>
                     -->
                    <beans:value type="java.lang.String">/main</beans:value>
                    <beans:value type="java.lang.String">/hproseJhpt/rpc</beans:value>
                    <beans:value type="java.lang.String">/login</beans:value>
                    <beans:value type="java.lang.String">/logout</beans:value>
                    <beans:value type="java.lang.String">/plugin</beans:value>
                    <beans:value type="java.lang.String">/esungis/gisdevtest</beans:value>
                </beans:list>
            </beans:property>
        </beans:bean>
    </interceptors>

</beans:beans>



public class SecurityInterceptorImpl extends SecurityInterceptor {
    private List<String> excludesPath;

    private String loginUrl = "/login";

    private String noPermUrl = "/noPermUrl";

    @Override
    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {

        if (!(handler instanceof HandlerMethod)) {
            return true;
        }

        SecurityToken token = SecurityTokenHolder.getSecurityToken();

        boolean userLogin = token != null;
        String contextPath = request.getContextPath();
        String path = request.getRequestURI();
        path = path.substring(contextPath.length());

        if (excludesPath != null && containInList(excludesPath, path)) {
            return true;
        }

        // 用户未登录
        if (!userLogin) {
            response.sendRedirect(contextPath + loginUrl);
            return false;
        }

        // 用户已登录
        if (!path.equals("/admin"))
            return true;

        response.sendRedirect(contextPath + noPermUrl);
        return false;

    }

    public List<String> getExcludesPath() {
        return excludesPath;
    }

    public void setExcludesPath(List<String> excludesPath) {
        this.excludesPath = excludesPath;
    }

    public String getLoginUrl() {
        return loginUrl;
    }

    public void setLoginUrl(String loginUrl) {
        this.loginUrl = loginUrl;
    }

    public String getNoPermUrl() {
        return noPermUrl;
    }

    public void setNoPermUrl(String noPermUrl) {
        this.noPermUrl = noPermUrl;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值