use of javax.security.cert.CertificateException in project j2objc by google.
the class CertificateExceptionTest method testCertificateException03.
/**
* Test for <code>CertificateException(String)</code> constructor
* Assertion: constructs CertificateException when <code>msg</code> is
* null
*/
public void testCertificateException03() {
String msg = null;
CertificateException tE = new CertificateException(msg);
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of javax.security.cert.CertificateException in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_userCertExpirations method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
HashMap<String, String> certsExpirations = new LinkedHashMap<String, String>();
try {
Attribute userCertsAttribute = getUserCertsAttribute(sess, user);
HashMap<String, String> certs = (LinkedHashMap<String, String>) userCertsAttribute.getValue();
if (certs != null) {
for (String certDN : certs.keySet()) {
String cert = certs.get(certDN);
// Remove --- BEGIN --- and --- END ----
String certWithoutBegin = cert.replaceFirst("-----BEGIN CERTIFICATE-----", "");
String rawCert = certWithoutBegin.replaceFirst("-----END CERTIFICATE-----", "");
X509Certificate x509 = X509Certificate.getInstance(Base64.decodeBase64(rawCert.getBytes()));
// TODO use some defined date/time format
DateFormat dateFormat = DateFormat.getDateInstance();
certsExpirations.put(certDN, dateFormat.format(x509.getNotAfter()));
}
attribute = Utils.copyAttributeToViAttributeWithoutValue(userCertsAttribute, attribute);
}
} catch (AttributeNotExistsException ex) {
// FIXME throw new WrongReferenceAttributeValueException("User " + user + " doesn't have assigned urn:perun:user:attribute-def:def:userCertificates attribute", ex);
} catch (CertificateException e) {
throw new InternalErrorException("CertificateException - user: " + user + ".", e);
}
attribute.setValue(certsExpirations);
return attribute;
}
use of javax.security.cert.CertificateException in project j2objc by google.
the class CertificateExceptionTest method testCertificateException02.
/**
* Test for <code>CertificateException(String)</code> constructor
* Assertion: constructs CertificateException with detail message msg.
* Parameter <code>msg</code> is not null.
*/
public void testCertificateException02() {
CertificateException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new CertificateException(msgs[i]);
assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
assertNull("getCause() must return null", tE.getCause());
}
}
use of javax.security.cert.CertificateException in project j2objc by google.
the class CertificateExceptionTest method testCertificateException01.
/**
* Test for <code>CertificateException()</code> constructor Assertion:
* constructs CertificateException with no detail message
*/
public void testCertificateException01() {
CertificateException tE = new CertificateException();
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of javax.security.cert.CertificateException in project j2objc by google.
the class X509CertificateTest method testGetInstance1.
/**
* getInstance(InputStream inStream) method testing.
*/
public void testGetInstance1() {
if (this.cert == null) {
// Test can not be applied.
return;
}
try {
ByteArrayInputStream bais = new ByteArrayInputStream(cert.getEncoded());
X509Certificate.getInstance(bais);
} catch (java.security.cert.CertificateEncodingException e) {
fail("Unexpected CertificateEncodingException was thrown.");
} catch (CertificateEncodingException e) {
fail("Unexpected CertificateEncodingException was thrown.");
} catch (CertificateException e) {
// The requested certificate type is not available.
// Test pass..
}
// Regression for HARMONY-756
try {
X509Certificate.getInstance((InputStream) null);
fail("No expected CertificateException");
} catch (CertificateException e) {
// expected;
}
}
Aggregations