Minor improvements to the code

revert-70aa11f8
Janak Amarasena 8 years ago
parent 3ecb6da575
commit 2b0800794d

@ -152,6 +152,9 @@ public class AuthenticationHandler extends AbstractHandler {
CertificateFactory cf = CertificateFactory.getInstance("X.509"); CertificateFactory cf = CertificateFactory.getInstance("X.509");
ByteArrayInputStream bais = new ByteArrayInputStream(certs[0].getEncoded()); ByteArrayInputStream bais = new ByteArrayInputStream(certs[0].getEncoded());
X509Certificate x509 = (X509Certificate) cf.generateCertificate(bais); X509Certificate x509 = (X509Certificate) cf.generateCertificate(bais);
if (bais != null) {
bais.close();
}
if (x509 != null) { if (x509 != null) {
headers.put(AuthConstants.PROXY_MUTUAL_AUTH_HEADER, CertificateGenerator.getCommonName(x509)); headers.put(AuthConstants.PROXY_MUTUAL_AUTH_HEADER, CertificateGenerator.getCommonName(x509));
return true; return true;
@ -197,13 +200,12 @@ public class AuthenticationHandler extends AbstractHandler {
log.error("Error while processing certificate.", e); log.error("Error while processing certificate.", e);
return false; return false;
} catch (CertificateException e) { } catch (CertificateException e) {
e.printStackTrace(); log.error("Certificate issue occurred when generating converting PEM to x509Certificate", e);
return false; return false;
} catch (CertificateEncodingException e) { } catch (CertificateEncodingException e) {
e.printStackTrace(); log.error("Error while attempting to encode certificate.", e);
return false; return false;
} }
} }
@Override @Override
@ -215,7 +217,7 @@ public class AuthenticationHandler extends AbstractHandler {
private String getDeviceType(String url) { private String getDeviceType(String url) {
StringTokenizer parts = new StringTokenizer(url, "/"); StringTokenizer parts = new StringTokenizer(url, "/");
while (parts.hasMoreElements()) { while (parts.hasMoreElements()) {
if (parts.nextElement().equals("device-mgt")) { if (parts.nextElement().equals("api")) {
return (String) parts.nextElement(); return (String) parts.nextElement();
} }
} }

Loading…
Cancel
Save