CXF With UsernameToken (WS-Security Policy)
| August 22, 2012
| Updated : March 27, 2016
cxf,
soap,
usernametoken,
ws-securitypolicy,
11 Comments
Create a cxf.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:soap="http://cxf.apache.org/bindings/soap" xmlns:wsa="http://cxf.apache.org/ws/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" id="loggingInInterceptor" /> <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" id="logOutInterceptor" /> <cxf:bus> <cxf:inInterceptors> <ref bean="loggingInInterceptor" /> </cxf:inInterceptors> <cxf:outInterceptors> <ref bean="logOutInterceptor" /> </cxf:outInterceptors> </cxf:bus> <jaxws:endpoint address="/ChangeStudent" id="changeStudent" implementor="com.student.ChangeStudentDetailsImpl" wsdlLocation="WEB-INF/ChangeStudent.wsdl"> <jaxws:properties> <entry key="ws-security.callback-handler" value-ref="myPasswordCallback" /> </jaxws:properties> </jaxws:endpoint> <!--Added callback for checking the usernametoken credential --> <bean class="com.student.ServerPasswordCallback" id="myPasswordCallback" /> </beans>
web.xml
Change the web.xml file to find CXF servlet and cxf.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/cxf.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
Publishing CXF Web Service
Deployed CXF Web Service
11 Responses to "CXF With UsernameToken (WS-Security Policy)"