2011-01-04 7 views
1

WS를 호출 할 수 있도록 WS 클라이언트를 보호하려고합니다.
내 코드는 다음과 같습니다UsernameToken (SOAP 보안 헤더)을 사용하여 WS 클라이언트 보안

  SendSmsService smsService = new SendSmsService(); 
SendSms sendSMS = smsService.getSendSms(); 
BindingProvider stub = (BindingProvider)sendSMS; 

//Override endpoint with local copy of wsdl. 
String URL ="";//here is the wsdl url 
Map<String,Object> requestContext = stub.getRequestContext(); 
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, URL); 

//Set usernametoken 
URL fileURL = loader.getResource("client-config.xml"); 
File file = new File(fileURL.getFile()); 

FileInputStream clientConfig = null; 
try { 
clientConfig = new FileInputStream(file); 
} catch (FileNotFoundException e) { 
e.printStackTrace(); 
} 

XWSSecurityConfiguration config = null; 
try { 
config = SecurityConfigurationFactory.newXWSSecurityConfiguration(clientConfig); 
} catch (Exception e) { 
e.printStackTrace(); 
log.warn("Exception: "+e.getMessage()); 
} 
requestContext.put(XWSSecurityConfiguration.MESSAGE_SECURITY_CONFIGURATION, config); 

//Invoke the web service 

String requestId = null; 
try { 
    requestId = sendSMS.sendSms(addresses, senderName, charging, message, receiptRequest); 
} catch (PolicyException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (ServiceException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

및 설정 파일은 다음과 같습니다

<xwss:JAXRPCSecurity xmlns:xwss="http://java.sun.com/xml/ns/xwss/config" optimize="true"> 
<xwss:Service> 
    <xwss:SecurityConfiguration dumpMessages="true" 
    xmlns:xwss="http://java.sun.com/xml/ns/xwss/config"> 
    <xwss:UsernameToken name="username" password="password> 
    </xwss:SecurityConfiguration> 
</xwss:Service> 
<xwss:SecurityEnvironmentHandler> 
    util.SecurityEnvironmentHandler 
</xwss:SecurityEnvironmentHandler> 
</xwss:JAXRPCSecurity> 

을 SecurityEnviromentHandler는 javax.security.auth.callback.CallbackHandler를 구현하는 더미 클래스입니다.

인증은 Oasis 웹 서비스 보안 사용자 이름 토큰 프로파일 1.0을 준수해야합니다.
하지만 계속해서 "보안 헤더 유효하지 않음"오류가 발생합니다.
내가 어디로 잘못 가고 있는지, 누구든지 말해 줄 수 있습니다.
나는 (내 클라이언트 클래스를 생성 JAX_WS 2.1) wsimport의 사용
참고 :이 WS에 대해 알고 한가지 내가 문제를 해결

답변

4

솔루션
WSDL의 URL 및 인증을위한 사용자 & 패스입니다 . 잘못되었다는 것은 client-config.xml 파일이 제대로 설정하지 못했기 때문입니다.

SendSmsService smsService = new SendSmsService(); 
HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver(); 
smsService.setHandlerResolver(handlerResolver); 
SendSms sendSMS = smsService.getSendSms(); 

이 지금은 완벽하게 작동합니다 : 이런 식으로 뭔가를
http://www.javadb.com/using-a-message-handler-to-alter-the-soap-header-in-a-web-service-client
그냥 내 프로젝트 구조로 링크하는이 개 클래스를 복사하고 전화 :이 예에 달려 그것을 사용!

+0

안녕하세요, 질문보다는 대답을 제시하는 것이 좋습니다. – Benjol