Search code examples
jsptomcatshiro

Shiro still looking for login.jsp, when all application pages renamed to .html


I am modifying my application to rename all .jsp pages to .html.

Modified shiro.ini looks as follows:

[main]
shiro.loginUrl = /login.html

dataSource = org.apache.shiro.jndi.JndiObjectFactory
dataSource.resourceName = java:/comp/env/jdbc/myappDB

credentialsMatcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher

jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.dataSource = $dataSource
jdbcRealm.credentialsMatcher = $credentialsMatcher

[filters]

[urls]
/login.html = authc
/logout = logout
/secure/** = authc

/api/** = authcBasic, rest

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <listener>
        <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
    </listener>

    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>ShiroFilter</filter-name>
        <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ShiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>appmain.html</welcome-file>
    </welcome-file-list>

</web-app>

A few points:

  • The application was working fine before I started modifying the web.xml and application pages to .html extension instead of .jsp extension.
  • The login link that I have on my home page displays "http://localhost:8080/myapp/login.html" when I hover over it. But when I click it, I get a 404 page not found error.
  • I have tried both Firefox and IE11, same problem encountered on both. Cleared cache several times.

Any pointers on what could be wrong?


Solution

  • There was a problem in my original shiro.ini. The first line below [main] started with shiro.loginURL when it actually should be shiro.loginUrl. I made this change and my application is working fine now. I am also editing the question to show correct syntax. I have accepted my own answer to complete/close this question.