Example usage for javax.naming.ldap Rdn Rdn

List of usage examples for javax.naming.ldap Rdn Rdn

Introduction

In this page you can find the example usage for javax.naming.ldap Rdn Rdn.

Prototype

public Rdn(String type, Object value) throws InvalidNameException 

Source Link

Document

Constructs an Rdn from the given attribute type and value.

Usage

From source file:au.org.theark.core.service.ArkCommonServiceImpl.java

public ArkUserVO getUser(String username) throws ArkSystemException, EntityNotFoundException {
    ArkUserVO userVO = new ArkUserVO();
    try {//from  w ww  .  j  a  v  a 2s  .c  om

        LdapName ldapName = new LdapName(ldapDataContextSource.getBasePeopleDn());
        ldapName.add(new Rdn("cn", username));
        Name nameObj = (Name) ldapName;

        userVO = (ArkUserVO) ldapDataContextSource.getLdapTemplate().lookup(nameObj, new PersonContextMapper());

    } catch (InvalidNameException ne) {
        throw new ArkSystemException("A System error has occured");
    } catch (NameNotFoundException ex) {
        log.error(username + " not found in LDAP");
        throw new EntityNotFoundException();
    }

    return userVO;
}

From source file:org.easy.ldap.NamingFactory.java

public static Rdn createRdn(RdnType type, String rdnValue) {
    try {/*  www .j  av  a2  s.  c  om*/
        return new Rdn(type.toString(), rdnValue);
    } catch (InvalidNameException e) {
        throw new RuntimeException("type " + type + " rdnValue " + rdnValue, e);
    }
}

From source file:org.easy.ldap.NamingFactory.java

public static Rdn createRdn(String rdnType, String rdnValue) {
    try {// w w  w  . jav a  2s. c o  m
        return new Rdn(rdnType, rdnValue);
    } catch (InvalidNameException e) {
        throw new RuntimeException("Type " + rdnType + " rdnValue " + rdnValue, e);
    }
}

From source file:org.easy.ldap.NamingFactory.java

public Rdn createRoleRdn(String roleName) throws InvalidNameException {
    return new Rdn(environment.getProperty(PropertyNames.ROLE_RDN_TYPE), roleName);
}

From source file:org.ejbca.core.model.ra.EndEntityInformationFiller.java

/** This method merge subject DN with data from End entity profile.
 * @param subjectDN user Distinguished Name.
 * @param profile user associated profile.
 * @param email entity email.//from  w  ww . ja va 2  s  .c o m
 * @return updated DN.
 */
private static String mergeSubjectDnWithDefaultValues(String subjectDN, EndEntityProfile profile,
        String entityEmail) {
    DistinguishedName profiledn;
    DistinguishedName userdn;
    try {
        userdn = new DistinguishedName(subjectDN);
    } catch (InvalidNameException ine) {
        log.debug(subjectDN, ine);
        throw new RuntimeException(ine);
    }
    int numberofsubjectdnfields = profile.getSubjectDNFieldOrderLength();
    List<Rdn> rdnList = new ArrayList<Rdn>(numberofsubjectdnfields);
    int[] fielddata = null;
    String value;
    //Build profile's DN
    for (int i = 0; i < numberofsubjectdnfields; i++) {
        value = null;
        fielddata = profile.getSubjectDNFieldsInOrder(i);
        String parameter = DNFieldExtractor.getFieldComponent(
                DnComponents.profileIdToDnId(fielddata[EndEntityProfile.FIELDTYPE]),
                DNFieldExtractor.TYPE_SUBJECTDN);
        value = profile.getValue(fielddata[EndEntityProfile.FIELDTYPE], 0);
        if (value != null) {
            value = value.trim();
            if (!value.equals("")) {
                try {
                    parameter = StringUtils.replace(parameter, "=", "");
                    rdnList.add(fielddata[EndEntityProfile.NUMBER], new Rdn(parameter, value));
                } catch (InvalidNameException ine) {
                    log.debug("InvalidNameException while creating new Rdn with parameter " + parameter
                            + " and value " + value, ine);
                    throw new RuntimeException(ine);
                }

            }
        }
    }
    profiledn = new DistinguishedName(rdnList);

    Map<String, String> dnMap = new HashMap<String, String>();
    if (profile.getUse(DnComponents.DNEMAILADDRESS, 0)) {
        dnMap.put(DnComponents.DNEMAILADDRESS, entityEmail);
    }

    return CertTools.stringToBCDNString(profiledn.mergeDN(userdn, true, dnMap).toString());
}

