use of org.apache.cxf.message.Message in project jbossws-cxf by jbossws.
the class JaspiServerAuthenticator method validateRequest.
public void validateRequest(SoapMessage message) {
SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
MessageInfo messageInfo = new GenericMessageInfo(soapMessage, null);
AuthStatus authStatus;
try {
authStatus = sctx.validateRequest(messageInfo, null, null);
} catch (AuthException e) {
if (isSOAP12(message)) {
SoapFault soap12Fault = new SoapFault(e.getMessage(), Soap12.getInstance().getReceiver());
throw soap12Fault;
} else {
throw new SoapFault(e.getMessage(), new QName("", "jaspi AuthException"));
}
}
Message response = null;
if (messageInfo.getResponseMessage() != null && !message.getExchange().isOneWay()) {
Endpoint e = message.getExchange().getEndpoint();
response = new MessageImpl();
response.setExchange(message.getExchange());
response = e.getBinding().createMessage(response);
message.getExchange().setOutMessage(response);
response.setContent(SOAPMessage.class, messageInfo.getResponseMessage());
if (AuthStatus.SEND_CONTINUE == authStatus) {
response.put(Message.RESPONSE_CODE, Integer.valueOf(303));
}
if (AuthStatus.SEND_FAILURE == authStatus) {
response.put(Message.RESPONSE_CODE, Integer.valueOf(500));
}
message.getInterceptorChain().abort();
InterceptorChain chain = OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange());
response.setInterceptorChain(chain);
chain.doInterceptStartingAfter(response, SoapPreProtocolOutInterceptor.class.getName());
}
}
use of org.apache.cxf.message.Message in project jbossws-cxf by jbossws.
the class JBossWSInvokerTest method getTestExchange.
// build up a fake exchange instance, the minimum required to let the flow proceed till the JBossWSInvoker
private Exchange getTestExchange() {
Exchange exchange = new ExchangeImpl();
Message message = new MessageImpl();
message.setExchange(exchange);
exchange.setInMessage(message);
exchange.put(BindingOperationInfo.class, new BindingOperationInfo());
Service service = new ServiceImpl();
MethodDispatcher md = new MethodDispatcher() {
@Override
public Method getMethod(BindingOperationInfo op) {
return this.getClass().getMethods()[0];
}
@Override
public BindingOperationInfo getBindingOperation(Method m, Endpoint endpoint) {
return null;
}
@Override
public void bind(OperationInfo o, Method... methods) {
}
};
service.put(MethodDispatcher.class.getName(), md);
exchange.put(Service.class, service);
return exchange;
}
use of org.apache.cxf.message.Message in project testcases by coheigea.
the class WSS4JBasicAuthFilter method filter.
public void filter(ContainerRequestContext requestContext) throws IOException {
Message message = JAXRSUtils.getCurrentMessage();
AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build());
return;
}
try {
super.validate(message);
} catch (Exception ex) {
throw ExceptionUtils.toInternalServerErrorException(ex, null);
}
}
use of org.apache.cxf.message.Message in project testcases by coheigea.
the class WSS4JBasicAuthFilter method filter.
public void filter(ContainerRequestContext requestContext) throws IOException {
Message message = JAXRSUtils.getCurrentMessage();
AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build());
return;
}
try {
super.validate(message);
} catch (Exception ex) {
throw ExceptionUtils.toInternalServerErrorException(ex, null);
}
}
use of org.apache.cxf.message.Message in project wildfly by wildfly.
the class UsernameTokenCallbackHandler method handle.
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof DelegationCallback) {
DelegationCallback callback = (DelegationCallback) callbacks[i];
Message message = callback.getCurrentMessage();
String username = (String) message.getContextualProperty(SecurityConstants.USERNAME);
String password = (String) message.getContextualProperty(SecurityConstants.PASSWORD);
if (username != null) {
Node contentNode = message.getContent(Node.class);
Document doc = null;
if (contentNode != null) {
doc = contentNode.getOwnerDocument();
} else {
doc = DOMUtils.createDocument();
}
UsernameToken usernameToken = createWSSEUsernameToken(username, password, doc);
callback.setToken(usernameToken.getElement());
}
} else {
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
}
}
}
Aggregations