大家好,我將在我的web應用程序中集成我寧靜的web服務的身份驗證。我已經將Spring安全3.1集成到了我的整個應用程序和它的工作中;但我很困惑,我真的陷入困境,如何在現有的應用程序中集成Web服務的安全性? 這裏是我現有的用於認證和授權的安全配置。爲Restful Web服務提供安全性,將其用於現有的Spring安全性3.1
securityApplicationContext.xml:
<beans:bean id="myAccessDecisionManager"
class="com.security.repository.MyAccessDecisionManager">
<beans:property name="customAuthenticatiuonService" ref="customAuthenticatiuonServiceImpl"> </beans:property>
</beans:bean>
<http auto-config="true" once-per-request="true"
access-decision-manager-ref="myAccessDecisionManager" access-denied-page="/jsp/errorPage.jsp">
<intercept-url pattern="/*.web" access="ROLE_ANONYMOUS" />
<intercept-url pattern="productsService/*.web" access="ROLE_ADMIN" />
<!-- Override default login and logout pages -->
<form-login login-page="/login.works" login-processing-url="/j_spring_security_check"
default-target-url="/login/validate.works"
authentication-failure-url="/login.works?login_error=1" />
<logout logout-url="/j_spring_security_logout"
logout-success-url="/login.works" invalidate-session="true" />
<session-management invalid-session-url="/login.works"
session-fixation-protection="newSession">
<concurrency-control max-sessions="100"
error-if-maximum-exceeded="false" />
</session-management>
</http>
<authentication-manager>
<authentication-provider ref="customAuthenticationProvider"></authentication-provider>
</authentication-manager>
<beans:bean id="customAuthenticationProvider"
class="com.security.repository.CustomAuthenticationProvider">
<beans:property name="customAuthenticatiuonService" ref="customAuthenticatiuonServiceImpl"> </beans:property>
</beans:bean>
<beans:bean id="customAuthenticatiuonServiceImpl"
class="com.service.impl.CustomAuthenticatiuonServiceImpl">
<beans:property name="customAuthenticationDAO" ref="customAuthenticationDAOTarget"> </beans:property>
</beans:bean>
<beans:bean id="customAuthenticationDAOTarget" class="com.dao.impl.CustomAuthenticatiuonDAOImpl">
<beans:property name="hibernateTemplate" ref="cessHibernateTemplate"/>
</beans:bean>
現在我期待它如下,以確保我的Web服務:
我的Web服務:
@Component
@Path("/productsService")
//@RequestMapping("/productsService")
@Scope("request")
@Controller
public class ProductsController {
@Autowired
private ProductsService products;
@GET
@Path("/getProductsList.lbt")
// @RequestMapping("/getProductsList.lbt")
@Produces("text/plain")
public String getProductsList() {
return products.getProductsList();
}
}
@Service("products")
public class ProductsService {
@Secured("ROLE_ADMIN")
public String getProductsList() {
return "Test String for Rest Web Service";
}
}
和最後我的客戶類別:
public static void main(String[] args) {
Client c = Client.create();
// plain text
WebResource r = c
.resource("http://localhost:8080/productsService/getProductsList.web");
c.addFilter(new HTTPBasicAuthFilter("admin", "admin"));
c.setFollowRedirects(false);
System.out.println("Plain Text=>> " + r.get(String.class));
}
我正在使用customAuthenticationManager和myAccessDecisionManger進行用戶的身份驗證和授權。 當我在控制器上使用@Path註解並對其進行調試時,調試器無法訪問我的控制器,並且發現402未找到錯誤,當我使用@RequestMapping時,它會正常運行,但是當從控制器返回時,我在客戶端302發現。 如何解決這個問題?請幫幫我。 在此先感謝。
感謝您的回覆;現在我忙於另一項任務,一旦我有空,我會嘗試你的建議。 – Balasaheb