Java Code Examples for io.vertx.ext.auth.User#principal()
The following examples show how to use
io.vertx.ext.auth.User#principal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserImpl.java From vertx-auth with Apache License 2.0 | 5 votes |
@Override public int readFromBuffer(int pos, Buffer buffer) { JsonObject jsonObject = new JsonObject(); int read = jsonObject.readFromBuffer(pos, buffer); User readUser = UserConverter.decode(jsonObject); this.principal = readUser.principal(); this.authorizations = readUser.authorizations(); this.attributes = readUser.attributes(); return read; }
Example 2
Source File: MicroProfileAuthorizationImpl.java From vertx-auth with Apache License 2.0 | 5 votes |
@Override public void getAuthorizations(User user, Handler<AsyncResult<Void>> handler) { final String rootClaim = user.attributes().getString("rootClaim"); final JsonObject accessToken = rootClaim == null ? user.principal() : user.attributes().getJsonObject(rootClaim); if (accessToken == null) { handler.handle(Future.failedFuture("User doesn't contain a decoded Token")); return; } final Set<Authorization> authorizations = new HashSet<>(); // the spec MP-JWT 1.1 defines a custom grant called "groups" final JsonArray groups = accessToken.getJsonArray("groups"); // This MP-JWT custom claim is the list of group names that have been assigned to the principal of the MP-JWT. // This typically will required a mapping at the application container level to application deployment roles, // but a a one-to-one between group names and application role names is required to be performed in addition // to any other mapping. if (groups != null && groups.size() >= 0) { for (Object el : groups) { // convert to the authorization type if (el instanceof String) { authorizations.add(RoleBasedAuthorization.create((String) el)); } else { // abort the parsing handler.handle(Future.failedFuture("Cannot parse role: " + el)); return; } } } user.authorizations().add(getId(), authorizations); // return handler.handle(Future.succeededFuture()); }