本文整理了Java中java.security.Principal.toString()
方法的一些代码示例,展示了Principal.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Principal.toString()
方法的具体详情如下:
包路径:java.security.Principal
类名称:Principal
方法名:toString
[英]Returns a string containing a concise, human-readable description of this Principal.
[中]返回一个字符串,其中包含此主体的简明易读描述。
代码示例来源:origin: commonsguy/cw-omnibus
private SigModel(X509Certificate cert) {
this.subject=cert.getSubjectDN().toString();
this.issuer=cert.getIssuerDN().toString();
this.validDates=
FORMAT.format(cert.getNotBefore())+" to "+
FORMAT.format(cert.getNotAfter());
}
}
代码示例来源:origin: apache/geode
private boolean authorize(Principal principal, String permission) {
String[] principals = principal.toString().toLowerCase().split(",");
for (String role : principals) {
String permissionString = permission.replace(":", "").toLowerCase();
if (permissionString.startsWith(role))
return true;
}
return false;
}
代码示例来源:origin: Javen205/IJPay
/**
* 获取证书的CN
* @param aCert
* @return
*/
private static String getIdentitiesFromCertficate(X509Certificate aCert) {
String tDN = aCert.getSubjectDN().toString();
String tPart = "";
if ((tDN != null)) {
String tSplitStr[] = tDN.substring(tDN.indexOf("CN=")).split("@");
if (tSplitStr != null && tSplitStr.length > 2
&& tSplitStr[2] != null)
tPart = tSplitStr[2];
}
return tPart;
}
代码示例来源:origin: TakahikoKawasaki/nv-websocket-client
private static String stringifyPrincipal(SSLSocket socket)
{
try
{
return String.format(" (%s)", socket.getSession().getPeerPrincipal().toString());
}
catch (Exception e)
{
// Principal information is not available.
return "";
}
}
代码示例来源:origin: igniterealtime/Openfire
/**
* Returns true if the specified certificate is ready to be signed by a Certificate Authority. Self-signed
* certificates need to get their issuer information entered to be able to generate a Certificate
* Signing Request (CSR).
*
* @return true if the specified certificate is ready to be signed by a Certificate Authority.
*/
public static boolean isSigningRequestPending(X509Certificate certificate) {
// Verify that this is a self-signed certificate
if (!isSelfSignedCertificate(certificate)) {
return false;
}
// Verify that the issuer information has been entered
Matcher matcher = valuesPattern.matcher(certificate.getIssuerDN().toString());
return matcher.find() && matcher.find();
}
代码示例来源:origin: stackoverflow.com
public class TestClass {
public static void main(String[] args) throws Exception {
KeyStore p12 = KeyStore.getInstance("pkcs12");
p12.load(new FileInputStream("pkcs.p12"), "password".toCharArray());
Enumeration e = p12.aliases();
while (e.hasMoreElements()) {
String alias = (String) e.nextElement();
X509Certificate c = (X509Certificate) p12.getCertificate(alias);
Principal subject = c.getSubjectDN();
String subjectArray[] = subject.toString().split(",");
for (String s : subjectArray) {
String[] str = s.trim().split("=");
String key = str[0];
String value = str[1];
System.out.println(key + " - " + value);
}
}
}
}
代码示例来源:origin: apache/incubator-pinot
X509Certificate cert = (X509Certificate) certificateFactory.generateCertificate(is);
LOGGER.info("Read certificate serial number {} by issuer {} ", cert.getSerialNumber().toString(16),
cert.getIssuerDN().toString());
代码示例来源:origin: wildfly/wildfly
private void handleAuthenticationFailedEvent(SecurityAuthenticationFailedEvent event, JsonObjectBuilder objectBuilder) {
handleDefiniteOutcomeEvent(event, objectBuilder);
if (event.getPrincipal() != null && event.getPrincipal().toString() != null) {
objectBuilder.add("principal", event.getPrincipal().toString());
} else {
objectBuilder.addNull("principal");
}
}
代码示例来源:origin: wildfly/wildfly
private void handleAuthenticationFailedEvent(SecurityAuthenticationFailedEvent event, StringBuilder stringBuilder) {
handleDefiniteOutcomeEvent(event, stringBuilder);
stringBuilder.append(",principal=").append(event.getPrincipal() != null ? event.getPrincipal().toString() : null);
}
代码示例来源:origin: apache/zookeeper
/**
* Encodes the given X509Certificate as a JKS TrustStore, optionally protecting the cert with a password (though
* it's unclear why one would do this since certificates only contain public information and do not need to be
* kept secret). Returns the byte array encoding of the trust store, which may be written to a file and loaded to
* instantiate the trust store at a later point or in another process.
* @param cert the certificate to serialize.
* @param keyPassword an optional password to encrypt the trust store. If empty or null, the cert will not be encrypted.
* @return the serialized bytes of the JKS trust store.
* @throws IOException
* @throws GeneralSecurityException
*/
public static byte[] certToJavaTrustStoreBytes(
X509Certificate cert,
String keyPassword) throws IOException, GeneralSecurityException {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
char[] keyPasswordChars = keyPassword == null ? new char[0] : keyPassword.toCharArray();
trustStore.load(null, keyPasswordChars);
trustStore.setCertificateEntry(cert.getSubjectDN().toString(), cert);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
trustStore.store(outputStream, keyPasswordChars);
outputStream.flush();
byte[] result = outputStream.toByteArray();
outputStream.close();
return result;
}
代码示例来源:origin: k9mail/k-9
chainInfo.append("Subject: ").append(chain[i].getSubjectDN().toString()).append("\n");
chainInfo.append("Issuer: ").append(chain[i].getIssuerDN().toString()).append("\n");
if (sha1 != null) {
sha1.reset();
代码示例来源:origin: apache/storm
String submitterPrincipal = principal == null ? null : principal.toString();
String submitterUser = principalToLocal.toLocal(principal);
String systemUser = System.getProperty("user.name");
代码示例来源:origin: apache/zookeeper
trustStore.setCertificateEntry(rootCertificate.getSubjectDN().toString(), rootCertificate);
FileOutputStream outputStream = new FileOutputStream(truststorePath);
trustStore.store(outputStream, PASSWORD);
代码示例来源:origin: apache/storm
+ "This is a potential security hole. Please see SECURITY.MD to learn how to "
+ "configure an impersonation authorizer.",
reqContext.realPrincipal().toString(), reqContext.principal().toString(),
conf.get(DaemonConfig.NIMBUS_IMPERSONATION_AUTHORIZER));
代码示例来源:origin: psi-probe/psi-probe
attributes.put("cn", cert.getSubjectDN().toString());
attributes.put("expirationDate",
new SimpleDateFormat("yyyy-MM-dd").format(cert.getNotAfter()));
代码示例来源:origin: psi-probe/psi-probe
/**
* Adds the to store.
*
* @param certs the certs
* @param alias the alias
* @param x509Cert the x509 cert
*/
private void addToStore(List<Cert> certs, String alias, X509Certificate x509Cert) {
Cert cert = new Cert();
cert.setAlias(alias);
cert.setSubjectDistinguishedName(x509Cert.getSubjectDN().toString());
cert.setNotBefore(x509Cert.getNotBefore());
cert.setNotAfter(x509Cert.getNotAfter());
cert.setIssuerDistinguishedName(x509Cert.getIssuerDN().toString());
certs.add(cert);
}
代码示例来源:origin: apache/cloudstack
@Test
public void testCertificateConversionMethods() throws Exception {
final X509Certificate in = caCertificate;
final String pem = CertUtils.x509CertificateToPem(in);
final X509Certificate out = CertUtils.pemToX509Certificate(pem);
Assert.assertTrue(pem.startsWith("-----BEGIN CERTIFICATE-----\n"));
Assert.assertTrue(pem.endsWith("-----END CERTIFICATE-----\n"));
Assert.assertEquals(in.getSerialNumber(), out.getSerialNumber());
Assert.assertArrayEquals(in.getSignature(), out.getSignature());
Assert.assertEquals(in.getSigAlgName(), out.getSigAlgName());
Assert.assertEquals(in.getPublicKey(), out.getPublicKey());
Assert.assertEquals(in.getNotBefore(), out.getNotBefore());
Assert.assertEquals(in.getNotAfter(), out.getNotAfter());
Assert.assertEquals(in.getIssuerDN().toString(), out.getIssuerDN().toString());
}
代码示例来源:origin: monkeyWie/proxyee
/**
* 读取ssl证书使用者信息
*/
public static String getSubject(X509Certificate certificate) throws Exception {
//读出来顺序是反的需要反转下
List<String> tempList = Arrays.asList(certificate.getIssuerDN().toString().split(", "));
return IntStream.rangeClosed(0, tempList.size() - 1)
.mapToObj(i -> tempList.get(tempList.size() - i - 1)).collect(Collectors.joining(", "));
}
代码示例来源:origin: monkeyWie/proxyee
/**
* 读取ssl证书使用者信息
*/
public static String getSubject(InputStream inputStream) throws Exception {
X509Certificate certificate = loadCert(inputStream);
//读出来顺序是反的需要反转下
List<String> tempList = Arrays.asList(certificate.getIssuerDN().toString().split(", "));
return IntStream.rangeClosed(0, tempList.size() - 1)
.mapToObj(i -> tempList.get(tempList.size() - i - 1)).collect(Collectors.joining(", "));
}
代码示例来源:origin: vmware/xenon
@Override
public void handleGet(Operation get) {
try {
TestServiceResponse resp = new TestServiceResponse();
resp.principal = get.getPeerPrincipal().toString();
get.setBody(resp);
get.complete();
} catch (Exception e) {
get.fail(e);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!