Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8461565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:55:00+00:00 2026-06-10T13:55:00+00:00

I am trying to enhance my spring-enabled web-app’s security using Apache Shiro and am

  • 0

I am trying to enhance my spring-enabled web-app’s security using Apache Shiro and am thus configuring filterchain definitions into a spring-configured file.
How do i achieve the equivalent of

@Controller
@RequestMapping("/mywebapp")
// @RequiresAuthentication (is this possible ? wish i could do this !)
public class MyWebAppController  {

@RequiresRoles(value={"Role1","Role2","Role3"},logical=Logical.OR)
@RequestMapping(value="/home", method = RequestMethod.GET)
public String home() { return .. }

and my spring-config file contains this :
assume that my dispatcherservlet is mapped to /rest/*

  <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    <property name="securityManager" ref="securityManager"/>
    <property name="loginUrl" value="/rest/secure/windowslogin"/>
    <property name="successUrl" value="/mywebapp/rest/menu"/>
    <property name="unauthorizedUrl" value="/mywebapp/rest/unauthorized"/>
    <property name="filters">
        <util:map>
            <entry key="anon">
                <bean class="org.apache.shiro.web.filter.authc.AnonymousFilter"/>
            </entry>
            <entry key="authc">
       <!-- why is this not invoked ? -->
                <bean class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter">
                </bean>
            </entry>
            <entry key="roles">
                <bean class="org.apache.shiro.web.filter.authz.RolesAuthorizationFilter"/>
            </entry>
        </util:map>
    </property>
    <property name="filterChainDefinitions">
        <value>
            /rest/secure/** = anon
            /rest/mywebapp/** = authc, roles[Role1,Role2,Role3]
        </value>
    </property>
</bean>

In the code above i need a logical.OR kind of mapping to the /rest/mywebapp/** using the roles mentioned. This is possible via shiro annotations and it works but rather than specifying at every method i would rather handle it here (since i dont think shiro supports class level annotations yet ?) .
Is this possible ?

Also on a side note why is the authc filter not invoked ?
( for now we assume that the windows login can serve as authentication, using shiro only for authorization )

home page = meta refresh to /rest/secure/windowslogin/
             if within intranet -> login ...
             else /rest/secure/login ... login page.

Is it because the loginurl is different ? How do i circumvent this ? Note that my realm’s getAuthorizationInfo is invoked though using the roles[ .. ] part specified in the config file.. but i was assuming that there should be a check to see if the request is ‘authc’ ? (which probably means that the filter is invoked and SubjectUtils.getSubject() is checked for authentication). Am i missing something in the flow or configuration ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:55:01+00:00Added an answer on June 10, 2026 at 1:55 pm

    This is how shiro-security.xml looks like.

    <bean id="customFilter1" class="com.pkg.RolesAuthorizationFilter">
            <property name="roles" value="ROLE1,ROLE3,ROLE5"></property>
    </bean>
    <bean id="customFilter2" class="com.pkg.RolesAuthorizationFilter">
            <property name="roles" value="ROLE1,ROLE2,ROLE5,ROLE6"></property>
    </bean>
    
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
            <property name="securityManager" ref="securityManager" />
            <property name="loginUrl" value="/login" />
            <property name="successUrl" value="/home" />
            <property name="unauthorizedUrl" value="/unauthorized" />    
         <property name="filters">
            <util:map>
                <entry key="authc">
                    <bean   class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter" />
                </entry>
            </util:map>
        </property>
    
    <property name="filterChainDefinitions">
                <value>
                 /resources/** = anon
                    /login = anon
                    /logout = authc             
                    /unauthorized = authc
                    /someurl/** = customFilter2
                    /** = customFilter1
                </value>
            </property>
    </bean>
    

    And this is RolesAuthorizationFilter class

    package com.pkg;
    
    import java.util.Arrays;
    
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    
    import org.apache.log4j.Logger;
    import org.apache.shiro.subject.Subject;
    import org.apache.shiro.web.filter.authz.AuthorizationFilter;
    
    public class RolesAuthorizationFilter extends AuthorizationFilter {
        protected Logger logger = Logger.getLogger(this.getClass()
                .getCanonicalName());
    
        private String[] roles;
    
        @Override
        protected boolean isAccessAllowed(ServletRequest request,
                ServletResponse response, Object mappedValue) throws Exception {
    
            logger.info("= Roles = " + Arrays.toString(roles));
    
            Subject subject = getSubject(request, response);
            boolean allowAccess = false;
    
            for (String role : roles) {
                if (subject.hasRole(role)) {
    
                    logger.info("Authenticated role " + role);
    
                    allowAccess = true;
                    break;
                }
            }
    
            return allowAccess;
        }
    
        public void setRoles(String[] roles) {
            this.roles = roles;
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand what's the correct way of implementing OpenID authentication with Spring Security.
I am trying to enhance the memory allocation in my non-ARC app. There are
I have a Sinatra web app that I'd very much like to enhance with
I am trying to enhance a form, by showing only relevant fields depending on
I'm trying to write some library functions to enhance the basic collections. Most of
I'm trying to parse a DSN (from a Symfony application) using regular expressions, in
Hoho there. I was just trying to enhance the performance of my application (.NET
I'm trying to enhance Qt's QPrintPreviewWidget by allowing it to display page numbers (in
I am trying to enhance my Logger class with some conditionals to control what
I am trying to work with Spring Data and Neo4j . I started by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.