Произошла ошибка при использовании обработчика обратного вызова для: SignatureKeyCallback.DefaultPrivKeyCertRequest - PullRequest
0 голосов
/ 13 октября 2019

У меня проблема с получением сертификатов из хранилища ключей.

Чтобы быть уверенным, что это не происходит с хранилищем ключей, я создал новое хранилище ключей на основе учебных пособий для устранения этой проблемы:

keytool -genkeypair -storepass secret -keypass password -keystore spring-boot-project/spring-boot/src/test/resources/test.jks -dname "CN=Spring Boot, OU=Spring, O=Pivotal, L=San Francisco, ST=California, C=US" -validity 3650 -alias spring-boot -keyalg RSA

Моя ошибка:

2019-10-13 19:41:59.563 ERROR 25204 --- [nio-8080-exec-1] j.e.resource.xml.webservices.security    : WSS0216: An Error occurred using Callback Handler for : SignatureKeyCallback.DefaultPrivKeyCertRequest
2019-10-13 19:41:59.571 ERROR 25204 --- [nio-8080-exec-1] j.e.resource.xml.webservices.security    : WSS0217: An Error occurred using Callback Handler handle() Method.

Хранилище ключей находится в каталоге ресурсов (так же, как в XML для политики).

@Bean
public XwsSecurityInterceptor securityInterceptor() {
    XwsSecurityInterceptor securityInterceptor = new XwsSecurityInterceptor();
    securityInterceptor.setPolicyConfiguration(new ClassPathResource("securityPolicy.xml"));
    securityInterceptor.setCallbackHandler(callback());
    //Security Policy -> securityPolicy.xml
    return securityInterceptor;
}

@Bean
public KeyStoreCallbackHandler callback(){
    KeyStoreCallbackHandler callbackHandler = new KeyStoreCallbackHandler();

    KeyStoreFactoryBean keyStoreFactoryBean = new KeyStoreFactoryBean();
    keyStoreFactoryBean.setPassword("secret");
    keyStoreFactoryBean.setLocation(new ClassPathResource("test.jks"));

    callbackHandler.setKeyStore(keyStoreFactoryBean.getObject());
    callbackHandler.setTrustStore(keyStoreFactoryBean.getObject());
    callbackHandler.setPrivateKeyPassword("password");
    return callbackHandler;
}

@Bean
public WebServiceTemplate template(){
    WebServiceTemplate template = new WebServiceTemplate();
    template.setMarshaller(marshaller());
    template.setUnmarshaller(marshaller());
    template.setMessageFactory(soapMessageFactory());
   // ClientInterceptor[] interceptors = new ClientInterceptor[] {securityInterceptor()};

    template.setInterceptors(new ClientInterceptor[] {securityInterceptor()});

    return template;

}

@Bean
public SaajSoapMessageFactory soapMessageFactory(){
    SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
    messageFactory.setSoapVersion(SoapVersion.SOAP_12);
    System.out.println("soapMessageFactory" +messageFactory );

    return messageFactory;
}

@Override
public void addInterceptors(List interceptors) {
    interceptors.add(securityInterceptor());
}
...