@Test public void testNullSession() { when(context.getSession()).thenReturn(null); // filter that basicAuthFilter.filter(filterChain, context); verifyZeroInteractions(filterChain); }
@Test public void testWorkingSessionWhenUsernameIsThere() { when(context.getSession()).thenReturn(sessionCookie); when(sessionCookie.get(SecureFilter.USERNAME)).thenReturn("myname"); // filter that basicAuthFilter.filter(filterChain, context); verify(filterChain).next(context); }
@Test public void testSessionIsReturningWithValidCredentials() { when(context.getSession()).thenReturn(sessionCookie); when(sessionCookie.get(SecureFilter.USERNAME)).thenReturn(null); when(context.getHeader("Authorization")).thenReturn(auth("james", "bond")); // filter that basicAuthFilter.filter(filterChain, context); verify(filterChain).next(context); }
public Object call(Context context, Object obj) throws Exception { if (obj != null) { context = context.getSession().getMap(); if (contextual) { return method.invoke(obj, new Object[] {context}); } else { return method.invoke(obj, new Object[0]); } } else { return null; } }
@Test public void testUnauthenticatedSession() { when(context.getSession()).thenReturn(sessionCookie); when(sessionCookie.get(SecureFilter.USERNAME)).thenReturn(null); when(result.getTemplate()).thenReturn(NinjaConstant.LOCATION_VIEW_FTL_HTML_UNAUTHORIZED); // filter that Result result = basicAuthFilter.filter(filterChain, context); assertEquals(NinjaConstant.LOCATION_VIEW_FTL_HTML_UNAUTHORIZED, result.getTemplate()); verifyZeroInteractions(filterChain); }
/** {@inheritDoc} */ @Override public void writeType(final Context context, final String entityName, final PrintWriter out) throws Exception { out.println("/**"); out.println(" * Lifecycle state names for <code>" + entityName + "</code>."); out.println(" */"); out.println("public interface " + createLifecycleClassName(entityName) + " {"); out.println(); out.println(" /**"); out.println(" * The name of the lifecycle itself."); out.println(" */"); out.println( " String " + entityName.toUpperCase() + " = \"" // + entityName + "\";"); out.println(); /** Don't create a name twice. */ final Set<String> processedStateNames = new HashSet<String>(); final StringTable stateNames = context .getSession() .query("select state_name from dm_policy where object_name = '" + entityName + "'"); StateLoop: for (final Row row : stateNames) { final String stateName = row.getValue(0); // missing error states lead to empty state names - skip if (StringUtils.isEmpty(stateName)) { continue StateLoop; } if (processedStateNames.contains(stateName)) { continue StateLoop; } processedStateNames.add(stateName); out.println(); out.println(" /**"); out.println(" * <code>" + stateName + "</code>."); out.println(" */"); out.println( " String " + createLifecycleStateConstantName(stateName) + " = \"" + stateName + "\";"); } out.println(); out.println("}"); }
@Test public void testSessionIsNotReturingWithInvalidCredentials() { when(context.getSession()).thenReturn(sessionCookie); when(sessionCookie.get(SecureFilter.USERNAME)).thenReturn(null); when(result.getTemplate()).thenReturn(NinjaConstant.LOCATION_VIEW_FTL_HTML_UNAUTHORIZED); when(context.getHeader("Authorization")).thenReturn(auth("test", "user")); // filter that Result result = basicAuthFilter.filter(filterChain, context); assertEquals(NinjaConstant.LOCATION_VIEW_FTL_HTML_UNAUTHORIZED, result.getTemplate()); verifyZeroInteractions(filterChain); }
/** {@inheritDoc} */ @Override public Collection<String> getEntityNames(final Context context) throws Exception { final Collection<String> names = new TreeSet<String>(); final StringTable lifecycleNames = context .getSession() .query("select object_name from dm_policy where object_name like 'spr_lc%'"); for (final Row row : lifecycleNames) { names.add(row.getValue(0)); } return names; }
@Override public Session getSession() { return wrapped.getSession(); }