Java Code Examples for java.security.Principal#equals()
The following examples show how to use
java.security.Principal#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: V1SchemeVerifier.java From Xpatch with Apache License 2.0 | 6 votes |
public static List<X509Certificate> getCertificateChain( List<X509Certificate> certs, X509Certificate leaf) { List<X509Certificate> unusedCerts = new ArrayList<>(certs); List<X509Certificate> result = new ArrayList<>(1); result.add(leaf); unusedCerts.remove(leaf); X509Certificate root = leaf; while (!root.getSubjectDN().equals(root.getIssuerDN())) { Principal targetDn = root.getIssuerDN(); boolean issuerFound = false; for (int i = 0; i < unusedCerts.size(); i++) { X509Certificate unusedCert = unusedCerts.get(i); if (targetDn.equals(unusedCert.getSubjectDN())) { issuerFound = true; unusedCerts.remove(i); result.add(unusedCert); root = unusedCert; break; } } if (!issuerFound) { break; } } return result; }
Example 2
Source File: GenericPrincipal.java From qpid-broker-j with Apache License 2.0 | 6 votes |
public static boolean principalsEqual(final Principal p1, final Principal p2) { if (p1 == null) { return p2 == null; } else if (p2 == null) { return false; } if (p1 instanceof GenericPrincipal) { return genericPrincipalEquals((GenericPrincipal) p1, p2); } if (p2 instanceof GenericPrincipal) { return genericPrincipalEquals((GenericPrincipal) p2, p1); } return p1.equals(p2); }
Example 3
Source File: GenericX509TrustManager.java From Android-Application-ZJB with Apache License 2.0 | 6 votes |
private X509Certificate findSignedCert(X509Certificate signingCert, List<X509Certificate> certificates) { X509Certificate signed = null; Iterator iterator = certificates.iterator(); while (iterator.hasNext()) { X509Certificate cert = (X509Certificate) iterator.next(); Principal signingCertSubjectDN = signingCert.getSubjectDN(); Principal certIssuerDN = cert.getIssuerDN(); if (certIssuerDN.equals(signingCertSubjectDN) && !cert.equals(signingCert)) { signed = cert; break; } } return signed; }
Example 4
Source File: GenericX509TrustManager.java From Android-Application-ZJB with Apache License 2.0 | 6 votes |
private X509Certificate findSigner(X509Certificate signedCert, List<X509Certificate> certificates) { X509Certificate signer = null; Iterator iterator = certificates.iterator(); while (iterator.hasNext()) { X509Certificate cert = (X509Certificate) iterator.next(); Principal certSubjectDN = cert.getSubjectDN(); Principal issuerDN = signedCert.getIssuerDN(); if (certSubjectDN.equals(issuerDN)) { signer = cert; break; } } return signer; }
Example 5
Source File: CustomTrustManager.java From android-ssl with MIT License | 5 votes |
/** * A helper method for certificate re-ordering. * Finds the certificate in the list of certificates that signed the signedCert. */ private X509Certificate findSigner(X509Certificate signedCert, List<X509Certificate> certificates) { X509Certificate signer = null; for(X509Certificate cert : certificates) { Principal certSubjectDN = cert.getSubjectDN(); Principal issuerDN = signedCert.getIssuerDN(); if(certSubjectDN.equals(issuerDN)) { signer = cert; break; } } return signer; }
Example 6
Source File: XMLDSigVerifier.java From alpha-wallet-android with MIT License | 5 votes |
private X509Certificate findSignedCert(X509Certificate signingCert, List<X509Certificate> certificates) { X509Certificate signed = null; for (X509Certificate cert : certificates) { Principal signingCertSubjectDN = signingCert.getSubjectDN(); Principal certIssuerDN = cert.getIssuerDN(); if (certIssuerDN.equals(signingCertSubjectDN) && !cert.equals(signingCert)) { signed = cert; break; } } return signed; }
Example 7
Source File: XMLDSigVerifier.java From alpha-wallet-android with MIT License | 5 votes |
private X509Certificate findSignerCertificate(X509Certificate signedCert, List<X509Certificate> certificates) { X509Certificate signer = null; for (X509Certificate cert : certificates) { Principal certSubjectDN = cert.getSubjectDN(); Principal issuerDN = signedCert.getIssuerDN(); if (certSubjectDN.equals(issuerDN)) { signer = cert; break; } } return signer; }
Example 8
Source File: CustomTrustManager.java From android-ssl with MIT License | 5 votes |
/** * A helper method for certificate re-ordering. * Finds the first certificate in the list of certificates that is signed by the sigingCert. */ private X509Certificate findSignedCert(X509Certificate signingCert, List<X509Certificate> certificates) { X509Certificate signed = null; for(X509Certificate cert : certificates) { Principal signingCertSubjectDN = signingCert.getSubjectDN(); Principal certIssuerDN = cert.getIssuerDN(); if(certIssuerDN.equals(signingCertSubjectDN) && !cert.equals(signingCert)) { signed = cert; break; } } return signed; }
Example 9
Source File: CustomTrustManager.java From hello-pinnedcerts with MIT License | 5 votes |
/** * A helper method for certificate re-ordering. * Finds the certificate in the list of certificates that signed the signedCert. */ private X509Certificate findSigner(X509Certificate signedCert, List<X509Certificate> certificates) { X509Certificate signer = null; for(X509Certificate cert : certificates) { Principal certSubjectDN = cert.getSubjectDN(); Principal issuerDN = signedCert.getIssuerDN(); if(certSubjectDN.equals(issuerDN)) { signer = cert; break; } } return signer; }
Example 10
Source File: CustomTrustManager.java From hello-pinnedcerts with MIT License | 5 votes |
/** * A helper method for certificate re-ordering. * Finds the first certificate in the list of certificates that is signed by the sigingCert. */ private X509Certificate findSignedCert(X509Certificate signingCert, List<X509Certificate> certificates) { X509Certificate signed = null; for(X509Certificate cert : certificates) { Principal signingCertSubjectDN = signingCert.getSubjectDN(); Principal certIssuerDN = cert.getIssuerDN(); if(certIssuerDN.equals(signingCertSubjectDN) && !cert.equals(signingCert)) { signed = cert; break; } } return signed; }
Example 11
Source File: SignerInfo.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public ArrayList<X509Certificate> getCertificateChain(PKCS7 block) throws IOException { X509Certificate userCert; userCert = block.getCertificate(certificateSerialNumber, issuerName); if (userCert == null) return null; ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>(); certList.add(userCert); X509Certificate[] pkcsCerts = block.getCertificates(); if (pkcsCerts == null || userCert.getSubjectDN().equals(userCert.getIssuerDN())) { return certList; } Principal issuer = userCert.getIssuerDN(); int start = 0; while (true) { boolean match = false; int i = start; while (i < pkcsCerts.length) { if (issuer.equals(pkcsCerts[i].getSubjectDN())) { // next cert in chain found certList.add(pkcsCerts[i]); // if selected cert is self-signed, we're done // constructing the chain if (pkcsCerts[i].getSubjectDN().equals( pkcsCerts[i].getIssuerDN())) { start = pkcsCerts.length; } else { issuer = pkcsCerts[i].getIssuerDN(); X509Certificate tmpCert = pkcsCerts[start]; pkcsCerts[start] = pkcsCerts[i]; pkcsCerts[i] = tmpCert; start++; } match = true; break; } else { i++; } } if (!match) break; } return certList; }
Example 12
Source File: TomcatLoginCommand.java From flex-blazeds with Apache License 2.0 | 4 votes |
private boolean principalMatchesWithRequest(Principal principal, HttpServletRequest request) { return principal != null && principal.equals(request.getUserPrincipal()); }
Example 13
Source File: SignerInfo.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public ArrayList<X509Certificate> getCertificateChain(PKCS7 block) throws IOException { X509Certificate userCert; userCert = block.getCertificate(certificateSerialNumber, issuerName); if (userCert == null) return null; ArrayList<X509Certificate> certList = new ArrayList<>(); certList.add(userCert); X509Certificate[] pkcsCerts = block.getCertificates(); if (pkcsCerts == null || userCert.getSubjectDN().equals(userCert.getIssuerDN())) { return certList; } Principal issuer = userCert.getIssuerDN(); int start = 0; while (true) { boolean match = false; int i = start; while (i < pkcsCerts.length) { if (issuer.equals(pkcsCerts[i].getSubjectDN())) { // next cert in chain found certList.add(pkcsCerts[i]); // if selected cert is self-signed, we're done // constructing the chain if (pkcsCerts[i].getSubjectDN().equals( pkcsCerts[i].getIssuerDN())) { start = pkcsCerts.length; } else { issuer = pkcsCerts[i].getIssuerDN(); X509Certificate tmpCert = pkcsCerts[start]; pkcsCerts[start] = pkcsCerts[i]; pkcsCerts[i] = tmpCert; start++; } match = true; break; } else { i++; } } if (!match) break; } return certList; }
Example 14
Source File: SignerInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public ArrayList<X509Certificate> getCertificateChain(PKCS7 block) throws IOException { X509Certificate userCert; userCert = block.getCertificate(certificateSerialNumber, issuerName); if (userCert == null) return null; ArrayList<X509Certificate> certList = new ArrayList<>(); certList.add(userCert); X509Certificate[] pkcsCerts = block.getCertificates(); if (pkcsCerts == null || userCert.getSubjectDN().equals(userCert.getIssuerDN())) { return certList; } Principal issuer = userCert.getIssuerDN(); int start = 0; while (true) { boolean match = false; int i = start; while (i < pkcsCerts.length) { if (issuer.equals(pkcsCerts[i].getSubjectDN())) { // next cert in chain found certList.add(pkcsCerts[i]); // if selected cert is self-signed, we're done // constructing the chain if (pkcsCerts[i].getSubjectDN().equals( pkcsCerts[i].getIssuerDN())) { start = pkcsCerts.length; } else { issuer = pkcsCerts[i].getIssuerDN(); X509Certificate tmpCert = pkcsCerts[start]; pkcsCerts[start] = pkcsCerts[i]; pkcsCerts[i] = tmpCert; start++; } match = true; break; } else { i++; } } if (!match) break; } return certList; }
Example 15
Source File: SignerInfo.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public ArrayList<X509Certificate> getCertificateChain(PKCS7 block) throws IOException { X509Certificate userCert; userCert = block.getCertificate(certificateSerialNumber, issuerName); if (userCert == null) return null; ArrayList<X509Certificate> certList = new ArrayList<>(); certList.add(userCert); X509Certificate[] pkcsCerts = block.getCertificates(); if (pkcsCerts == null || userCert.getSubjectDN().equals(userCert.getIssuerDN())) { return certList; } Principal issuer = userCert.getIssuerDN(); int start = 0; while (true) { boolean match = false; int i = start; while (i < pkcsCerts.length) { if (issuer.equals(pkcsCerts[i].getSubjectDN())) { // next cert in chain found certList.add(pkcsCerts[i]); // if selected cert is self-signed, we're done // constructing the chain if (pkcsCerts[i].getSubjectDN().equals( pkcsCerts[i].getIssuerDN())) { start = pkcsCerts.length; } else { issuer = pkcsCerts[i].getIssuerDN(); X509Certificate tmpCert = pkcsCerts[start]; pkcsCerts[start] = pkcsCerts[i]; pkcsCerts[i] = tmpCert; start++; } match = true; break; } else { i++; } } if (!match) break; } return certList; }
Example 16
Source File: SignerInfo.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public ArrayList<X509Certificate> getCertificateChain(PKCS7 block) throws IOException { X509Certificate userCert; userCert = block.getCertificate(certificateSerialNumber, issuerName); if (userCert == null) return null; ArrayList<X509Certificate> certList = new ArrayList<>(); certList.add(userCert); X509Certificate[] pkcsCerts = block.getCertificates(); if (pkcsCerts == null || userCert.getSubjectDN().equals(userCert.getIssuerDN())) { return certList; } Principal issuer = userCert.getIssuerDN(); int start = 0; while (true) { boolean match = false; int i = start; while (i < pkcsCerts.length) { if (issuer.equals(pkcsCerts[i].getSubjectDN())) { // next cert in chain found certList.add(pkcsCerts[i]); // if selected cert is self-signed, we're done // constructing the chain if (pkcsCerts[i].getSubjectDN().equals( pkcsCerts[i].getIssuerDN())) { start = pkcsCerts.length; } else { issuer = pkcsCerts[i].getIssuerDN(); X509Certificate tmpCert = pkcsCerts[start]; pkcsCerts[start] = pkcsCerts[i]; pkcsCerts[i] = tmpCert; start++; } match = true; break; } else { i++; } } if (!match) break; } return certList; }
Example 17
Source File: NestablePrincipal.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Returns true if the passed principal is a member of the group. * This method does a recursive search, so if a principal belongs to a * group which is a member of this group, true is returned. * * @param member the principal whose membership is to be checked. * * @return true if the principal is a member of this group, * false otherwise. */ public boolean isMember(Principal member) { if( principalStack.size() == 0 ) return false; Object activePrincipal = principalStack.getFirst(); return member.equals(activePrincipal); }