use of com.sun.messaging.jmq.util.BASE64Encoder in project openmq by eclipse-ee4j.
the class BasicAuthenticationHandler method handleRequest.
@Override
public byte[] handleRequest(byte[] authRequest, int sequence) throws LoginException {
if (username == null || password == null) {
throw new LoginException("null");
}
try {
byte[] response;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeUTF(username);
BASE64Encoder encoder = new BASE64Encoder();
String encodepass = encoder.encode(password.getBytes("UTF8"));
dos.writeUTF(encodepass);
dos.flush();
response = bos.toByteArray();
dos.close();
return response;
} catch (IOException e) {
throw new LoginException("IOException: " + e.getMessage());
}
}
use of com.sun.messaging.jmq.util.BASE64Encoder in project openmq by eclipse-ee4j.
the class JSONWebSocket method doSend.
@Override
protected void doSend(StompFrameMessage frame) throws Exception {
JsonBuilderFactory jsonfactory = Json.createBuilderFactory(null);
JsonObjectBuilder obuilder = jsonfactory.createObjectBuilder();
JsonObjectBuilder hbuilder = jsonfactory.createObjectBuilder();
JsonObjectBuilder bbuilder = jsonfactory.createObjectBuilder();
obuilder = obuilder.add(JsonMessage.Key.COMMAND, frame.getCommand().toString());
Iterator<Map.Entry<String, String>> itr = frame.getHeaders().entrySet().iterator();
Map.Entry<String, String> pair;
String key, val;
while (itr.hasNext()) {
pair = itr.next();
key = pair.getKey();
val = pair.getValue();
hbuilder.add(key, val);
}
obuilder.add(JsonMessage.Key.HEADERS, hbuilder.build());
if (frame.getCommand().equals(StompFrameMessage.Command.MESSAGE)) {
if (frame.isTextMessage()) {
String body = frame.getBodyText();
bbuilder.add(JsonMessage.BodySubKey.TYPE, JsonMessage.BODY_TYPE_TEXT);
if (body != null) {
bbuilder.add(JsonMessage.BodySubKey.TEXT, body);
} else {
bbuilder.add(JsonMessage.BodySubKey.TEXT, "");
}
} else {
byte[] body = frame.getBody();
bbuilder.add(JsonMessage.BodySubKey.TYPE, JsonMessage.BODY_TYPE_BYTES);
bbuilder.add(JsonMessage.BodySubKey.ENCODER, JsonMessage.ENCODER_BASE64);
String textbody = "";
if (body != null) {
if (base64Class == null) {
BASE64Encoder encoder = new BASE64Encoder();
textbody = encoder.encode(body);
} else {
Method gm = base64Class.getMethod("getEncoder", (new Class[] {}));
Object o = gm.invoke(null);
Method em = o.getClass().getMethod("encodeToString", (new Class[] { byte[].class }));
textbody = (String) em.invoke(o, body);
}
}
bbuilder.add(JsonMessage.BodySubKey.TEXT, textbody);
}
} else {
byte[] body = frame.getBody();
bbuilder.add(JsonMessage.BodySubKey.TYPE, JsonMessage.BODY_TYPE_TEXT);
if (body != null) {
bbuilder.add(JsonMessage.BodySubKey.TEXT, new String(body, "UTF-8"));
} else {
bbuilder.add(JsonMessage.BodySubKey.TEXT, "");
}
}
JsonObject jo = obuilder.add(JsonMessage.Key.BODY, bbuilder.build()).build();
send(jo.toString());
if (DEBUG) {
logger.log(logger.INFO, toString() + " SENT JsonObject[" + jo + "]");
}
}
use of com.sun.messaging.jmq.util.BASE64Encoder in project openmq by eclipse-ee4j.
the class JMQAdminKeyAuthenticationHandler method handleRequest.
@Override
public byte[] handleRequest(byte[] authRequest, int sequence) throws LoginException {
if (username == null || password == null) {
String errorString = AdministeredObject.cr.getKString(AdministeredObject.cr.X_NO_USERNAME_PASSWORD);
throw new LoginException(errorString);
}
try {
byte[] response;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeUTF(username);
BASE64Encoder encoder = new BASE64Encoder();
String encodepass = encoder.encode(password.getBytes("UTF8"));
dos.writeUTF(encodepass);
dos.flush();
response = bos.toByteArray();
dos.close();
return response;
} catch (IOException e) {
throw new LoginException("IOException: " + e.getMessage());
}
}
Aggregations