From source file:org.ejbca.core.model.ra.EndEntityInformationFiller.java

/**
 * This method merge subject Alt name with data from End entity profile.
 * @param subjectAltName user subject alt name.
 * @param profile user associated profile.
 * @param email entity email field//from   w w  w.  j  a va  2 s  . c  om
 * @return updated subject alt name
 */
private static String mergeSubjectAltNameWithDefaultValues(String subjectAltName, EndEntityProfile profile,
        String entityEmail) {
    DistinguishedName profileAltName;
    DistinguishedName userAltName;
    try {
        if (subjectAltName == null) {
            subjectAltName = "";
        }
        userAltName = new DistinguishedName(subjectAltName);
    } catch (InvalidNameException ine) {
        log.debug(subjectAltName, ine);
        throw new RuntimeException(ine);
    }
    int numberofsubjectAltNamefields = profile.getSubjectAltNameFieldOrderLength();
    List<Rdn> rdnList = new ArrayList<Rdn>(numberofsubjectAltNamefields);
    int[] fielddata = null;
    String value;
    //Build profile's Alt Name
    for (int i = 0; i < numberofsubjectAltNamefields; i++) {
        value = null;
        fielddata = profile.getSubjectAltNameFieldsInOrder(i);
        String parameter = DNFieldExtractor.getFieldComponent(
                DnComponents.profileIdToDnId(fielddata[EndEntityProfile.FIELDTYPE]),
                DNFieldExtractor.TYPE_SUBJECTALTNAME);
        value = profile.getValue(fielddata[EndEntityProfile.FIELDTYPE], 0);
        if (value != null) {
            value = value.trim();
            if (!value.equals("")) {
                try {
                    parameter = StringUtils.replace(parameter, "=", "");
                    rdnList.add(fielddata[EndEntityProfile.NUMBER], new Rdn(parameter, value));
                } catch (InvalidNameException ine) {
                    log.debug("InvalidNameException while creating new Rdn with parameter " + parameter
                            + " and value " + value, ine);
                    throw new RuntimeException(ine);
                }

            }
        }
    }
    profileAltName = new DistinguishedName(rdnList);

    Map<String, String> dnMap = new HashMap<String, String>();
    if (profile.getUse(DnComponents.RFC822NAME, 0)) {
        dnMap.put(DnComponents.RFC822NAME, entityEmail);
    }

    return CertTools.stringToBCDNString(profileAltName.mergeDN(userAltName, true, dnMap).toString());
}

From source file:org.ejbca.core.model.ra.UserDataFiller.java

/** This method merge subject DN with data from End entity profile.
 * @param subjectDN user Distinguished Name.
 * @param profile user associated profile.
 * @param email entity email./*from   w w  w  . j av a  2 s.com*/
 * @return updated DN.
 */
