List of usage examples for io.vertx.core.json JsonObject getBinary
public byte[] getBinary(String key, byte[] def)
From source file:org.eclipse.hono.service.auth.AbstractHonoAuthenticationService.java
License:Open Source License
/** * The authentication request is required to contain the SASL mechanism in property {@link AuthenticationConstants#FIELD_MECHANISM} * and the client's SASL response (Base64 encoded byte array) in property {@link AuthenticationConstants#FIELD_SASL_RESPONSE}. * When the mechanism is {@linkplain AuthenticationConstants#MECHANISM_EXTERNAL EXTERNAL}, the request must also contain * the <em>subject</em> distinguished name of the verified client certificate in property {@link AuthenticationConstants#FIELD_SUBJECT_DN}. * <p>/*from w ww. j ava 2 s . c o m*/ * An example request for a client using SASL EXTERNAL wishing to act as <em>NEW_IDENTITY</em> instead of <em>ORIG_IDENTITY</em> * looks like this: * <pre> * { * "mechanism": "EXTERNAL", * "sasl-response": "TkVXX0lERU5USVRZ", // the Base64 encoded UTF-8 representation of "NEW_IDENTITY" * "subject-dn": "CN=ORIG_IDENTITY" // the subject Distinguished Name from the verified client certificate * } * </pre> */ @Override public final void authenticate(final JsonObject authRequest, final Handler<AsyncResult<HonoUser>> resultHandler) { final String mechanism = Objects.requireNonNull(authRequest) .getString(AuthenticationConstants.FIELD_MECHANISM); log.debug("received authentication request [mechanism: {}]", mechanism); if (AuthenticationConstants.MECHANISM_PLAIN.equals(mechanism)) { byte[] saslResponse = authRequest.getBinary(AuthenticationConstants.FIELD_SASL_RESPONSE, new byte[0]); try { String[] fields = readFields(saslResponse); String authzid = fields[0]; String authcid = fields[1]; String pwd = fields[2]; log.debug("processing PLAIN authentication request [authzid: {}, authcid: {}, pwd: *****]", authzid, authcid); verifyPlain(authzid, authcid, pwd, resultHandler); } catch (CredentialException e) { // response did not contain expected values resultHandler.handle(Future.failedFuture(e)); } } else if (AuthenticationConstants.MECHANISM_EXTERNAL.equals(mechanism)) { final String authzid = new String(authRequest.getBinary(AuthenticationConstants.FIELD_SASL_RESPONSE), StandardCharsets.UTF_8); final String subject = authRequest.getString(AuthenticationConstants.FIELD_SUBJECT_DN); log.debug("processing EXTERNAL authentication request [Subject DN: {}]", subject); verifyExternal(authzid, subject, resultHandler); } else { resultHandler.handle(Future.failedFuture("unsupported SASL mechanism")); } }