2013-07-26 2 views
0

У меня есть тест JUnit случай, который запускает код, как:org.apache.shiro.UnavailableSecurityManagerException: Нет SecurityManager доступны вызывающему коду

if (SecurityUtil.isAuthenticated()) { 

} 

и дает исключение:

org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration. 

Конфигурация моего тестового класса выглядит следующим образом:

@RunWith(SpringJUnit4ClassRunner.class) 
@TestExecutionListeners({ WebContextTestExecutionListener.class, 
     DependencyInjectionTestExecutionListener.class, 
     DirtiesContextTestExecutionListener.class, 
     TransactionalTestExecutionListener.class }) 
@ActiveProfiles("test") 
@DirtiesContext 
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = { 
     SpringConfig.class, SpringTestingConfig.class, 
     SpringLocalContainerJPAConfig.class, CustomConfiguration.class }) 
public class MyTestClass { } 

, пожалуйста, сообщите, как исправить эту ошибку, спасибо.

ответ

4

решается следующим образом:

private ThreadState _threadState; 
protected Subject _mockSubject; 

     @Before 
     public void before() { 
      _mockSubject = Mockito.mock(Subject.class); 
      _threadState = new SubjectThreadState(_mockSubject); 
      _threadState.bind(); 
     } 
Смежные вопросы