Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Shiro - form based authentication doesn't seem to work for me

Tags:

security

shiro

I have got problems with implementing form based authentication. I created a simple web application and before openening a page (/jsp/index.jsp) I want to check the user's rights and open a login page if it is necessary.

Unfortunately if I try to open the link of index.jsp (http://localhost:8080/mywebapp/jsp/index.jsp) the index.jsp is turning up immediately but I expected the login.jsp first! Here are the importan 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 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>

Hopefully I wrote any of the important information! Could anyone help me why it doesn't work for me? Thanks, 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
like image 341
Viktor Avatar asked Dec 01 '25 14:12

Viktor


1 Answers

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

like image 174
Viktor Avatar answered Dec 03 '25 15:12

Viktor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!