Shiro always redirects me to login.jsp

Here is the config from shiro.ini

shiro.loginUrl = / login.jsp

######### URL CONFIG ################### [urls] /login.jsp = anon / public / login / ** = anon / public / app / ** = authc

Stripes ...

@UrlBinding("/public/app/")
public class CalculatorActionBean implements ActionBean {
.....

}

@UrlBinding("/public/login/")
public class UserAuthenticateBean implements ActionBean {

    private static final transient Logger log = LoggerFactory.getLogger(UserAuthenticateBean.class);
    private ActionBeanContext context;
    private String username;
    private String password;
    private String message;

    public ActionBeanContext getContext() {
        return context;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @DefaultHandler
    @DontValidate
    public Resolution defaultHander() {
        return new ForwardResolution("/login.jsp");
    }

    public Resolution login() {

        Subject currentUser = SecurityUtils.getSubject();
        log.info("CU=" + currentUser.toString());


        if (!currentUser.isAuthenticated()) {
            TenantAuthenticationToken token = new TenantAuthenticationToken(username, password, "jdbcRealm");
            //UsernamePasswordToken token = new UsernamePasswordToken("akumar", "ash");
            token.setRememberMe(true);
            try {
                currentUser.login(token);
            } catch (UnknownAccountException uae) {
                log.info("There is no user with username of " + token.getPrincipal());
            } catch (IncorrectCredentialsException ice) {
                log.info("Password for account " + token.getPrincipal() + " was incorrect!");
            } catch (LockedAccountException lae) {
                log.info("The account for username " + token.getPrincipal() + " is locked.  "
                        + "Please contact your administrator to unlock it.");
            } // ... catch more exceptions here (maybe custom ones specific to your application?
            catch (AuthenticationException ae) {
                //unexpected condition?  error?
                ae.printStackTrace();
            }
        }

        if (currentUser.isAuthenticated()) {
            message = "Success";
        } else {
            message = "Fail";
        }

        System.out.println(message);


        message += getUsername() + getPassword();
        return new ForwardResolution("/logged_in.jsp");
    }
}

      

logged_in.jsp

<a href ="/oc/public/app">app</a>

      

Now if I remove the line / public / app / ** = authc from shiro.ini I can access / public / app for registered users and guests

If I save the line then nobody can access the page and it goes back to login.jsp

Driving me nuts!

help!!

+3


source to share


1 answer


Modify your urls configuration to have an "authc" filter on the actual login url:

[main]
...
authc.loginUrl = /login.jsp

[urls]
/login.jsp = authc
/public/login/** = anon 
/public/app/** = authc

      



The filter authc

is smart enough to know if the request is not validated so that it has not yet gone to the base page for the user to be able to log in.

+3


source







All Articles