CXF三

本文介绍了一种服务器端的授权拦截器实现方式,该拦截器继承自SoapHeaderInterceptor,并详细展示了其核心代码逻辑,包括配置加载、连接管理和输出流关闭等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

校验类AuthorizationInterceptor写在服务器端的,代码如下:
package com.huawei.support.security;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor;
import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
import org.apache.cxf.transport.Conduit;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
import org.springframework.core.io.Resource;
import com.huawei.support.utils.StreamUtil;
import com.huawei.support.utils.StringUtil;

public class AuthorizationInterceptor extends SoapHeaderInterceptor
{
private static Properties props;
/**
* 配置路径
*/
private Resource configLocation;

public void setConfigLocation(Resource aConfigLocation)
{
this.configLocation = aConfigLocation;
}
private Properties getProps()
{
if (null == props)
{
props = new Properties();
InputStream is = null;
try
{
is = configLocation.getInputStream();
props.load(is);
}
catch (IOException e)
{
props = null;
}
finally
{
StreamUtil.close(is);
}
}
return props;
}
private Conduit getConduit(Message inMessage) throws IOException
{
Exchange exchange = inMessage.getExchange();
EndpointReferenceType target = exchange.get(EndpointReferenceType.class);
Conduit conduit = exchange.getDestination().getBackChannel(inMessage,
null,
target);
exchange.setConduit(conduit);
return conduit;
}
private void close(Message outMessage) throws IOException
{
OutputStream os = outMessage.getContent(OutputStream.class);
os.flush();
os.close();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值