/** @see junit.framework.TestCase#setUp() */
  @Before
  public void setUp() throws Exception {
    super.setUp();
    trustedLoginFilter = new TrustedLoginFilter();
    when(componentManager.get(ServerConfigurationService.class))
        .thenReturn(serverConfigurationService);
    when(componentManager.get(SessionManager.class)).thenReturn(sessionManager);
    when(componentManager.get(UserDirectoryService.class)).thenReturn(userDirectoryService);
    when(serverConfigurationService.getBoolean(
            TrustedLoginFilter.ORG_SAKAIPROJECT_UTIL_TRUSTED_LOGIN_FILTER_ENABLED, true))
        .thenReturn(true);
    when(serverConfigurationService.getString(
            TrustedLoginFilter.ORG_SAKAIPROJECT_UTIL_TRUSTED_LOGIN_FILTER_SHARED_SECRET, null))
        .thenReturn("e2KS54H35j6vS5Z38nK40");
    when(serverConfigurationService.getString(
            TrustedLoginFilter.ORG_SAKAIPROJECT_UTIL_TRUSTED_LOGIN_FILTER_SAFE_HOSTS,
            trustedLoginFilter.safeHosts))
        .thenReturn(trustedLoginFilter.safeHosts);
    when(request.getRemoteHost()).thenReturn("localhost");
    when(request.getHeader("x-sakai-token"))
        .thenReturn("sw9TTTqlEbGQkELqQuQPq92ydr4=;username;nonce");
    // default to non-existing session to exercise more code
    when(existingSession.getUserEid()).thenReturn(null);
    when(sessionManager.getCurrentSession()).thenReturn(existingSession);
    when(sessionManager.startSession()).thenReturn(newSession);
    when(user.getEid()).thenReturn("username");
    when(user.getId()).thenReturn("uuid1234567890");
    when(userDirectoryService.getUserByEid("username")).thenReturn(user);

    trustedLoginFilter.setupTestCase(componentManager);
    trustedLoginFilter.init(config);
  }
Example #2
0
  /** inject dependencies */
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ComponentManager manager = org.sakaiproject.component.cover.ComponentManager.getInstance();

    if (securityService == null) {
      securityService = (SecurityService) manager.get(SecurityService.class.getName());
    }
    if (serverConfigurationService == null) {
      serverConfigurationService =
          (ServerConfigurationService) manager.get(ServerConfigurationService.class.getName());
    }
    if (sessionManager == null) {
      sessionManager = (SessionManager) manager.get(SessionManager.class.getName());
    }
  }
 private Object load(ComponentManager cm, String name) {
   Object o = cm.get(name);
   if (o == null) {
     log.error("Cant find Spring component named " + name);
   }
   return o;
 }
  protected void resolveTransientFields() {
    // These are spelled out instead of using imports, to be explicit
    org.sakaiproject.component.api.ComponentManager compMgr =
        org.sakaiproject.component.cover.ComponentManager.getInstance();

    usageSessionServiceAdaptor =
        (UsageSessionServiceAdaptor) compMgr.get("org.sakaiproject.event.api.UsageSessionService");
  }
 /**
  * @throws ServletException
  * @see TrustedLoginFilter#init(FilterConfig)
  */
 @Test(expected = IllegalStateException.class)
 public void testNullUserDirectoryService() throws ServletException {
   when(componentManager.get(UserDirectoryService.class)).thenReturn(null);
   trustedLoginFilter.init(config);
 }