NdsBeisEsb/src/main/java/com/northgateps/nds/beis/esb/beisregistration/BeisRegistrationLdapComponent.java
/**
     * Create a new LDAP user from a template copy and update it with the request data.
     */
Create a new LDAP user from a template copy and update it with the request data.
Create a new LDAP user from a template copy and update it with the request data .
@Override
    protected void doProcess(BeisRegistrationNdsRequest request, DirectoryAccessConnection directoryConnection,
            NdsSoapRequestAdapterExchangeProxy ndsExchange, DirectoryConnectionConfig directoryConnectionConfig)
                    throws NdsApplicationException, NdsBusinessException {
        BeisRegistrationDetails registrationDetails = request.getRegistrationDetails(); 
        String activationCode = request.getRegistrationDetails().getActivationCode();
        if (activationCode == null) {
            ZonedDateTime expiry = ZonedDateTime.now(ZoneOffset.UTC).plusHours(
                    Integer.parseInt(configurationManager.getString("app.registrationExpiryHours")));
            activationCode = PlatformTokenFactory.generateActivationToken(
                    request.getRegistrationDetails().getUserDetails().getUsername(), expiry);
        }
        request.getRegistrationDetails().setActivationCode(activationCode);
        String ldapAttributeUserId = configurationManager.getString("attribute.userid");
        String ldapAttributePassword = configurationManager.getString("attribute.password");
        String ldapAttributeEmail = configurationManager.getString("attribute.email");
        String ldapAttributeActivationCode = configurationManager.getString("attribute.activationCode");       
        String ldapAttributeFirstname = configurationManager.getString("attribute.forename");     
        String ldapAttributeSurname = configurationManager.getString("attribute.surname");
        String ldapAttributeStreetLineOne = configurationManager.getString("attribute.street");
        String ldapAttributeStreetLineTwo = configurationManager.getString("attribute.street2");
        String ldapAttributeTown = configurationManager.getString("attribute.town");
        String ldapAttributeCounty = configurationManager.getString("attribute.county");
        String ldapAttributeCountry = configurationManager.getString("attribute.country");
        String ldapAttributePostcode = configurationManager.getString("attribute.postalCode");
        String ldapAttributeOrganisation = configurationManager.getString("attribute.organisationName");
        String ldapAttributeHomePhone = configurationManager.getString("attribute.homePhone");
        HashMap<String, String> changes = new HashMap<String, String>();
        changes.put(ldapAttributeUserId, registrationDetails.getUserDetails().getUsername());
        changes.put(ldapAttributePassword, registrationDetails.getUserDetails().getPassword());
        changes.put(ldapAttributeEmail, registrationDetails.getUserDetails().getEmail());
        changes.put(ldapAttributeHomePhone, registrationDetails.getAccountDetails().getTelNumber());
        changes.put(ldapAttributeActivationCode, registrationDetails.getActivationCode());
        if(registrationDetails.getUserDetails().getUserType().equals(UserType.LANDLORD)){
            if (registrationDetails.getAccountDetails().getAccountType().equals(AccountType.PERSON)) {
                changes.put(ldapAttributeFirstname,
                        registrationDetails.getAccountDetails().getPersonNameDetail().getFirstname());
                changes.put(ldapAttributeSurname,
                        registrationDetails.getAccountDetails().getPersonNameDetail().getSurname());
            } else {
                changes.put(ldapAttributeOrganisation,
                        registrationDetails.getAccountDetails().getOrganisationNameDetail().getOrgName());
            }
          }else{
              changes.put(ldapAttributeOrganisation,
                      registrationDetails.getAccountDetails().getAgentNameDetails().getAgentName());
          }
        if (registrationDetails.getContactAddress() != null) {
            changes.put(ldapAttributeStreetLineOne, registrationDetails.getContactAddress().getLine().get(0));
            if (registrationDetails.getContactAddress().getLine().size() > 1) {
                changes.put(ldapAttributeStreetLineTwo, registrationDetails.getContactAddress().getLine().get(1));
            }
            changes.put(ldapAttributeTown, registrationDetails.getContactAddress().getTown());
            changes.put(ldapAttributeCounty, registrationDetails.getContactAddress().getCounty());
            changes.put(ldapAttributePostcode, registrationDetails.getContactAddress().getPostcode());
            changes.put(ldapAttributeCountry, registrationDetails.getContactAddress().getCountry());
        }
        String ldapTemplateUserDn = getTemplateUserDn(configurationManager, registrationDetails.getTenant(), null);
        String newUserDn = getUserDn(configurationManager, registrationDetails.getUserDetails().getUsername(),
                registrationDetails.getTenant());
        ndsExchange.setAnExchangeProperty(AbstractPersistenceAdapter.EVENT_USER_DN, newUserDn);
        try {
            getUserManager().createNewUser(directoryConnection, newUserDn, ldapTemplateUserDn, changes);
            ndsExchange.setAnExchangeProperty("userNameEntryCreated", registrationDetails.getUserDetails().getUsername());
            ndsExchange.setAnExchangeProperty("userTenantEntryCreated", registrationDetails.getTenant());
        } catch (DirectoryUnwillingToPerformOperationException | DirectoryPasswordConstraintViolationException e) {
            throw new NdsBusinessException(e.getMessage());
        } catch (DirectoryException e) {
            throw new NdsDirectoryException(e.getMessage(), e);
        }
    }
