即使在SpringMVC中包含密钥库证书后,也无法对服务器进行身份validation
我正在尝试对jira服务器进行身份validation并从服务器获取问题详细信息,这里我最初手动给出id。 我已经下载了服务器证书并使用keytool导入,密码是“密码”到密钥库。 但我无法在下面validation它是我的代码
我的java代码:
@Controller public class Service{ @RequestMapping("/hello") public String Data(ModelMap model) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, KeyManagementException, UnrecoverableKeyException{ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(new FileInputStream("/users/crohitk/Documents/workspace/frr/publicKey1.store"), "password".toCharArray()); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()) .loadKeyMaterial(keyStore, "password".toCharArray()).build()); HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build(); ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory( httpClient); RestTemplate restTemplate = new RestTemplate(requestFactory); ResponseEntity result = restTemplate.exchange("https://jira.example.com/", HttpMethod.GET, new HttpEntity(createHeaders("user", "password")), String.class); model.addAttribute("message", result); return "helloworld"; } HttpHeaders createHeaders( String username, String password ){ HttpHeaders header = new HttpHeaders(); String auth = username + ":" + password; byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")) ); String base64Creds = "Basic " + new String( encodedAuth ); header.add("Authorization", "Basic " + base64Creds); return header; } }
dispatcher-servlet.xml:
/WEB-INF/views/ .jsp
web.xml:
Archetype Created Web Application dispatcher org.springframework.web.servlet.DispatcherServlet 1 dispatcher / contextConfigLocation /WEB-INF/dispatcher-servlet.xml org.springframework.web.context.ContextLoaderListener
pom.xml中:
4.0.0 frr frr war 0.0.1-SNAPSHOT frr Maven Webapp http://maven.apache.org 4.2.0.RELEASE junit junit 3.8.1 test org.springframework spring-core ${spring.version} org.springframework spring-web ${spring.version} org.springframework spring-webmvc ${spring.version} org.apache.httpcomponents httpclient 4.3.5 commons-codec commons-codec 1.9 frr
将上述代码的编码凭证更改为java文件中的以下代码,上述代码的编码存在一些错误
HttpHeaders createHeaders(){ String plainCreds = "user:password"; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); return headers; }
- 使用JAAS LdapLoginModule通过ActiveDirectory进行身份validation时遇到FailedLoginException
- 身份validation:Kerberos还是SSL?
- Spring Security 4.0.0 + ActiveDirectoryLdapAuthenticationProvider + BadCredentialsException PartialResultException
- 如何使用WSS4J拦截器在Web服务方法中获取经过身份validation的用户
- 在Jetty服务器中,如何获取需要客户端身份validation时使用的客户端证书?
- Spring安全切换到Ldap身份validation和数据库权限
- 身份validation后以编程方式添加角色
- Java – javax.net.ssl.SSLPeerUnverifiedException:peer未经过身份validation
- 如何在spring-security中注销所有登录用户?