Java源码示例:org.opensaml.saml.saml2.core.StatusResponseType
示例1
private void validateVersion(StatusResponseType response) throws SamlException {
if (response.getVersion() == null) {
throw new SamlException("Version attribute must not be null");
}
if (!Objects.equals(response.getVersion().toString(), SAMLVersion.VERSION_20.toString())) {
throw new SamlException("Wrong SAML Version");
}
}
示例2
/**
* Validate response.
*
* @param response the response
* @param responseIssuer the response issuer
* @throws SamlException the saml exception
*/
private static void validateResponse(StatusResponseType response, String responseIssuer)
throws SamlException {
try {
new ResponseSchemaValidator().validate(response);
} catch (SamlException e) {
throw new SamlException("The response schema validation failed", e);
}
validateIssuer(response, responseIssuer);
}
示例3
/**
* Validate status.
*
* @param response the response
* @throws SamlException the saml exception
*/
private static void validateStatus(StatusResponseType response) throws SamlException {
String statusCode = response.getStatus().getStatusCode().getValue();
if (!StatusCode.SUCCESS.equals(statusCode)) {
throw new SamlException("Invalid status code: " + statusCode);
}
}
示例4
/**
* Validate the received SAML Response as per the protocol
* @throws ProcessingException
*/
protected void validateSamlResponseProtocol(
StatusResponseType samlResponse,
FedizContext config
) throws ProcessingException {
try {
SAMLProtocolResponseValidator protocolValidator = new SAMLProtocolResponseValidator();
protocolValidator.validateSamlResponse(samlResponse, config);
} catch (WSSecurityException ex) {
LOG.debug(ex.getMessage(), ex);
throw new ProcessingException(TYPE.INVALID_REQUEST);
}
}
示例5
public void validate(StatusResponseType response) throws SamlException {
validateStatus(response);
validateID(response);
validateVersion(response);
validateIssueInstant(response);
}
示例6
private void validateStatus(StatusResponseType response) throws SamlException {
if (response.getStatus() == null) {
throw new SamlException("Status is required");
}
}
示例7
private void validateID(StatusResponseType response) throws SamlException {
if (StringUtils.isEmpty(response.getID())) {
throw new SamlException("ID attribute must not be empty");
}
}
示例8
private void validateIssueInstant(StatusResponseType response) throws SamlException {
if (response.getIssueInstant() == null) {
throw new SamlException("IssueInstant attribute must not be null");
}
}
示例9
/**
* Validate issuer.
*
* @param response the response
* @param responseIssuer the response issuer
* @throws SamlException the saml exception
*/
private static void validateIssuer(StatusResponseType response, String responseIssuer)
throws SamlException {
if (!response.getIssuer().getValue().equals(responseIssuer)) {
throw new SamlException("The response issuer didn't match the expected value");
}
}