@Test public void defaultBehaviour() { HttpCommand command = mock(HttpCommand.class); HttpServletRequest request = mock(HttpServletRequest.class); when(command.getRequest()).thenReturn(request); when(request.getScheme()).thenReturn("https"); validator.validate(command); when(request.getScheme()).thenReturn("http"); when(request.getHeader("Front-End-Https")).thenReturn("On"); validator.validate(command); when(request.getHeader("Front-End-Https")).thenReturn(null); try { validator.validate(command); fail("validate should throw exception if not secured"); } catch (CougarException ce) { } }
@Override public void validate(HttpCommand command) throws CougarException { if (enabled) { if (!command.getRequest().getScheme().equals("https")) { if (!allowExternalTermination || command.getRequest().getHeader(externalTerminationHeader) == null) { throw new CougarServiceException(ServerFaultCode.SecurityException, "This service requires a secure communication protocol"); } } } }
HttpsCommandValidator implements CommandValidator<HttpCommand> { @Override public void validate(HttpCommand command) throws CougarException { if (enabled) { if (!command.getRequest().getScheme().equals("https")) { if (!allowExternalTermination || command.getRequest().getHeader(externalTerminationHeader) == null) { throw new CougarServiceException(ServerFaultCode.SecurityException, "This service requires a secure communication protocol"); } } } } }
HttpsCommandValidator implements CommandValidator<HttpCommand> { @Override public void validate(HttpCommand command) throws CougarException { if (enabled) { if (!command.getRequest().getScheme().equals("https")) { if (!allowExternalTermination || command.getRequest().getHeader(externalTerminationHeader) == null) { throw new CougarServiceException(ServerFaultCode.SecurityException, "This service requires a secure communication protocol"); } } } }  }
HttpsCommandValidator implements CommandValidator<HttpCommand> { @Override public void validate(HttpCommand command) throws CougarException { if (enabled) { if (!command.getRequest().getScheme().equals("https")) { if (!allowExternalTermination || command.getRequest().getHeader(externalTerminationHeader) == null) { throw new CougarServiceException(ServerFaultCode.SecurityException, "This service requires a secure communication protocol"); } } } }  @Override void validate(HttpCommand command); @ManagedAttribute void setEnabled(boolean enabled); @ManagedAttribute void setAllowExternalTermination(boolean allowExternalTermination); @ManagedAttribute void setExternalTerminationHeader(String externalTerminationHeader); @ManagedAttribute boolean isEnabled(); @ManagedAttribute boolean isAllowExternalTermination(); @ManagedAttribute String getExternalTerminationHeader(); }
HttpsCommandValidator implements CommandValidator<HttpCommand> { @Override public void validate(HttpCommand command) throws CougarException { if (enabled) { if (!command.getRequest().getScheme().equals("https")) { if (!allowExternalTermination || command.getRequest().getHeader(externalTerminationHeader) == null) { throw new CougarServiceException(ServerFaultCode.SecurityException, "This service requires a secure communication protocol"); } } } }  @Override void validate(HttpCommand command); @ManagedAttribute void setEnabled(boolean enabled); @ManagedAttribute void setAllowExternalTermination(boolean allowExternalTermination); @ManagedAttribute void setExternalTerminationHeader(String externalTerminationHeader); @ManagedAttribute boolean isEnabled(); @ManagedAttribute boolean isAllowExternalTermination(); @ManagedAttribute String getExternalTerminationHeader();  }