Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stateless approach for REST API #5

Open
animator013 opened this issue Aug 5, 2019 · 4 comments
Open

Stateless approach for REST API #5

animator013 opened this issue Aug 5, 2019 · 4 comments

Comments

@animator013
Copy link

Hi there,

i was wondering how to manage specific urls not to use session but a different realm (that is easy) and stateless approach (not sure the best way how to handle this).

Maybe I can use this specific filter https://shiro.apache.org/static/1.3.0/apidocs/org/apache/shiro/web/filter/session/NoSessionCreationFilter.html. Don't know if that is the best approach, if it is maybe we can incorporate this as a setting in the plugin ?

Also there is an .ini file settings here https://shiro.apache.org/session-management.html#web-applications for specific urls, but as we are using grails and a grails plugin, wondering if this is possible.

I know this is doable without shiro but as I am using it maybe it would be better to use shiro for everything security related.

Can you help me with this ?

@animator013
Copy link
Author

animator013 commented Aug 5, 2019

It seems this from NoSessionCreationFilter is enough to paste to before method in Interceptor.

request.setAttribute(DefaultSubjectContext.SESSION_CREATION_ENABLED, Boolean.FALSE)

Maybe we can create a metaclass method stateless() in the Interceptor class to inject this one-line ? Or static variable to control this ?

@pmcneil
Copy link
Member

pmcneil commented Aug 8, 2019

Hmm, yes I've implemented a stateless/sessionless api access - which is related to the JWTRealm I'm implementing - a couple of times....
I have a case where both stateless and statefull are implemented, using ApiSessionStorageEvaluator to determine iff a session is required. in a simplified way it looks like this:

    boolean isSessionStorageEnabled(Subject subject) {
        String api = subject.principals.find { it == 'api' || it == 'jwt' }
        if (api) {
            return false
        }
        return true
    }

maybe add a new security.shiro.session.mode for the simpler case of no session at all?

@animator013
Copy link
Author

animator013 commented Aug 8, 2019

So you've added subjectDao and evaluator beans to the plugin ?

Because that would be awesome and I am looking forward to it :)

@animator013
Copy link
Author

Hi there @pmcneil. Do you have any ETA on this ? Do you have your JWTRealm done ?

Would like to remove that ugly line from my codebase
request.setAttribute(DefaultSubjectContext.SESSION_CREATION_ENABLED, Boolean.FALSE)

If you are not ready with this, maybe I'll make a PR so the subjectDao bean can be overriden.

Thanks, hope you are well :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants