Apache Shiro - Forms based authentication not working for me

I'm having trouble implementing forms based authentication. I created a simple web application and before opening the page (/jsp/index.jsp) I want to check the user rights and open the login page if needed.

Unfortunately, if I try to open the link index.jsp (http: // localhost: 8080 / mywebapp / jsp / index.jsp), index.jsp opens immediately, but I was expecting login.jsp first! Here are the import files:

Shiro.ini

[main]
# specify login page
authc.loginUrl = /login.jsp
# name of request parameter with username; if not present filter assumes 'username'
authc.usernameParam = user
# name of request parameter with password; if not present filter assumes 'password'
authc.passwordParam = passw
# does the user wish to be remembered?; if not present filter assumes 'rememberMe'
authc.rememberMeParam = remember
[url]
# enable authc filter for all application pages
/jsp/** = authc
[users]
adminstrator=throttling,Administrator

      

web.xml

<web-app id="starter" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <listener>
        <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
    </listener>
    <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>
        </filter-mapping>
</web-app>

      

This is the directory structure of maven project / src / main

β”œβ”€β”€β”€java
β”œβ”€β”€β”€resources
β”‚       log4j.properties
β”‚       Shiro.ini
β”‚
└───webapp
    β”‚   login.jsp
    β”‚
    β”œβ”€β”€β”€jsp
    β”‚       index.jsp
    β”‚
    └───WEB-INF
        β”‚   web.xml
        β”‚
        └───lib

      

I added these two dependencies to the pom.xml

    <dependency>
      <groupId>org.apache.shiro</groupId>
      <artifactId>shiro-web</artifactId>
      <version>1.2.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.shiro</groupId>
      <artifactId>shiro-core</artifactId>
      <version>1.2.1</version>
    </dependency>

      

I hope I have written any important information! Can anyone help me why this doesn't work for me? Thank you, V.

log4j.properties

log4j.rootLogger=TRACE, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c]: %m%n
log4j.logger.net.sf.ehcache=WARN
log4j.logger.org.apache=WARN
log4j.logger.org.quartz=WARN
log4j.logger.org.apache.shiro=TRACE
log4j.logger.org.apache.shiro.util.ThreadContext=INFO

      

+3


source to share


2 answers


Sorry, but I made a mistake in shiro.ini. I wrote [url] instead of [urls] ... Sorry again and thanks for the help!



0


source


If what you showed here is more accurate, your problem is probably that Shiro is looking for "shiro.ini" by default, whereas you created "Shiro.ini". There is probably also a message in your logs that "ShiroFilter cannot find the ini file".



Also note that you will need to make sure authc is applied to login.jsp for the login to work.

0


source







All Articles