Example usage for java.security.cert CertificateEncodingException toString

List of usage examples for java.security.cert CertificateEncodingException toString

Introduction

In this page you can find the example usage for java.security.cert CertificateEncodingException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.netscape.cmscore.usrgrp.UGSubsystem.java

/**
 * adds a user certificate to user/*from  w  w w. j av a2s  .co m*/
 */
public void addUserCert(IUser identity) throws EUsrGrpException {
    User user = (User) identity;

    if (user == null) {
        return;
    }

    X509Certificate cert[] = null;
    LDAPModificationSet addCert = new LDAPModificationSet();

    if ((cert = user.getX509Certificates()) != null) {
        LDAPAttribute attrCertStr = new LDAPAttribute(LDAP_ATTR_USER_CERT_STRING);
        LDAPAttribute attrCertBin = new LDAPAttribute(LDAP_ATTR_USER_CERT);

        try {
            attrCertBin.addValue(cert[0].getEncoded());
            attrCertStr.addValue(getCertificateString(cert[0]));
        } catch (CertificateEncodingException e) {
            log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_USRGRP_ADD_USER_CERT", e.toString()));
            throw new EUsrGrpException(CMS.getUserMessage("CMS_USRGRP_USR_CERT_ERROR"));
        }

        addCert.add(LDAPModification.ADD, attrCertStr);
        addCert.add(LDAPModification.ADD, attrCertBin);

        LDAPConnection ldapconn = null;

        try {
            ldapconn = getConn();
            ldapconn.modify("uid=" + LDAPUtil.escapeRDNValue(user.getUserID()) + "," + getUserBaseDN(),
                    addCert);
            // for audit log
            SessionContext sessionContext = SessionContext.getContext();
            String adminId = (String) sessionContext.get(SessionContext.USER_ID);

            mLogger.log(ILogger.EV_AUDIT, ILogger.S_USRGRP, AuditFormat.LEVEL, AuditFormat.ADDUSERCERTFORMAT,
                    new Object[] { adminId, user.getUserID(), cert[0].getSubjectDN().toString(),
                            cert[0].getSerialNumber().toString(16) });

        } catch (LDAPException e) {
            if (Debug.ON) {
                e.printStackTrace();
            }
            log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_USRGRP_ADD_USER", e.toString()));
            throw LDAPExceptionConverter.toPKIException(e);

        } catch (ELdapException e) {
            log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_USRGRP_ADD_USER", e.toString()));
            throw new EUsrGrpException(CMS.getUserMessage("CMS_USRGRP_USR_CERT_ERROR"));

        } finally {
            if (ldapconn != null)
                returnConn(ldapconn);
        }
    }

    return;
}