@Test(expected = IllegalArgumentException.class) public void getAuthenticationInfoShouldThrowExceptionIfTokenEmpty() { underTest.getAuthenticationInfo(new X509CertificateToken(new X509Certificate[0])); }
@Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { if (!(token instanceof X509CertificateToken)) { throw new UnsupportedTokenException(); } X500Principal identityPrincipal = (X500Principal) token.getPrincipal(); String uid = null; String cn = null; LdapName ln; try { ln = new LdapName(identityPrincipal.getName(X500Principal.RFC2253)); } catch (InvalidNameException e) { throw new IncorrectCredentialsException("Certificate does not have a valid DN for user", e); } for (Rdn rdn : ln.getRdns()) { if (rdn.getType().equalsIgnoreCase(UID)) { uid = rdn.getValue().toString(); } else if (rdn.getType().equalsIgnoreCase(CN)) { cn = rdn.getValue().toString(); } } X509Certificate subjectX509Certificate = (X509Certificate) token.getCredentials(); try { subjectX509Certificate.checkValidity(); } catch (CertificateExpiredException | CertificateNotYetValidException e) { throw new IncorrectCredentialsException("Subject X509 certificate is not valid", e); } AuthenticationInfo authInfo; if (!Strings.isNullOrEmpty(uid)) { authInfo = new AuthenticationInfo(uid, subjectX509Certificate); authInfo.getOtherPrincipals().add(new X500PrincipalProvider(identityPrincipal)); } else { authInfo = new AuthenticationInfo(new X500PrincipalProvider(identityPrincipal), subjectX509Certificate); } if (cn != null) { authInfo.getOtherPrincipals().add(Principals.fullNamePrincipal(cn)); } authInfo.getOtherPrincipals().add( new X509CertificatePrincipalProvider(((X509CertificateToken) token).getAuthenticatingCertificates()) ); return authInfo; }
X509CertificateRealm implements Realm { @Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { if (!(token instanceof X509CertificateToken)) { throw new UnsupportedTokenException(); } X500Principal identityPrincipal = (X500Principal) token.getPrincipal(); String uid = null; String cn = null; LdapName ln; try { ln = new LdapName(identityPrincipal.getName(X500Principal.RFC2253)); } catch (InvalidNameException e) { throw new IncorrectCredentialsException("Certificate does not have a valid DN for user", e); } for (Rdn rdn : ln.getRdns()) { if (rdn.getType().equalsIgnoreCase(UID)) { uid = rdn.getValue().toString(); } else if (rdn.getType().equalsIgnoreCase(CN)) { cn = rdn.getValue().toString(); } } X509Certificate subjectX509Certificate = (X509Certificate) token.getCredentials(); try { subjectX509Certificate.checkValidity(); } catch (CertificateExpiredException | CertificateNotYetValidException e) { throw new IncorrectCredentialsException("Subject X509 certificate is not valid", e); } AuthenticationInfo authInfo; if (!Strings.isNullOrEmpty(uid)) { authInfo = new AuthenticationInfo(uid, subjectX509Certificate); authInfo.getOtherPrincipals().add(new X500PrincipalProvider(identityPrincipal)); } else { authInfo = new AuthenticationInfo(new X500PrincipalProvider(identityPrincipal), subjectX509Certificate); } if (cn != null) { authInfo.getOtherPrincipals().add(Principals.fullNamePrincipal(cn)); } authInfo.getOtherPrincipals().add( new X509CertificatePrincipalProvider(((X509CertificateToken) token).getAuthenticatingCertificates()) ); return authInfo; } }
X509CertificateRealm implements Realm { @Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { if (!(token instanceof X509CertificateToken)) { throw new UnsupportedTokenException(); } X500Principal identityPrincipal = (X500Principal) token.getPrincipal(); String uid = null; String cn = null; LdapName ln; try { ln = new LdapName(identityPrincipal.getName(X500Principal.RFC2253)); } catch (InvalidNameException e) { throw new IncorrectCredentialsException("Certificate does not have a valid DN for user", e); } for (Rdn rdn : ln.getRdns()) { if (rdn.getType().equalsIgnoreCase(UID)) { uid = rdn.getValue().toString(); } else if (rdn.getType().equalsIgnoreCase(CN)) { cn = rdn.getValue().toString(); } } X509Certificate subjectX509Certificate = (X509Certificate) token.getCredentials(); try { subjectX509Certificate.checkValidity(); } catch (CertificateExpiredException | CertificateNotYetValidException e) { throw new IncorrectCredentialsException("Subject X509 certificate is not valid", e); } AuthenticationInfo authInfo; if (!Strings.isNullOrEmpty(uid)) { authInfo = new AuthenticationInfo(uid, subjectX509Certificate); authInfo.getOtherPrincipals().add(new X500PrincipalProvider(identityPrincipal)); } else { authInfo = new AuthenticationInfo(new X500PrincipalProvider(identityPrincipal), subjectX509Certificate); } if (cn != null) { authInfo.getOtherPrincipals().add(Principals.fullNamePrincipal(cn)); } authInfo.getOtherPrincipals().add( new X509CertificatePrincipalProvider(((X509CertificateToken) token).getAuthenticatingCertificates()) ); return authInfo; } @Inject protected  X509CertificateRealm(@Named("X509CertificateRealm-role-mapping") RoleMapping roleMapping,
            @Named("X509CertificateRealm-role-permission-resolver") RolePermissionResolver rolePermissionResolver); }