private static String mergeSubjectDnWithDefaultValues(String subjectDN, EndEntityProfile profile,
        String entityEmail) {
    DistinguishedName profiledn;
    DistinguishedName userdn;
    try {
        userdn = new DistinguishedName(subjectDN);
    } catch (InvalidNameException ine) {
        log.debug(subjectDN, ine);
        throw new RuntimeException(ine);
    }
    int numberofsubjectdnfields = profile.getSubjectDNFieldOrderLength();
    List rdnList = new ArrayList(numberofsubjectdnfields);
    int[] fielddata = null;
    String value;
    //Build profile's DN
    for (int i = 0; i < numberofsubjectdnfields; i++) {
        value = null;
        fielddata = profile.getSubjectDNFieldsInOrder(i);
        String parameter = DNFieldExtractor.getFieldComponent(
                DnComponents.profileIdToDnId(fielddata[EndEntityProfile.FIELDTYPE]),
                DNFieldExtractor.TYPE_SUBJECTDN);
        value = profile.getValue(fielddata[EndEntityProfile.FIELDTYPE], 0);
        if (value != null) {
            value = value.trim();
            if (!value.equals("")) {
                try {
                    parameter = StringUtils.replace(parameter, "=", "");
                    rdnList.add(fielddata[EndEntityProfile.NUMBER], new Rdn(parameter, value));
                } catch (InvalidNameException ine) {
                    log.debug("InvalidNameException while creating new Rdn with parameter " + parameter
                            + " and value " + value, ine);
                    throw new RuntimeException(ine);
                }

            }
        }
    }
    profiledn = new DistinguishedName(rdnList);

    Map dnMap = new HashMap();
    if (profile.getUse(DnComponents.DNEMAIL, 0)) {
        dnMap.put(DnComponents.DNEMAIL, entityEmail);
    }
    //        return  profiledn.mergeDN(userdn, true, dnMap).toString();
    return CertTools.stringToBCDNString(profiledn.mergeDN(userdn, true, dnMap).toString());
}

From source file:org.ejbca.core.model.ra.UserDataFiller.java

/**
 * This method merge subject Alt name with data from End entity profile.
 * @param subjectAltName user subject alt name.
 * @param profile user associated profile.
 * @param email entity email field// w ww  .j a  va2s.co m
 * @return updated subject alt name
 */
private static String mergeSubjectAltNameWithDefaultValues(String subjectAltName, EndEntityProfile profile,
        String entityEmail) {
    DistinguishedName profileAltName;
    DistinguishedName userAltName;
    try {
        if (subjectAltName == null) {
            subjectAltName = "";
        }
        userAltName = new DistinguishedName(subjectAltName);
    } catch (InvalidNameException ine) {
        log.debug(subjectAltName, ine);
        throw new RuntimeException(ine);
    }
    int numberofsubjectAltNamefields = profile.getSubjectAltNameFieldOrderLength();
    List rdnList = new ArrayList(numberofsubjectAltNamefields);
    int[] fielddata = null;
    String value;
    //Build profile's Alt Name
    for (int i = 0; i < numberofsubjectAltNamefields; i++) {
        value = null;
        fielddata = profile.getSubjectAltNameFieldsInOrder(i);
        String parameter = DNFieldExtractor.getFieldComponent(
                DnComponents.profileIdToDnId(fielddata[EndEntityProfile.FIELDTYPE]),
                DNFieldExtractor.TYPE_SUBJECTALTNAME);
        value = profile.getValue(fielddata[EndEntityProfile.FIELDTYPE], 0);
        if (value != null) {
            value = value.trim();
            if (!value.equals("")) {
                try {
                    parameter = StringUtils.replace(parameter, "=", "");
                    rdnList.add(fielddata[EndEntityProfile.NUMBER], new Rdn(parameter, value));
                } catch (InvalidNameException ine) {
                    log.debug("InvalidNameException while creating new Rdn with parameter " + parameter
                            + " and value " + value, ine);
                    throw new RuntimeException(ine);
                }

            }
        }
    }
    profileAltName = new DistinguishedName(rdnList);

    Map dnMap = new HashMap();
    if (profile.getUse(DnComponents.RFC822NAME, 0)) {
        dnMap.put(DnComponents.RFC822NAME, entityEmail);
    }
    //        return  profileAltName.mergeDN(userAltName, true, dnMap).toString();
    return CertTools.stringToBCDNString(profileAltName.mergeDN(userAltName, true, dnMap).toString());
}