Java Code Examples for io.vertx.ext.auth.User#create()
The following examples show how to use
io.vertx.ext.auth.User#create() .
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: UserConverter.java From vertx-auth with Apache License 2.0 | 6 votes |
public static User decode(JsonObject json) throws IllegalArgumentException { Objects.requireNonNull(json); JsonObject principal = json.getJsonObject(FIELD_PRINCIPAL); User user = User.create(principal); // authorizations JsonObject jsonAuthorizations = json.getJsonObject(FIELD_AUTHORIZATIONS); for (String fieldName: jsonAuthorizations.fieldNames()) { JsonArray jsonAuthorizationByProvider = jsonAuthorizations.getJsonArray(fieldName); for (int i=0; i<jsonAuthorizationByProvider.size(); i++) { JsonObject jsonAuthorization = jsonAuthorizationByProvider.getJsonObject(i); user.authorizations().add(fieldName, AuthorizationConverter.decode(jsonAuthorization)); } } return user; }
Example 2
Source File: MicroProfileTest.java From vertx-auth with Apache License 2.0 | 6 votes |
@Test public void itShouldNotFailForMissingGroupsField(TestContext should) { final Async test = should.async(); User user = User.create(new JsonObject( "{\n" + " \"iss\": \"https://server.example.com\",\n" + " \"aud\": \"s6BhdRkqt3\",\n" + " \"jti\": \"a-123\",\n" + " \"exp\": 999999999999,\n" + " \"iat\": 1311280970,\n" + " \"sub\": \"24400320\"\n" + "}")); MicroProfileAuthorization.create().getAuthorizations(user, call -> { should.assertTrue(call.succeeded()); test.complete(); }); }
Example 3
Source File: MicroProfileTest.java From vertx-auth with Apache License 2.0 | 6 votes |
@Test public void itShouldBeFalseForRoleUnknown(TestContext should) { final Async test = should.async(); User user = User.create(new JsonObject( "{\n" + " \"iss\": \"https://server.example.com\",\n" + " \"aud\": \"s6BhdRkqt3\",\n" + " \"jti\": \"a-123\",\n" + " \"exp\": 999999999999,\n" + " \"iat\": 1311280970,\n" + " \"sub\": \"24400320\",\n" + " \"upn\": \"[email protected]\",\n" + " \"groups\": [\"red-group\", \"green-group\", \"admin-group\", \"admin\"]\n" + "}")); MicroProfileAuthorization.create().getAuthorizations(user, call -> { should.assertTrue(call.succeeded()); should.assertFalse(user.authorizations().getProviderIds().isEmpty()); should.assertFalse(RoleBasedAuthorization.create("unknown").match(user)); test.complete(); }); }
Example 4
Source File: OAuth2UserInfoTest.java From vertx-auth with Apache License 2.0 | 5 votes |
@Test public void getUserInfo() { final User accessToken = User.create(new JsonObject("{\"access_token\":\"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyZXNvdXJjZV9zZXRfaWQiOiJkMmZlOTg0My02NDYyLTRiZmMtYmFiYS1iNTc4N2JiNmUwZTciLCJyZXNvdXJjZV9zZXRfbmFtZSI6IkhlbGxvIFdvcmxkIFJlc291cmNlIn1dfSwianRpIjoiZDYxMDlhMDktNzhmZC00OTk4LWJmODktOTU3MzBkZmQwODkyLTE0NjQ5MDY2Nzk0MDUiLCJleHAiOjk5OTk5OTk5OTksIm5iZiI6MCwiaWF0IjoxNDY0OTA2NjcxLCJzdWIiOiJmMTg4OGY0ZC01MTcyLTQzNTktYmUwYy1hZjMzODUwNWQ4NmMiLCJ0eXAiOiJrY19ldHQiLCJhenAiOiJoZWxsby13b3JsZC1hdXRoei1zZXJ2aWNlIn0\",\"active\":true,\"scope\":\"scopeA scopeB\",\"client_id\":\"client-id\",\"username\":\"username\",\"token_type\":\"bearer\",\"expires_at\":99999999999000}")); oauth2.userInfo(accessToken, userInfo -> { if (userInfo.failed()) { fail(userInfo.cause().getMessage()); } else { testComplete(); } }); await(); }
Example 5
Source File: OAuth2UserInfoTest.java From vertx-auth with Apache License 2.0 | 5 votes |
@Test public void getUserInfoWithParams() { final User accessToken = User.create(new JsonObject("{\"access_token\":\"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyZXNvdXJjZV9zZXRfaWQiOiJkMmZlOTg0My02NDYyLTRiZmMtYmFiYS1iNTc4N2JiNmUwZTciLCJyZXNvdXJjZV9zZXRfbmFtZSI6IkhlbGxvIFdvcmxkIFJlc291cmNlIn1dfSwianRpIjoiZDYxMDlhMDktNzhmZC00OTk4LWJmODktOTU3MzBkZmQwODkyLTE0NjQ5MDY2Nzk0MDUiLCJleHAiOjk5OTk5OTk5OTksIm5iZiI6MCwiaWF0IjoxNDY0OTA2NjcxLCJzdWIiOiJmMTg4OGY0ZC01MTcyLTQzNTktYmUwYy1hZjMzODUwNWQ4NmMiLCJ0eXAiOiJrY19ldHQiLCJhenAiOiJoZWxsby13b3JsZC1hdXRoei1zZXJ2aWNlIn0\",\"active\":true,\"scope\":\"scopeA scopeB\",\"client_id\":\"client-id\",\"username\":\"username\",\"token_type\":\"bearer\",\"expires_at\":99999999999000}")); oauth2.userInfo(accessToken, userInfo -> { if (userInfo.failed()) { fail(userInfo.cause().getMessage()); } else { assertEquals(fixture, userInfo.result()); testComplete(); } }); await(); }
Example 6
Source File: JWTAuthProviderImpl.java From vertx-auth with Apache License 2.0 | 5 votes |
private User createUser(JsonObject jwtToken, String permissionsClaimKey) { User result = User.create(jwtToken); JsonArray jsonPermissions = getJsonPermissions(jwtToken, permissionsClaimKey); if (jsonPermissions != null) { for (Object item : jsonPermissions) { if (item instanceof String) { String permission = (String) item; result.authorizations().add("jwt-authentication", PermissionBasedAuthorization.create(permission)); } } } return result; }
Example 7
Source File: MicroProfileTest.java From vertx-auth with Apache License 2.0 | 5 votes |
@Test public void itShouldAssertThatTokenHasRoles(TestContext should) { final Async test = should.async(); User user = User.create(new JsonObject( "{\n" + " \"iss\": \"https://server.example.com\",\n" + " \"aud\": \"s6BhdRkqt3\",\n" + " \"jti\": \"a-123\",\n" + " \"exp\": 999999999999,\n" + " \"iat\": 1311280970,\n" + " \"sub\": \"24400320\",\n" + " \"upn\": \"[email protected]\",\n" + " \"groups\": [\"red-group\", \"green-group\", \"admin-group\", \"admin\"]\n" + "}")); // assert that the user has the following roles: final List<String> roles = Arrays.asList("red-group", "green-group", "admin-group", "admin"); MicroProfileAuthorization.create().getAuthorizations(user, call -> { should.assertTrue(call.succeeded()); for (String role : roles) { should.assertTrue(RoleBasedAuthorization.create(role).match(user)); } test.complete(); }); }