use of org.apache.cxf.binding.soap.model.SoapOperationInfo in project ddf by codice.
the class PEPAuthorizingInterceptor method getActionUri.
/**
* This method is an implementation of the WSA-M and WSA-W specs for determining the action URI.<br>
* <ul>
* <li>http://www.w3.org/TR/ws-addr-metadata/#actioninwsdl</li>
* <li>http://www.w3.org/TR/ws-addr-wsdl/#actioninwsdl</li>
* </ul>
* Adapted from {@link org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl} and
* {@link org.apache.cxf.ws.addressing.impl.InternalContextUtils}
*
* @param message
* @return
*/
private String getActionUri(Message message) {
String actionURI = null;
/**
* See if the action is explicitly defined in the WSDL message service model. Retrieves one
* of the Action attribute in the wsdl:input message.
*/
MessageInfo msgInfo = (MessageInfo) message.get(MessageInfo.class.getName());
if (msgInfo != null && msgInfo.getExtensionAttributes() != null) {
// wsaw:Action
Object attr = msgInfo.getExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME);
// wsam:Action
if (attr == null) {
attr = msgInfo.getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME);
}
// support for older usages
if (attr == null) {
attr = msgInfo.getExtensionAttributes().get(new QName(JAXWSAConstants.NS_WSA, Names.WSAW_ACTION_NAME));
}
if (attr == null) {
attr = msgInfo.getExtensionAttributes().get(new QName(Names.WSA_NAMESPACE_WSDL_NAME_OLD, Names.WSAW_ACTION_NAME));
}
if (attr instanceof QName) {
actionURI = ((QName) attr).getLocalPart();
} else {
actionURI = attr == null ? null : attr.toString();
}
}
/**
* See if the action is explicitly defined in the WSDL operation service model. Retrieves
* the operation soap:soapAction property.
*/
if (StringUtils.isEmpty(actionURI)) {
BindingOperationInfo bindingOpInfo = message.getExchange().get(BindingOperationInfo.class);
SoapOperationInfo soi = null;
if (bindingOpInfo != null) {
soi = bindingOpInfo.getExtensor(SoapOperationInfo.class);
if (soi == null && bindingOpInfo.isUnwrapped()) {
soi = bindingOpInfo.getWrappedOperation().getExtensor(SoapOperationInfo.class);
}
}
actionURI = soi == null ? null : soi.getAction();
actionURI = StringUtils.isEmpty(actionURI) ? null : actionURI;
}
/**
* If the service model doesn't explicitly defines the action, we'll construct the default
* URI string.
*/
if (StringUtils.isEmpty(actionURI)) {
QName op = (QName) message.get(MessageContext.WSDL_OPERATION);
QName port = (QName) message.get(MessageContext.WSDL_PORT);
if (op != null && port != null) {
actionURI = port.getNamespaceURI();
actionURI = addPath(actionURI, port.getLocalPart());
actionURI = addPath(actionURI, op.getLocalPart() + "Request");
}
}
return actionURI;
}
use of org.apache.cxf.binding.soap.model.SoapOperationInfo in project ddf by codice.
the class TestPepInterceptorActions method testMessageWithOperationAction.
@Test
public void testMessageWithOperationAction() throws SecurityServiceException {
PEPAuthorizingInterceptor interceptor = new PEPAuthorizingInterceptor();
SecurityManager mockSecurityManager = mock(SecurityManager.class);
interceptor.setSecurityManager(mockSecurityManager);
Message messageWithAction = mock(Message.class);
SecurityAssertion mockSecurityAssertion = mock(SecurityAssertion.class);
SecurityToken mockSecurityToken = mock(SecurityToken.class);
Subject mockSubject = mock(Subject.class);
assertNotNull(mockSecurityAssertion);
PowerMockito.mockStatic(SecurityAssertionStore.class);
PowerMockito.mockStatic(SecurityLogger.class);
when(SecurityAssertionStore.getSecurityAssertion(messageWithAction)).thenReturn(mockSecurityAssertion);
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getSecurityToken()).thenReturn(mockSecurityToken);
when(mockSecurityToken.getToken()).thenReturn(null);
when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
Exchange mockExchange = mock(Exchange.class);
BindingOperationInfo mockBOI = mock(BindingOperationInfo.class);
SoapOperationInfo mockSOI = mock(SoapOperationInfo.class);
when(messageWithAction.getExchange()).thenReturn(mockExchange);
when(mockExchange.get(BindingOperationInfo.class)).thenReturn(mockBOI);
when(mockBOI.getExtensor(SoapOperationInfo.class)).thenReturn(mockSOI);
when(mockSOI.getAction()).thenReturn("urn:catalog:query:query-port:search");
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
CollectionPermission perm = (CollectionPermission) invocation.getArguments()[0];
assertEquals("urn:catalog:query:query-port:search", perm.getAction());
return true;
}
}).when(mockSubject).isPermitted(isA(CollectionPermission.class));
// This should work.
interceptor.handleMessage(messageWithAction);
PowerMockito.verifyStatic();
}
Aggregations