Пример #1
0
    @Override
    public Result filter(FilterChain filterChain, Context context) {

      if (props.isProd()) {
        context.getFlashScope().error("error.unauthorizedAccess");
        return Results.redirect(router.getReverseRoute(AuthController.class, "login"));
      }

      return filterChain.next(context);
    }
Пример #2
0
  @Before
  public void setup() {
    String app = "Ninja";
    String challenge = "Basic realm=\"" + app + "\"";

    when(ninjaProperties.getWithDefault(NinjaConstant.applicationName, app)).thenReturn(app);

    basicAuthFilter =
        new BasicAuthFilter(
            ninja,
            ninjaProperties,
            new UsernamePasswordValidator() {

              @Override
              public boolean validateCredentials(String username, String password) {
                return "james".equals(username) && "bond".equals(password);
              }
            });

    when(ninja.getUnauthorizedResult(context)).thenReturn(result);
    when(result.status(Result.SC_401_UNAUTHORIZED)).thenReturn(result);
    when(result.addHeader(Result.WWW_AUTHENTICATE, challenge)).thenReturn(result);
  }