Hi Brian
 
I am talking about using Shiro in my test (or in any NON WEB environment).
 
consider the following code:
 
@Test
public void testMe() {
    var subject = SecurityUtils.getSubject();
    subject.login(new SomeToken());
    //here subject is bound to thread (as I understand!!!)
}
 
I’ve read this
Subject subject = new Subject.Builder()...
ThreadState threadState = new SubjectThreadState(subject);
threadState.bind();
try {
    //execute work as the built Subject
} finally {
    //ensure any state is cleaned so the thread won't be
    //corrupt in a reusable or pooled thread environment
    threadState.clear();
}
 
but this is not my situation, as when I do subject.login(...) I don’t manually 
bind
subject to thread. And I want to understand how to unbind thread after 
subject.login().
Or I understand something wrong?
 
 
--
Best regards, Alex Orlov
 
  
>Пятница, 20 ноября 2020, 18:48 +03:00 от Brian Demers <brian.dem...@gmail.com>:
> 
>What type of application are you building? For web applications Shiro can 
>handle the Login (collecting of the username/password) and the thread binding 
>for you, so you don't actually need to do that. (this all happens with the 
>ShiroFilter, and associated chain)
> 
>That said, if you do not want to use shiro-web, you could accomplish the same 
>thing by sticking your code in a Runnable:
>https://github.com/apache/shiro/blob/b0091dfef63288f957389bce42f5a8e85329a1aa/web/src/main/java/org/apache/shiro/web/servlet/AbstractShiroFilter.java#L359-L368
>
>Take a look at the Subject / Thread Association doc:
>https://shiro.apache.org/subject.html#thread-association  
>On Fri, Nov 20, 2020 at 8:50 AM Alex Orlov < ooo_satu...@mail.ru > wrote:
>>Hi all,
>> 
>>I use the following code:
>>var subject = SecurityUtils.getSubject();
>>subject.login(new SomeToken());
>> 
>>As I understand, after `subject.login(new SomeToken())` if subject 
>>successfully logs in, he
>>is bound  to the current thread. Could anyone say how I can clear current 
>>thread, without subject.logout()?
>>I just want the subject leaves in system until it is necessary again (for 
>>example until next request).
>> 
>>I’ve read this article  https://shiro.apache.org/subject.html   but didn’t 
>>find answer there. Please, help.
>> 
>>--
>>Best regards, Alex Orlov
 

Reply via email to