jeesite登录至业务

转自https://blog.csdn.net/gaoduicai/article/details/79300464

登录后跳操作理解

首先配置中jeesite.properties中设置:

adminPath=/a :项目管理端域名

frontPath=/f :前端域名

<form id="loginForm" class="form login-form" action="${ctx}/login" method="post">

点击登录会通过springmvc至后台colltrer控制器

通过控制器类可知道:

@RequestMapping(value = "${adminPath}/login", method = RequestMethod.GET)

mapping请求地址会被相关拦截器拦截;成功

<!-- 拦截器配置,拦截顺序:先执行后定义的,排在第一位的最后执行。-->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="${adminPath}/**" />
<mvc:mapping path="/rest/**" />
<mvc:exclude-mapping path="${adminPath}/"/>
<mvc:exclude-mapping path="${adminPath}/login"/>
<mvc:exclude-mapping path="${adminPath}/sys/menu/tree"/>
<mvc:exclude-mapping path="${adminPath}/sys/menu/treeData"/>
<mvc:exclude-mapping path="${adminPath}/oa/oaNotify/self/count"/>
<bean class="com.thinkgem.jeesite.modules.sys.interceptor.LogInterceptor" />
</mvc:interceptor>
</mvc:interceptors>

return return "modules/sys/sysLogin";(此处则为登录界面jsp)至此访问应用之登录jsp前端完成;

下来时登录页面跳转:

shiro的登陆功能在controller之前加入了一个filter。这个filter被配置在文件spring-context-shiro.xml文件里;

<!-- Shiro权限过滤过滤器定义 -->
<bean name="shiroFilterChainDefinitions" class="java.lang.String"><!-- 配置shiro要拦截的请求 -->
    <constructor-arg>
       <value>
          /static/** = anon
          /userfiles/** = anon
          ${adminPath}/cas = cas
          ${adminPath}/login = authc
          ${adminPath}/logout = logout
          ${adminPath}/** = authc
          /act/editor/** = user
          /ReportServer/** = user
          /rest/** = anon
          /chat/** = authc
       </value>
     </constructor-arg>
</bean>

<!-- 安全认证过滤器 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    <property name="securityManager" ref="securityManager" /><!-- 
    <property name="loginUrl" value="${cas.server.url}?service=${cas.project.url}${adminPath}/cas" /> -->
    <property name="loginUrl" value="${adminPath}/login" />
    <property name="successUrl" value="${adminPath}?login" /><!-- 登录成功跳转页面 -->
    <property name="filters">
        <map>
            <entry key="cas" value-ref="casFilter"/>
            <entry key="authc" value-ref="formAuthenticationFilter"/>
            <entry key="logout" value-ref="systemLogoutFilter" /> 
        </map>
    </property>
    <property name="filterChainDefinitions">
        <ref bean="shiroFilterChainDefinitions"/>
    </property>
</bean>

以上就是配置过程最关键的部分。loginUrl属性所指定的url表示的是所有未通过验证的url所访问的位置,此处就是登录界面;
successUrl表示的是成功登陆的url访问的位置,此处就是主页。filters则是配置具体验证方法的位置。
在此处,${adminPath}/login = authc指定了/a/login,既登陆页面,所需要的验证权限名为authc,又配置了authc所用的
filter为formAuthenticationFilter。
因此整个逻辑是:如果任何地方未登陆,则访问/a/login页面,而/a/login页面的验证权限中又指定了formAuthenticationFilter
做为过滤,如果过滤中验证成功,则访问/a这个主页。所以,login.jsp中的表单信息则首先交由formAuthenticationFilter首先处理。

后台shiro

Shiro在注解模式下,登录失败,与没有权限均是通过抛出异常。并且默认并没有去处理或者捕获这些异常。在springMVC下需要配置捕获
相应异常来通知用户信息,如果不配置异常会抛出到页面

<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
  <property name="exceptionMappings">
     <props>
        <prop key="org.apache.shiro.authz.UnauthorizedException">error/403</prop>
        <prop key="java.lang.Throwable">error/500</prop>
     </props>
  </property>
</bean>

猜你喜欢

转载自www.cnblogs.com/person008/p/9488301.html