@ Override protected void doProcess ( BeisRegistrationNdsRequest request , DirectoryAccessConnection directoryConnection , NdsSoapRequestAdapterExchangeProxy ndsExchange , DirectoryConnectionConfig directoryConnectionConfig ) throws NdsApplicationException , NdsBusinessException { BeisRegistrationDetails registrationDetails = request . getRegistrationDetails ( ) ; String activationCode = request . getRegistrationDetails ( ) . getActivationCode ( ) ; if ( activationCode == null ) { ZonedDateTime expiry = ZonedDateTime . now ( ZoneOffset . UTC ) . plusHours ( Integer . parseInt ( configurationManager . getString ( "app.registrationExpiryHours" ) ) ) ; activationCode = PlatformTokenFactory . generateActivationToken ( request . getRegistrationDetails ( ) . getUserDetails ( ) . getUsername ( ) , expiry ) ; } request . getRegistrationDetails ( ) . setActivationCode ( activationCode ) ; String ldapAttributeUserId = configurationManager . getString ( "attribute.userid" ) ; String ldapAttributePassword = configurationManager . getString ( "attribute.password" ) ; String ldapAttributeEmail = configurationManager . getString ( "attribute.email" ) ; String ldapAttributeActivationCode = configurationManager . getString ( "attribute.activationCode" ) ; String ldapAttributeFirstname = configurationManager . getString ( "attribute.forename" ) ; String ldapAttributeSurname = configurationManager . getString ( "attribute.surname" ) ; String ldapAttributeStreetLineOne = configurationManager . getString ( "attribute.street" ) ; String ldapAttributeStreetLineTwo = configurationManager . getString ( "attribute.street2" ) ; String ldapAttributeTown = configurationManager . getString ( "attribute.town" ) ; String ldapAttributeCounty = configurationManager . getString ( "attribute.county" ) ; String ldapAttributeCountry = configurationManager . getString ( "attribute.country" ) ; String ldapAttributePostcode = configurationManager . getString ( "attribute.postalCode" ) ; String ldapAttributeOrganisation = configurationManager . getString ( "attribute.organisationName" ) ; String ldapAttributeHomePhone = configurationManager . getString ( "attribute.homePhone" ) ; HashMap < String , String > changes = new HashMap < String , String > ( ) ; changes . put ( ldapAttributeUserId , registrationDetails . getUserDetails ( ) . getUsername ( ) ) ; changes . put ( ldapAttributePassword , registrationDetails . getUserDetails ( ) . getPassword ( ) ) ; changes . put ( ldapAttributeEmail , registrationDetails . getUserDetails ( ) . getEmail ( ) ) ; changes . put ( ldapAttributeHomePhone , registrationDetails . getAccountDetails ( ) . getTelNumber ( ) ) ; changes . put ( ldapAttributeActivationCode , registrationDetails . getActivationCode ( ) ) ; if ( registrationDetails . getUserDetails ( ) . getUserType ( ) . equals ( UserType . LANDLORD ) ) { if ( registrationDetails . getAccountDetails ( ) . getAccountType ( ) . equals ( AccountType . PERSON ) ) { changes . put ( ldapAttributeFirstname , registrationDetails . getAccountDetails ( ) . getPersonNameDetail ( ) . getFirstname ( ) ) ; changes . put ( ldapAttributeSurname , registrationDetails . getAccountDetails ( ) . getPersonNameDetail ( ) . getSurname ( ) ) ; } else { changes . put ( ldapAttributeOrganisation , registrationDetails . getAccountDetails ( ) . getOrganisationNameDetail ( ) . getOrgName ( ) ) ; } } else { changes . put ( ldapAttributeOrganisation , registrationDetails . getAccountDetails ( ) . getAgentNameDetails ( ) . getAgentName ( ) ) ; } if ( registrationDetails . getContactAddress ( ) != null ) { changes . put ( ldapAttributeStreetLineOne , registrationDetails . getContactAddress ( ) . getLine ( ) . get ( 0 ) ) ; if ( registrationDetails . getContactAddress ( ) . getLine ( ) . size ( ) > 1 ) { changes . put ( ldapAttributeStreetLineTwo , registrationDetails . getContactAddress ( ) . getLine ( ) . get ( 1 ) ) ; } changes . put ( ldapAttributeTown , registrationDetails . getContactAddress ( ) . getTown ( ) ) ; changes . put ( ldapAttributeCounty , registrationDetails . getContactAddress ( ) . getCounty ( ) ) ; changes . put ( ldapAttributePostcode , registrationDetails . getContactAddress ( ) . getPostcode ( ) ) ; changes . put ( ldapAttributeCountry , registrationDetails . getContactAddress ( ) . getCountry ( ) ) ; } String ldapTemplateUserDn = getTemplateUserDn ( configurationManager , registrationDetails . getTenant ( ) , null ) ; String newUserDn = getUserDn ( configurationManager , registrationDetails . getUserDetails ( ) . getUsername ( ) , registrationDetails . getTenant ( ) ) ; ndsExchange . setAnExchangeProperty ( AbstractPersistenceAdapter . EVENT_USER_DN , newUserDn ) ; try { getUserManager ( ) . createNewUser ( directoryConnection , newUserDn , ldapTemplateUserDn , changes ) ; ndsExchange . setAnExchangeProperty ( "userNameEntryCreated" , registrationDetails . getUserDetails ( ) . getUsername ( ) ) ; ndsExchange . setAnExchangeProperty ( "userTenantEntryCreated" , registrationDetails . getTenant ( ) ) ; } catch ( DirectoryUnwillingToPerformOperationException | DirectoryPasswordConstraintViolationException e ) { throw new NdsBusinessException ( e . getMessage ( ) ) ; } catch ( DirectoryException e ) { throw new NdsDirectoryException ( e . getMessage ( ) , e ) ; } }
Create a new LDAP user from a template copy and update it with the request data.
Create a new LDAP user from a template copy and update it with the request data .
// Any attributes to be changed on the new user after copying the template user // get standard template and work out where in LDAP the user should be created // if any errors (eg. email) occur later in the route, then this data can be used to remove the entry from // directory