List of usage examples for javax.ejb ObjectNotFoundException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.ejbca.core.protocol.cmp.EndEntityCertAuthModuleTest.java
private AuthenticationToken createTokenWithCert(String adminName, AuthenticationSubject subject, KeyPair keys, int _caid, int eepid, int cpid) { // A small check if we have added a "fail" credential to the subject. // If we have we will return null, so we can test authentication failure. Set<?> usercredentials = subject.getCredentials(); if ((usercredentials != null) && (usercredentials.size() > 0)) { Object o = usercredentials.iterator().next(); if (o instanceof String) { String str = (String) o; if (StringUtils.equals("fail", str)) { return null; }/* w w w .j a v a 2 s . com*/ } } X509Certificate certificate = null; // If there was no certificate input, create a self signed String dn = "CN=" + adminName; // If we have created a subject with an X500Principal we will use this DN to create the dummy certificate. { Set<Principal> principals = subject.getPrincipals(); if ((principals != null) && (principals.size() > 0)) { Principal p = principals.iterator().next(); if (p instanceof X500Principal) { X500Principal xp = (X500Principal) p; dn = xp.getName(); } } } try { createUser(adminName, dn, "foo123", true, _caid, eepid, cpid); } catch (AuthorizationDeniedException e1) { throw new IllegalStateException(e1.getLocalizedMessage(), e1); } catch (UserDoesntFullfillEndEntityProfile e1) { throw new IllegalStateException(e1.getLocalizedMessage(), e1); } catch (WaitingForApprovalException e1) { throw new IllegalStateException(e1.getLocalizedMessage(), e1); } catch (EjbcaException e1) { throw new IllegalStateException(e1.getLocalizedMessage(), e1); } catch (Exception e1) { throw new IllegalStateException(e1.getLocalizedMessage(), e1); } try { certificate = (X509Certificate) signSession.createCertificate(ADMIN, adminName, "foo123", new PublicKeyWrapper(keys.getPublic())); } catch (ObjectNotFoundException e) { throw new IllegalStateException(e.getLocalizedMessage(), e); } catch (CADoesntExistsException e) { throw new IllegalStateException(e.getLocalizedMessage(), e); } catch (EjbcaException e) { throw new IllegalStateException(e.getLocalizedMessage(), e); } catch (AuthorizationDeniedException e) { throw new IllegalStateException(e.getLocalizedMessage(), e); } catch (CesecoreException e) { throw new IllegalStateException(e.getLocalizedMessage(), e); } assertNotNull("Failed to create a test user certificate", certificate); // We cannot use the X509CertificateAuthenticationToken here, since it can only be used internally in a JVM. AuthenticationToken result = new TestX509CertificateAuthenticationToken(certificate); assertNotNull("Failed to create authentication token.", result); return result; }