Package net.shibboleth.shared.servlet.impl

# Class BasicHttpServletRequestContentTypeValidator

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.servlet.impl.BasicHttpServletRequestContentTypeValidator

All Implemented Interfaces:
  `Component`, `DestructableComponent`, `InitializableComponent`, `HttpServletRequestValidator`

public class BasicHttpServletRequestContentTypeValidator extends AbstractInitializableComponent implements HttpServletRequestValidator
Component that validates the HTTP content type as one of an allowed set.

Optionally allows for no type to be specified.

Since:
  9.2.0

## Field Summary

Fields
Modifier and Type
Field
Description
`private Set<MediaType>`
`allowedContentTypes`
Allowed parameters.
`private boolean`
`allowNullContentType`
Whether an absent content type is allowed.

## Constructor Summary

Constructors
Constructor
Description
`BasicHttpServletRequestContentTypeValidator()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`Set<String>`
`getAllowedContentTypes()`
Get the allowed types.
`boolean`
`getAllowNullContentType()`
Gets whether to allow an absent content type.
`void`
`setAllowedContentTypes(Collection<String> types)`
Set the allowed types.
`void`
`setAllowNullContentType(boolean flag)`
Sets whether to allow an absent content type.
`void`
`validate(HttpServletRequest request)`
Validate the request.

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, doInitialize, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### allowedContentTypes

@Nonnull private Set<MediaType> allowedContentTypes
Allowed parameters.

### allowNullContentType

private boolean allowNullContentType
Whether an absent content type is allowed.

## Constructor Details

### BasicHttpServletRequestContentTypeValidator

public BasicHttpServletRequestContentTypeValidator()
Constructor.

## Method Details

### getAllowedContentTypes

@Nonnull @Unmodifiable @NotLive public Set<String> getAllowedContentTypes()
Get the allowed types.

Returns:
  the allowed types

### setAllowedContentTypes

public void setAllowedContentTypes(@Nullable Collection<String> types)
Set the allowed types.

Parameters:
  `types` - the allowed types

### getAllowNullContentType

public boolean getAllowNullContentType()
Gets whether to allow an absent content type.

Returns:
  whether to allow an absent content type

### setAllowNullContentType

public void setAllowNullContentType(boolean flag)
Sets whether to allow an absent content type.

Defaults to false.

Parameters:
  `flag` - flag to set

### validate

public void validate(@Nonnull HttpServletRequest request) throws ServletException
Validate the request.

Specified by:
  `validate` in interface `HttpServletRequestValidator`
Parameters:
  `request` - the request to validate
Throws:
  `ServletException` - if the request is determined to be invalid