use of org.apache.wss4j.common.ext.WSSecurityException in project ddf by codice.
the class PaosInInterceptor method checkAuthnRequest.
private void checkAuthnRequest(SOAPPart soapRequest) throws IOException {
XMLObject authnXmlObj = null;
try {
Node node = soapRequest.getEnvelope().getBody().getFirstChild();
authnXmlObj = SamlProtocol.getXmlObjectFromNode(node);
} catch (WSSecurityException | SOAPException | XMLStreamException ex) {
throw new IOException("Unable to convert AuthnRequest document to XMLObject.");
}
if (authnXmlObj == null) {
throw new IOException("AuthnRequest object is not Found.");
}
if (!(authnXmlObj instanceof AuthnRequest)) {
throw new IOException("SAMLRequest object is not AuthnRequest.");
}
}
use of org.apache.wss4j.common.ext.WSSecurityException in project ddf by codice.
the class UsernameTokenValidator method validateToken.
/**
* Validate a Token using the given TokenValidatorParameters.
*/
public TokenValidatorResponse validateToken(TokenValidatorParameters tokenParameters) {
LOGGER.debug("Validating UsernameToken");
if (parser == null) {
throw new IllegalStateException("XMLParser must be configured.");
}
if (failedLoginDelayer == null) {
throw new IllegalStateException("Failed Login Delayer must be configured");
}
STSPropertiesMBean stsProperties = tokenParameters.getStsProperties();
Crypto sigCrypto = stsProperties.getSignatureCrypto();
CallbackHandler callbackHandler = stsProperties.getCallbackHandler();
RequestData requestData = new RequestData();
requestData.setSigVerCrypto(sigCrypto);
WSSConfig wssConfig = WSSConfig.getNewInstance();
requestData.setWssConfig(wssConfig);
requestData.setCallbackHandler(callbackHandler);
TokenValidatorResponse response = new TokenValidatorResponse();
ReceivedToken validateTarget = tokenParameters.getToken();
validateTarget.setState(ReceivedToken.STATE.INVALID);
response.setToken(validateTarget);
if (!validateTarget.isUsernameToken()) {
return response;
}
//
// Turn the JAXB UsernameTokenType into a DOM Element for validation
//
UsernameTokenType usernameTokenType = (UsernameTokenType) validateTarget.getToken();
JAXBElement<UsernameTokenType> tokenType = new JAXBElement<>(QNameConstants.USERNAME_TOKEN, UsernameTokenType.class, usernameTokenType);
Document doc = DOMUtils.createDocument();
Element rootElement = doc.createElement("root-element");
List<String> ctxPath = new ArrayList<>(1);
ctxPath.add(UsernameTokenType.class.getPackage().getName());
Element usernameTokenElement = null;
ParserConfigurator configurator = parser.configureParser(ctxPath, UsernameTokenValidator.class.getClassLoader());
try {
parser.marshal(configurator, tokenType, rootElement);
usernameTokenElement = (Element) rootElement.getFirstChild();
} catch (ParserException ex) {
LOGGER.info("Unable to parse username token", ex);
return response;
}
//
try {
boolean allowNamespaceQualifiedPasswordTypes = requestData.isAllowNamespaceQualifiedPasswordTypes();
UsernameToken ut = new UsernameToken(usernameTokenElement, allowNamespaceQualifiedPasswordTypes, new BSPEnforcer());
// The parsed principal is set independent whether validation is successful or not
response.setPrincipal(new CustomTokenPrincipal(ut.getName()));
if (ut.getPassword() == null) {
failedLoginDelayer.delay(ut.getName());
return response;
}
Credential credential = new Credential();
credential.setUsernametoken(ut);
//Only this section is new, the rest is copied from the apache class
Set<Map.Entry<String, Validator>> entries = validators.entrySet();
for (Map.Entry<String, Validator> entry : entries) {
try {
entry.getValue().validate(credential, requestData);
validateTarget.setState(ReceivedToken.STATE.VALID);
break;
} catch (WSSecurityException ex) {
LOGGER.debug("Unable to validate user against {}" + entry.getKey(), ex);
}
}
if (ReceivedToken.STATE.INVALID.equals(validateTarget.getState())) {
failedLoginDelayer.delay(ut.getName());
return response;
}
//end new section
Principal principal = createPrincipal(ut.getName(), ut.getPassword(), ut.getPasswordType(), ut.getNonce(), ut.getCreated());
response.setPrincipal(principal);
response.setTokenRealm(null);
validateTarget.setState(ReceivedToken.STATE.VALID);
validateTarget.setPrincipal(principal);
} catch (WSSecurityException ex) {
LOGGER.debug("Unable to validate token.", ex);
}
return response;
}
use of org.apache.wss4j.common.ext.WSSecurityException in project ddf by codice.
the class TestUsernameTokenValidator method setup.
@Before
public void setup() {
try {
Credential credential = mock(Credential.class);
when(niceValidator.validate(any(Credential.class), any(RequestData.class))).thenReturn(credential);
} catch (WSSecurityException ignore) {
//do nothing
}
failedLoginDelayer = mock(FailedLoginDelayer.class);
}
use of org.apache.wss4j.common.ext.WSSecurityException in project ddf by codice.
the class TestX509PathTokenValidator method setUp.
@Before
public void setUp() {
x509PathTokenValidator = new X509PathTokenValidator();
x509PathTokenValidator.merlin = mock(Merlin.class);
try {
X509Certificate mockCert = mock(X509Certificate.class);
X509Certificate[] x509Certificates = new X509Certificate[] { mockCert };
when(x509PathTokenValidator.merlin.getCertificatesFromBytes(any(byte[].class))).thenReturn(x509Certificates);
when(x509PathTokenValidator.merlin.loadCertificate(any(InputStream.class))).thenReturn(mockCert);
} catch (WSSecurityException e) {
//ignore
}
validator = mock(Validator.class);
}
use of org.apache.wss4j.common.ext.WSSecurityException in project midpoint by Evolveum.
the class ModelWebService method throwFault.
public void throwFault(Throwable ex, OperationResult result) throws FaultMessage {
if (result != null) {
result.recordFatalError(ex.getMessage(), ex);
}
FaultType faultType;
if (ex instanceof ObjectNotFoundException) {
faultType = new ObjectNotFoundFaultType();
} else if (ex instanceof IllegalArgumentException) {
faultType = new IllegalArgumentFaultType();
} else if (ex instanceof ObjectAlreadyExistsException) {
faultType = new ObjectAlreadyExistsFaultType();
} else if (ex instanceof CommunicationException) {
faultType = new CommunicationFaultType();
} else if (ex instanceof ConfigurationException) {
faultType = new ConfigurationFaultType();
} else if (ex instanceof ExpressionEvaluationException) {
faultType = new SystemFaultType();
} else if (ex instanceof SchemaException) {
faultType = new SchemaViolationFaultType();
} else if (ex instanceof PolicyViolationException) {
faultType = new PolicyViolationFaultType();
} else if (ex instanceof AuthorizationException) {
throw new Fault(new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION), WSSecurityException.ErrorCode.FAILED_AUTHENTICATION.getQName());
} else if (ex instanceof SecurityViolationException) {
throw new Fault(new WSSecurityException(WSSecurityException.ErrorCode.FAILURE), WSSecurityException.ErrorCode.FAILURE.getQName());
} else {
faultType = new SystemFaultType();
}
faultType.setMessage(ex.getMessage());
if (result != null) {
faultType.setOperationResult(result.createOperationResultType());
}
FaultMessage fault = new FaultMessage(ex.getMessage(), faultType, ex);
LOGGER.trace("Throwing fault message type: {}", faultType.getClass(), fault);
throw fault;
}
Aggregations