use of java.nio.charset.CharacterCodingException in project Payara by payara.
the class RealmBase method authenticate.
/**
* Return the Principal associated with the specified username, which
* matches the digest calculated using the given parameters using the
* method described in RFC 2069; otherwise return <code>null</code>.
*
* @param username Username of the Principal to look up
* @param clientDigest Digest which has been submitted by the client
* @param nOnce Unique (or supposedly unique) token which has been used
* for this request
* @param realm Realm name
* @param md5a2 Second MD5 digest used to calculate the digest :
* MD5(Method + ":" + uri)
*/
public Principal authenticate(String username, char[] clientDigest, String nOnce, String nc, String cnonce, String qop, String realm, char[] md5a2) {
char[] md5a1 = getDigest(username, realm);
if (md5a1 == null)
return null;
int nOnceLength = ((nOnce != null) ? nOnce.length() : 0);
int ncLength = ((nc != null) ? nc.length() : 0);
int cnonceLength = ((cnonce != null) ? cnonce.length() : 0);
int qopLength = ((qop != null) ? qop.length() : 0);
int md5a2Length = ((md5a2 != null) ? md5a2.length : 0);
// serverDigestValue = md5a1:nOnce:nc:cnonce:qop:md5a2
char[] serverDigestValue = new char[md5a1.length + 1 + nOnceLength + 1 + ncLength + 1 + cnonceLength + 1 + qopLength + 1 + md5a2Length];
System.arraycopy(md5a1, 0, serverDigestValue, 0, md5a1.length);
int ind = md5a1.length;
serverDigestValue[ind++] = ':';
if (nOnce != null) {
System.arraycopy(nOnce.toCharArray(), 0, serverDigestValue, ind, nOnceLength);
ind += nOnceLength;
}
serverDigestValue[ind++] = ':';
if (nc != null) {
System.arraycopy(nc.toCharArray(), 0, serverDigestValue, ind, ncLength);
ind += ncLength;
}
serverDigestValue[ind++] = ':';
if (cnonce != null) {
System.arraycopy(cnonce.toCharArray(), 0, serverDigestValue, ind, cnonceLength);
ind += cnonceLength;
}
serverDigestValue[ind++] = ':';
if (qop != null) {
System.arraycopy(qop.toCharArray(), 0, serverDigestValue, ind, qopLength);
ind += qopLength;
}
serverDigestValue[ind++] = ':';
if (md5a2 != null) {
System.arraycopy(md5a2, 0, serverDigestValue, ind, md5a2Length);
}
byte[] valueBytes = null;
try {
valueBytes = Utility.convertCharArrayToByteArray(serverDigestValue, getDigestEncoding());
} catch (CharacterCodingException cce) {
String msg = MessageFormat.format(rb.getString(LogFacade.ILLEGAL_DIGEST_ENCODING_EXCEPTION), getDigestEncoding());
log.log(Level.SEVERE, msg, cce);
throw new IllegalArgumentException(cce.getMessage());
}
char[] serverDigest = null;
// Bugzilla 32137
synchronized (md5Helper) {
serverDigest = md5Encoder.encode(md5Helper.digest(valueBytes));
}
if (log.isLoggable(Level.FINE)) {
String msg = "Username:" + username + " ClientSigest:" + Arrays.toString(clientDigest) + " nOnce:" + nOnce + " nc:" + nc + " cnonce:" + cnonce + " qop:" + qop + " realm:" + realm + "md5a2:" + Arrays.toString(md5a2) + " Server digest:" + String.valueOf(serverDigest);
log.log(Level.FINE, msg);
}
if (Arrays.equals(serverDigest, clientDigest)) {
return getPrincipal(username);
} else {
return null;
}
}
use of java.nio.charset.CharacterCodingException in project hive by apache.
the class TestVectorTimestampExpressions method encodeTime.
private byte[] encodeTime(Timestamp timestamp) {
ByteBuffer encoded;
long time = timestamp.getTime();
try {
String formatted = dateFormat.format(new Date(time));
encoded = Text.encode(formatted);
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
return Arrays.copyOf(encoded.array(), encoded.limit());
}
use of java.nio.charset.CharacterCodingException in project bigbluebutton by bigbluebutton.
the class BlockStreamProtocolDecoder method tryToParsePolicyRequest.
private boolean tryToParsePolicyRequest(IoSession session, IoBuffer in, ProtocolDecoderOutput out) {
byte[] message = new byte[POLICY_REQUEST.length];
if (in.remaining() >= POLICY_REQUEST.length) {
in.get(message, 0, message.length);
if (Arrays.equals(message, POLICY_REQUEST)) {
log.debug("Sending cross domain policy to the user");
IoBuffer buffer = IoBuffer.allocate(8);
buffer.setAutoExpand(true);
try {
buffer.putString("<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>", Charset.forName("UTF-8").newEncoder());
buffer.put((byte) 0);
} catch (CharacterCodingException e) {
e.printStackTrace();
return false;
}
buffer.flip();
session.write(buffer);
return true;
}
}
return false;
}
use of java.nio.charset.CharacterCodingException in project bigbluebutton by bigbluebutton.
the class BlockStreamProtocolDecoder method decodeRoom.
private String decodeRoom(IoSession session, IoBuffer in) {
int roomLength = in.get();
// System.out.println("Room length = " + roomLength);
String room = "";
try {
room = in.getString(roomLength, Charset.forName("UTF-8").newDecoder());
if (session.containsAttribute(ROOM)) {
String attRoom = (String) session.getAttribute(ROOM);
if (!attRoom.equals(room)) {
log.warn(room + " is not the same as room in attribute [" + attRoom + "]");
}
}
} catch (CharacterCodingException e) {
log.error(e.getMessage());
}
return room;
}
use of java.nio.charset.CharacterCodingException in project hive by apache.
the class VectorUDFDayOfWeekString method doGetField.
@Override
protected long doGetField(byte[] bytes, int start, int length) throws ParseException {
Date date = null;
try {
String decoded = Text.decode(bytes, start, length);
date = format.parse(decoded);
} catch (CharacterCodingException e) {
throw new ParseException(e.getMessage(), 0);
}
calendar.setTime(date);
return calendar.get(Calendar.DAY_OF_WEEK);
}
Aggregations