使用metro 2.3以编程方式从webservice读取加密的错误消息

时间:2014-07-29 10:34:05

标签: java ws-security java-metro-framework

在Netbeans中使用带有WS-Security的METRO 2.3我尝试读取加密的Web服务的错误消息。

通信正常,直到我的有效负载包含错误。然后,服务器发送一条加密的错误消息,其中包含出错的信息。我的客户端尝试解密它并理解消息得到的结构超出预期,并抛出XMLSignatureException:

javax.xml.crypto.dsig.XMLSignatureException: 
WSS1717: Error occurred while doing digest verification of body/payload

隐藏服务器发送的错误消息。

第146行引用了异常:

http://grepcode.com/file/repo1.maven.org/maven2/org.glassfish.metro/webservices-rt/2.3/com/sun/xml/ws/security/opt/impl/incoming/processor/StreamingPayLoadDigester.java?av=f#146

如果我启用了最好的日志记录级别,我可以读取第141行记录的信息。

当我捕获异常时,是否可以读取xml流的canonicalizedData?

1 个答案:

答案 0 :(得分:1)

由于似乎没有简单的方法可以做到这一点,我写了一个解决方法。

如果我在最好的级别上启用“记录”,则会报告太多详细信息。所以我编写了自己的日志消息过滤器。

Logger wsitlogger = Logger.getLogger("com.sun.xml.wss.logging.impl.opt.signature");
wsitlogger.setLevel(Level.FINEST);
TextAndLevelFilter logFilter= new TextAndLevelFilter(Level.INFO);
logFilter.addPrefix("WSS1764");
wsitlogger.setFilter(logFilter);

和我的TextLevelFilter.java:

public class TextAndLevelFilter implements Filter {
    private static final int offValue = Level.OFF.intValue();
    private final int levelValue;

    private final Collection<String> prefixes = new LinkedList<>();

    public TextAndLevelFilter(Level level) {
        this.levelValue = level.intValue();
    }

    public void addPrefix(String prefix) {
        prefixes.add(prefix);
    }

    @Override
    public boolean isLoggable(LogRecord record) {
        final String message = record.getMessage();
        for (String prefix : prefixes) {
            if (message.startsWith(prefix)) {
                return true;
            }
        }
        return record.getLevel().intValue() >= levelValue && levelValue != offValue;
    }
}
相关问题