use of org.apache.cxf.service.model.MessageInfo in project ddf by codice.
the class TestPepInterceptorActions method testMessageWithMessageAction.
@Test
public void testMessageWithMessageAction() 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);
MessageInfo mockMessageInfo = mock(MessageInfo.class);
when(messageWithAction.get(MessageInfo.class.getName())).thenReturn(mockMessageInfo);
when(mockMessageInfo.getExtensionAttribute(new QName(Names.WSA_NAMESPACE_WSDL_METADATA, Names.WSAW_ACTION_NAME))).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();
}
use of org.apache.cxf.service.model.MessageInfo in project tomee by apache.
the class JAXBContextInitializer method begin.
@Override
public void begin(MessagePartInfo part) {
Class<?> clazz = part.getTypeClass();
if (clazz == null) {
return;
}
if (Exception.class.isAssignableFrom(clazz)) {
// exceptions are handled special, make sure we mark it
part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
}
boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
if (isFromWrapper && !Boolean.TRUE.equals(part.getProperty("messagepart.isheader"))) {
UnwrappedOperationInfo uop = (UnwrappedOperationInfo) part.getMessageInfo().getOperation();
OperationInfo op = uop.getWrappedOperation();
MessageInfo inf = null;
if (uop.getInput() == part.getMessageInfo()) {
inf = op.getInput();
} else if (uop.getOutput() == part.getMessageInfo()) {
inf = op.getOutput();
}
if (inf != null && inf.getFirstMessagePart().getTypeClass() != null) {
// wrapper type (unless it's a header which wouldn't be in the wrapper)
return;
}
}
if (isFromWrapper && clazz.isArray() && !Byte.TYPE.equals(clazz.getComponentType())) {
clazz = clazz.getComponentType();
}
Annotation[] a = (Annotation[]) part.getProperty("parameter.annotations");
checkForAdapter(clazz, a);
Type genericType = (Type) part.getProperty("generic.type");
if (genericType != null) {
boolean isList = Collection.class.isAssignableFrom(clazz);
if (isFromWrapper) {
if (genericType instanceof Class && ((Class<?>) genericType).isArray()) {
Class<?> cl2 = (Class<?>) genericType;
if (cl2.isArray() && !Byte.TYPE.equals(cl2.getComponentType())) {
genericType = cl2.getComponentType();
}
addType(genericType);
} else if (!isList) {
addType(genericType);
}
} else {
addType(genericType, true);
}
if (isList && genericType instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) genericType;
if (pt.getActualTypeArguments().length > 0 && pt.getActualTypeArguments()[0] instanceof Class) {
Class<? extends Object> arrayCls = Array.newInstance((Class<?>) pt.getActualTypeArguments()[0], 0).getClass();
clazz = arrayCls;
part.setTypeClass(clazz);
if (isFromWrapper) {
addType(clazz.getComponentType(), true);
}
} else if (pt.getActualTypeArguments().length > 0 && pt.getActualTypeArguments()[0] instanceof GenericArrayType) {
GenericArrayType gat = (GenericArrayType) pt.getActualTypeArguments()[0];
gat.getGenericComponentType();
Class<? extends Object> arrayCls = Array.newInstance((Class<?>) gat.getGenericComponentType(), 0).getClass();
clazz = Array.newInstance(arrayCls, 0).getClass();
part.setTypeClass(clazz);
if (isFromWrapper) {
addType(clazz.getComponentType(), true);
}
}
}
if (isFromWrapper && isList) {
clazz = null;
}
}
if (clazz != null) {
if (!isFromWrapper && clazz.getAnnotation(XmlRootElement.class) == null && clazz.getAnnotation(XmlType.class) != null && StringUtils.isEmpty(clazz.getAnnotation(XmlType.class).name())) {
Object ref = createTypeReference(part.getName(), clazz);
if (ref != null) {
typeReferences.add(ref);
}
}
addClass(clazz);
}
}
use of org.apache.cxf.service.model.MessageInfo 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>http://www.w3.org/TR/ws-addr-wsdl/#actioninwsdl
* </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.service.model.MessageInfo in project ddf by codice.
the class PepInterceptorActionsTest method testMessageWithMessageAction.
@Test
public void testMessageWithMessageAction() throws SecurityServiceException {
SecurityManager mockSecurityManager = mock(SecurityManager.class);
interceptor.setSecurityManager(mockSecurityManager);
Message messageWithAction = mock(Message.class);
SecurityToken mockSecurityToken = mock(SecurityToken.class);
Subject mockSubject = mock(Subject.class);
assertNotNull(mockSecurityAssertion);
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getToken()).thenReturn(mockSecurityToken);
when(mockSecurityToken.getToken()).thenReturn(null);
when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
MessageInfo mockMessageInfo = mock(MessageInfo.class);
when(messageWithAction.get(MessageInfo.class.getName())).thenReturn(mockMessageInfo);
when(mockMessageInfo.getExtensionAttribute(new QName(Names.WSA_NAMESPACE_WSDL_METADATA, Names.WSAW_ACTION_NAME))).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);
}
use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class JaxWsServiceFactoryBeanTest method testDocLiteralPartWithType.
@Test
public void testDocLiteralPartWithType() throws Exception {
ReflectionServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
serviceFactory.setBus(getBus());
serviceFactory.setServiceClass(NoBodyPartsImpl.class);
Service service = serviceFactory.create();
ServiceInfo serviceInfo = service.getServiceInfos().get(0);
QName qname = new QName("urn:org:apache:cxf:no_body_parts/wsdl", "operation1");
MessageInfo mi = serviceInfo.getMessage(qname);
qname = new QName("urn:org:apache:cxf:no_body_parts/wsdl", "mimeAttachment");
MessagePartInfo mpi = mi.getMessagePart(qname);
QName elementQName = mpi.getElementQName();
XmlSchemaElement element = serviceInfo.getXmlSchemaCollection().getElementByQName(elementQName);
assertNotNull(element);
}
Aggregations