UserRepositoryContext implements Serializable { public static UserRepositoryContext getContext(final HttpServletRequest request, final RepositoryName repositoryName) { final HttpSession session = request.getSession(true); final String userName = ServletRequestUtils.getStringParameter(request, "userName", ""); final String userPassword = ServletRequestUtils.getStringParameter(request, "userPassword", ""); final UserContext userContext = (UserContext) WebUtils.getOrCreateSessionAttribute( session, "userContext", UserContext.class); UserRepositoryContext userRepositoryContext = userContext.getUserRepositoryContext(repositoryName); if (userRepositoryContext == null) { userRepositoryContext = new UserRepositoryContext(); userContext.add(repositoryName, userRepositoryContext); } if (!StringUtils.isEmpty(userName) && !StringUtils.isEmpty(userPassword)) { userRepositoryContext.setCredentials(new Credentials(userName, userPassword)); } return userRepositoryContext; }  static UserRepositoryContext getContext(final HttpServletRequest request, final RepositoryName repositoryName); boolean getIsWaitingForExport(); boolean getIsLoggedIn(); void setIsWaitingForExport(final boolean isWaitingForExport); DirEntryComparator.SortType getSortType(); void setSortType(final DirEntryComparator.SortType sortType); DirEntrySorter.SortMode getSortMode(); void setSortMode(final DirEntrySorter.SortMode sortMode); void setLatestRevisionsDisplayCount(final int latestRevisionsDisplayCount); int getLatestRevisionsDisplayCount(); String getCharset(); void setCharset(final String charset); String getSearchMode(); void setSearchMode(final String searchMode); DirEntryTray getDirEntryTray(); void setCredentials(final Credentials credentials); Credentials getCredentials(); boolean hasCredentials(); void clearCredentials(); UUID getExportUuid(); void setExportUuid(UUID uuid); @Override String toString();  }
@Test public void testGetUserContext() throws Exception { final RepositoryName name = new RepositoryName("repository1"); final HttpServletRequest request = new MockHttpServletRequest(); assertNull(request.getSession().getAttribute("userContext")); final UserRepositoryContext userRepositoryContext = UserRepositoryContext.getContext(request, name); assertNotNull(request.getSession()); final Object o = request.getSession().getAttribute("userContext"); assertNotNull(o); assertTrue(o instanceof UserContext); final UserRepositoryContext contextFromSession = ((UserContext) o).getUserRepositoryContext(name); assertSame(contextFromSession, userRepositoryContext); }