@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { byte[] contents; if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) { contents = value.getBytes(); } else if (EventConstants.XML_ENCODING_BASE64.equals(encoding)) { contents = Base64.decodeBase64(value.toCharArray()); } else if (EventConstants.XML_ENCODING_MAC_ADDRESS.equals(encoding)) { contents = InetAddressUtils.macAddressStringToBytes(value); } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpOctetString"); } trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getOctetString(contents)); } }
static String determineBasicAuthentication(final Map<String, Object> parameters) { String credentials = resolveKeyedString(parameters, PARAMETER_BASIC_AUTHENTICATION, null); if (isNotBlank(credentials)) { credentials = new String(Base64.encodeBase64(credentials.getBytes())); } else { String user = resolveKeyedString(parameters, PARAMETER_USER, null); if (isBlank(user)) { credentials = null; } else { String passwd = resolveKeyedString(parameters, PARAMETER_PASSWORD, ""); credentials = new String(Base64.encodeBase64((user+":"+passwd).getBytes())); } } return credentials; }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { if (EventConstants.XML_ENCODING_BASE64.equals(encoding)) { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getOpaque(Base64.decodeBase64(value.toCharArray()))); } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpOpaque"); } } }
} else if (XML_ENCODING_BASE64.equals(encoding)) { if (value instanceof String) result = new String(Base64.encodeBase64(((String) value).getBytes())); else if (value instanceof Number) { ibuf = BigInteger.valueOf(((Number) value).longValue()).toByteArray(); result = new String(Base64.encodeBase64(ibuf)); result = new String(Base64.encodeBase64(snmpValue.getBytes()));
/** * Converts the value of a parm ('Value') of the instance to a string * * @param pvalue a {@link org.opennms.netmgt.xml.event.Value} object. * @return a {@link java.lang.String} object. */ public static String getValueAsString(Value pvalue) { if (pvalue == null) return null; if (pvalue.getContent() == null) return null; String result = ""; String encoding = pvalue.getEncoding(); if (encoding.equals(EventConstants.XML_ENCODING_TEXT)) { result = pvalue.getContent(); } else if (encoding.equals(EventConstants.XML_ENCODING_BASE64)) { byte[] bytes = Base64.decodeBase64(pvalue.getContent().toCharArray()); result = "0x"+toHexString(bytes); } else if (encoding.equals(EventConstants.XML_ENCODING_MAC_ADDRESS)) { result = pvalue.getContent(); } else { throw new IllegalStateException("Unknown encoding for parm value: " + encoding); } return result.trim(); }
String authString = new String(Base64.encodeBase64(authBytes)); conn.setRequestProperty("Authorization", "Basic " + authString);
/** * Converts the value of a parm ('Value') of the instance to a string * * @param pvalue a {@link org.opennms.netmgt.xml.event.Value} object. * @return a {@link java.lang.String} object. */ public static String getValueAsString(Value pvalue) { if (pvalue == null) return null; if (pvalue.getContent() == null) return null; String result = ""; String encoding = pvalue.getEncoding(); if (encoding.equals(EventConstants.XML_ENCODING_TEXT)) { result = pvalue.getContent(); } else if (encoding.equals(EventConstants.XML_ENCODING_BASE64)) { byte[] bytes = Base64.decodeBase64(pvalue.getContent().toCharArray()); result = "0x"+toHexString(bytes); } else if (encoding.equals(EventConstants.XML_ENCODING_MAC_ADDRESS)) { result = pvalue.getContent(); } else { throw new IllegalStateException("Unknown encoding for parm value: " + encoding); } return result.trim(); }
} else if (XML_ENCODING_BASE64.equals(encoding)) { if (value instanceof String) result = new String(Base64.encodeBase64(((String) value).getBytes())); else if (value instanceof Number) { ibuf = BigInteger.valueOf(((Number) value).longValue()).toByteArray(); result = new String(Base64.encodeBase64(ibuf)); result = new String(Base64.encodeBase64(snmpValue.getBytes()));
contents = value.getBytes(); } else if (EventConstants.XML_ENCODING_BASE64.equals(encoding)) { contents = Base64.decodeBase64(value.toCharArray()); } else if (EventConstants.XML_ENCODING_MAC_ADDRESS.equals(encoding)) { contents = InetAddressUtils.macAddressStringToBytes(value);
String authString = new String(Base64.encodeBase64(authBytes)); conn.setRequestProperty("Authorization", "Basic " + authString);
/** * Constructs a new SnmpVarBind with the specified name and value. The * value will be encoded as an SnmpOpaque. The value is assumed to have * been encoded with the specified encoding (only XML_ENCODING_BASE64 is * supported). * @param name * The name (a.k.a. "id") of the variable binding to be * created * @param encoding * Describes the way in which the value content has been * encoded (i.e. XML_ENCODING_TEXT, or XML_ENCODING_BASE64) * @param value * The variable binding value * * @return The newly-created variable binding * @exception Throws * SnmpTrapHelperException if the variable binding cannot * be created for any reason (e.g. encoding not * supported, invalid value, etc.). */ @Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapHelperException { if (EventConstants.XML_ENCODING_BASE64.equals(encoding)) { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getOpaque(Base64.decodeBase64(value.toCharArray()))); } else { throw new SnmpTrapHelperException("Encoding " + encoding + "is invalid for SnmpOpaque"); } } }