我正在使用spring 4構建應用程序,並在java.So中保留其他Web服務。對於所有要發送用戶名和密碼的URL,以確保Web services的安全。用戶名應該是「ADMIN」,密碼應該是「ADMIN123」。點擊該服務後,它應該發送一個身份驗證令牌,該值可以用於該會話。如何在java中使用身份驗證令牌執行Spring安全性
服務類
@Path("/users")
@Service
@Component
public class UserWebservice {
@Autowired
ApplicationContext appContext = new ClassPathXmlApplicationContext("spring/config/BeanLocations.xml");
@Autowired
UserProfileBo userProfileBo = (UserProfileBo) appContext.getBean("userProfileBo");
@Path("/")
@GET
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<UserProfilePojo> fetchUserProfile() {
ArrayList<UserProfilePojo> userProfilePojo = userProfileBo.fetch();
return userProfilePojo;
}
的web.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" 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">
<display-name>ABC</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.abc.webservices</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
因此,雖然現在我打http://localhost:8080/ABC/users
並得到響應。 但我希望用戶名和密碼應該添加URL頭爲安全。
請張貼一些代碼,你有問題..鍵入「給我解決方案」不是很歡迎.. – nayana
我已經添加了代碼示例。請查看@otopolsky –
我不是專家o ñ春天等..我只是審查你的問題..但恕我直言,你不通過發送用戶名/密碼通過網址獲得任何安全..或者你已經是https? – nayana