protected Target createTrapTarget(Notification notification, SnmpVersion snmpVersion) throws InvalidSnmpConfigurationException {
    if (snmpVersion.isCommunityTargetRequired()) {
      OctetString community = new OctetString(getDispatchProperty(notification.DispatchProperties, COMMUNITY_PROPERTY));
      CommunityTarget communityTarget = new CommunityTarget();
      communityTarget.setCommunity(community);
      communityTarget.setVersion(snmpVersion.getTargetVersion());
      return communityTarget;
    } else {
      OctetString userName = new OctetString(getDispatchProperty(notification.DispatchProperties, SECURITY_USERNAME_PROPERTY));
      if (snmp.getUSM() == null) {
        // provide User-based Security Model (USM) with user specified
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        // authPassphraseProperty and privPassphraseProperty can be null for NoAuthNoPriv security level
        String authPassphraseProperty = notification.DispatchProperties.get(SECURITY_AUTH_PASSPHRASE_PROPERTY);
        String privPassphraseProperty = notification.DispatchProperties.get(SECURITY_PRIV_PASSPHRASE_PROPERTY);
        OctetString authPassphrase = authPassphraseProperty != null ? new OctetString(authPassphraseProperty) : null;
        OctetString privPassphrase = privPassphraseProperty != null ? new OctetString(privPassphraseProperty) : null;
        UsmUser usmUser = new UsmUser(userName, AuthMD5.ID, authPassphrase, PrivDES.ID, privPassphrase);
        usm.addUser(userName, usmUser);
        SecurityModels.getInstance().addSecurityModel(usm);
      }
      UserTarget userTarget = new UserTarget();
      userTarget.setSecurityName(userName);
      userTarget.setSecurityLevel(getSecurityLevel(notification.DispatchProperties).getSecurityLevel());
      userTarget.setSecurityModel(SecurityModel.SECURITY_MODEL_USM);
      userTarget.setVersion(snmpVersion.getTargetVersion());
      return userTarget;
    }
  }
Creates snmp target with security model corresponding to snmp version.
@param notification alerts notification
@param snmpVersion SNMP version
@return target with corresponding security model
@throws InvalidSnmpConfigurationException if notification's dispatch properties don't contain any of required properties
ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/SNMPDispatcher.java