X509CertificateRealm implements Realm { @Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { if (!(token instanceof X509CertificateToken)) { throw new UnsupportedTokenException(); } X500Principal identityPrincipal = (X500Principal) token.getPrincipal(); String uid = null; String cn = null; LdapName ln; try { ln = new LdapName(identityPrincipal.getName(X500Principal.RFC2253)); } catch (InvalidNameException e) { throw new IncorrectCredentialsException("Certificate does not have a valid DN for user", e); } for (Rdn rdn : ln.getRdns()) { if (rdn.getType().equalsIgnoreCase(UID)) { uid = rdn.getValue().toString(); } else if (rdn.getType().equalsIgnoreCase(CN)) { cn = rdn.getValue().toString(); } } X509Certificate subjectX509Certificate = (X509Certificate) token.getCredentials(); try { subjectX509Certificate.checkValidity(); } catch (CertificateExpiredException | CertificateNotYetValidException e) { throw new IncorrectCredentialsException("Subject X509 certificate is not valid", e); } AuthenticationInfo authInfo; if (!Strings.isNullOrEmpty(uid)) { authInfo = new AuthenticationInfo(uid, subjectX509Certificate); authInfo.getOtherPrincipals().add(new X500PrincipalProvider(identityPrincipal)); } else { authInfo = new AuthenticationInfo(new X500PrincipalProvider(identityPrincipal), subjectX509Certificate); } if (cn != null) { authInfo.getOtherPrincipals().add(Principals.fullNamePrincipal(cn)); } authInfo.getOtherPrincipals().add( new X509CertificatePrincipalProvider(((X509CertificateToken) token).getAuthenticatingCertificates()) ); return authInfo; } @Inject protected  X509CertificateRealm(@Named("X509CertificateRealm-role-mapping") RoleMapping roleMapping,
            @Named("X509CertificateRealm-role-permission-resolver") RolePermissionResolver rolePermissionResolver); @Override AuthenticationInfo getAuthenticationInfo(AuthenticationToken token); @Override Set<String> getRealmRoles(PrincipalProvider<?> identityPrincipal,
            Collection<PrincipalProvider<?>> otherPrincipals); @Override RoleMapping getRoleMapping(); @Override RolePermissionResolver getRolePermissionResolver(); @Override Class<? extends AuthenticationToken> supportedToken(); }
X509CertificateRealm implements Realm { @Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { if (!(token instanceof X509CertificateToken)) { throw new UnsupportedTokenException(); } X500Principal identityPrincipal = (X500Principal) token.getPrincipal(); String uid = null; String cn = null; LdapName ln; try { ln = new LdapName(identityPrincipal.getName(X500Principal.RFC2253)); } catch (InvalidNameException e) { throw new IncorrectCredentialsException("Certificate does not have a valid DN for user", e); } for (Rdn rdn : ln.getRdns()) { if (rdn.getType().equalsIgnoreCase(UID)) { uid = rdn.getValue().toString(); } else if (rdn.getType().equalsIgnoreCase(CN)) { cn = rdn.getValue().toString(); } } X509Certificate subjectX509Certificate = (X509Certificate) token.getCredentials(); try { subjectX509Certificate.checkValidity(); } catch (CertificateExpiredException | CertificateNotYetValidException e) { throw new IncorrectCredentialsException("Subject X509 certificate is not valid", e); } AuthenticationInfo authInfo; if (!Strings.isNullOrEmpty(uid)) { authInfo = new AuthenticationInfo(uid, subjectX509Certificate); authInfo.getOtherPrincipals().add(new X500PrincipalProvider(identityPrincipal)); } else { authInfo = new AuthenticationInfo(new X500PrincipalProvider(identityPrincipal), subjectX509Certificate); } if (cn != null) { authInfo.getOtherPrincipals().add(Principals.fullNamePrincipal(cn)); } authInfo.getOtherPrincipals().add( new X509CertificatePrincipalProvider(((X509CertificateToken) token).getAuthenticatingCertificates()) ); return authInfo; } @Inject protected  X509CertificateRealm(@Named("X509CertificateRealm-role-mapping") RoleMapping roleMapping,
            @Named("X509CertificateRealm-role-permission-resolver") RolePermissionResolver rolePermissionResolver); @Override AuthenticationInfo getAuthenticationInfo(AuthenticationToken token); @Override Set<String> getRealmRoles(PrincipalProvider<?> identityPrincipal,
            Collection<PrincipalProvider<?>> otherPrincipals); @Override RoleMapping getRoleMapping(); @Override RolePermissionResolver getRolePermissionResolver(); @Override Class<? extends AuthenticationToken> supportedToken();  }