使用java URL连接绕过spring安全性
我在我的项目中使用Spring MVC,在将用户请求映射到URI时,我无法绕过它。 当url被截获时,我收到403错误。 但我能够通过浏览器访问它。
更新
我删除了security.xml中的拦截,当我尝试命中时,我得到以下错误。
请求方法“POST”不受支持
http://49.205.88.200:5080/Batasariservice/groupview.htm username : userx@bat password : 123456
更新:
我的rest控制器:
@RestController public class AuthenticateDeviceRestWS { @Autowired ManageDeviceWSBusiness manageDeviceWSBusiness; @RequestMapping(value = "authAndRegDevice.htm", method = RequestMethod.POST) public @ResponseBody String authenticateAndRegisterDevice( @RequestBody String notificationJsonRequest) throws BatasariWSException { WSDeviceAuthenticateRequest wsDeviceAuthenticateRequest = (WSDeviceAuthenticateRequest) UserAccessManagementUtil .convertToJava(notificationJsonRequest, WSDeviceAuthenticateRequest.class); WSDeviceAuthenticateResponse wsDeviceAuthenticateResponse = manageDeviceWSBusiness .authAndRegisterDevice(wsDeviceAuthenticateRequest); return UserAccessManagementUtil .convertToJson(wsDeviceAuthenticateResponse); } }
更新了 Java Main类,即经过测试
public class AuthURLConnection { static String URL = "http://localhost:5080/Batasariservice/authAndRegDevice.htm"; public static void main(String[] args) { // TODO Auto-generated method stub String json = "{ " + "\"deviceID\":\"Test\", " + "\"deviceName\":\"Test Device\", " + "\"phoneNumber\":\"testnumber\", " + "\"companyIdentifier\":\"bat\", " + "\"userIdentifier\":\"Test\", " + "\"addtionalInfo\":\"\"" + "}"; wsRequest(json); } private static void wsRequest(String jsonInput) { try { URL targetUrl = new URL(URL); HttpURLConnection httpConnection = (HttpURLConnection) targetUrl .openConnection(); httpConnection.setDoOutput(true); httpConnection.setRequestMethod("POST"); httpConnection.setRequestProperty("Content-Type", "application/json"); OutputStream outputStream = httpConnection.getOutputStream(); outputStream.write(jsonInput.getBytes()); outputStream.flush(); if (httpConnection.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + httpConnection.getResponseCode() + ":" + httpConnection.getResponseMessage()); } BufferedReader responseBuffer = new BufferedReader( new InputStreamReader(httpConnection.getInputStream())); String output; StringBuffer sb = new StringBuffer(); while ((output = responseBuffer.readLine()) != null) { sb.append(output); } httpConnection.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
}
更新了我的spring-security.xml文件