[英]Restful Web application (security) in java
我們正在開發兩個Web應用程序應用程序A:在glassfish服務器上運行的Restful Web服務。 應用程序B:在Tomcat服務器上運行的Dynamics Web應用程序。
我只通過我的應用程序B訪問應用程序A,我不希望任何其他應用程序訪問我的應用程序A. 為此,我計划在相應的服務器中安裝客戶端 - 服務器證書,以便我的應用程序A只能由我的應用程序B訪問,我想阻止其他應用程序訪問我的應用程序A.你能告訴我如何在相應的服務器中安裝客戶端 - 服務器證書????
如果有人有更好的替代方案來獲得這個,請解釋我。
如果可能,請用示例解釋。
謝謝
您在尋找身份驗證和授權嗎? 如果是,你可以使用彈簧安全。 如果您只查找具有某些用戶標識和密碼的身份驗證(根級別訪問),請使用基本身份驗證。 它將檢查用戶是否有效並且可以訪問網址。
代碼和更多信息檢查網址。
當您使用Java時,我認為您正在使用Spring Framework,如果是這樣,您可以使用Spring Session在應用程序之間共享身份驗證
碼:
// to inject request
@Context
private HttpServletRequest request;
@GET
@Path("/testAuth")
@Produces(MediaType.APPLICATION_JSON)
public Response testAuth() {
// TODO
// this is only a template for doing authentication in the near future
String returnString = "";
//check if authenticated
String authorization = request.getHeader("Authorization");
if (authorization == null || authorization.toUpperCase().startsWith("BASIC ") == false) {
//no authenticated
returnString = "{\"testAuth\", \"need authentication\"}";
return Response.status(401).entity(returnString).build();
} else{
String credentials = authorization.substring("Basic".length()).trim();
byte[] decoded = DatatypeConverter.parseBase64Binary(credentials);
String decodedString = new String(decoded);
String[] actualCredentials = decodedString.split(":");
String ID = actualCredentials[0];
String Password = actualCredentials[1];
String Result = userAuthenticate(ID, Password);
returnString = "{\"testAuth\", \"" +
" (" + Result + ") \"}";
return Response.status(200).entity(returnString).build();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.