Skip to content

Commit b0e6fc4

Browse files
authored
Merge pull request #56 from auth0/add-get-user-values
Add getter for User and ProfileData extra properties
2 parents 072e005 + 83641e3 commit b0e6fc4

7 files changed

Lines changed: 158 additions & 25 deletions

File tree

src/main/java/com/auth0/json/mgmt/users/ProfileData.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.auth0.json.mgmt.users;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4-
import com.fasterxml.jackson.annotation.JsonInclude;
5-
import com.fasterxml.jackson.annotation.JsonProperty;
3+
import com.fasterxml.jackson.annotation.*;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
67

78
@SuppressWarnings({"unused", "WeakerAccess"})
89
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -25,7 +26,11 @@ public class ProfileData {
2526
private Boolean phoneVerified;
2627
@JsonProperty("family_name")
2728
private String familyName;
29+
private Map<String, Object> values;
2830

31+
public ProfileData() {
32+
values = new HashMap<>();
33+
}
2934

3035
@JsonProperty("email")
3136
public String getEmail() {
@@ -66,4 +71,14 @@ public Boolean isPhoneVerified() {
6671
public String getFamilyName() {
6772
return familyName;
6873
}
74+
75+
@JsonAnySetter
76+
void setValue(String key, Object value) {
77+
values.put(key, value);
78+
}
79+
80+
@JsonAnyGetter
81+
public Map<String, Object> getValues() {
82+
return values;
83+
}
6984
}

src/main/java/com/auth0/json/mgmt/users/User.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.*;
44

55
import java.util.Date;
6+
import java.util.HashMap;
67
import java.util.List;
78
import java.util.Map;
89

@@ -71,9 +72,15 @@ public class User {
7172
private Integer loginsCount;
7273
@JsonProperty("blocked")
7374
private Boolean blocked;
75+
private Map<String, Object> values;
76+
77+
User() {
78+
this(null);
79+
}
7480

7581
@JsonCreator
7682
public User(@JsonProperty("connection") String connection) {
83+
this.values = new HashMap<>();
7784
this.connection = connection;
7885
}
7986

@@ -509,4 +516,14 @@ Boolean willVerifyPhoneNumber() {
509516
String getConnection() {
510517
return connection;
511518
}
519+
520+
@JsonAnySetter
521+
void setValue(String key, Object value) {
522+
values.put(key, value);
523+
}
524+
525+
@JsonAnyGetter
526+
public Map<String, Object> getValues() {
527+
return values;
528+
}
512529
}

src/test/java/com/auth0/json/mgmt/users/ProfileDataTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import static org.hamcrest.MatcherAssert.assertThat;
77
import static org.hamcrest.Matchers.is;
88
import static org.hamcrest.Matchers.notNullValue;
9+
import static org.hamcrest.collection.IsMapContaining.hasEntry;
910

1011
public class ProfileDataTest extends JsonTest<ProfileData> {
1112

12-
private static final String json = "{\"email\":\"me@auth0.com\",\"email_verified\":true,\"name\":\"John\", \"username\":\"usr\", \"given_name\":\"John\", \"family_name\":\"Walker\", \"phone_number\":\"1234567890\", \"phone_verified\":true}";
13+
private static final String json = "{\"email\":\"me@auth0.com\",\"email_verified\":true,\"name\":\"John\", \"username\":\"usr\", \"given_name\":\"John\", \"family_name\":\"Walker\", \"phone_number\":\"1234567890\", \"phone_verified\":true, \"description\":\"My description\"}";
1314

1415
@Test
1516
public void shouldDeserialize() throws Exception {
@@ -24,5 +25,7 @@ public void shouldDeserialize() throws Exception {
2425
assertThat(data.getFamilyName(), is("Walker"));
2526
assertThat(data.getPhoneNumber(), is("1234567890"));
2627
assertThat(data.isPhoneVerified(), is(true));
28+
assertThat(data.getValues(), is(notNullValue()));
29+
assertThat(data.getValues(), hasEntry("description", (Object) "My description"));
2730
}
2831
}

src/test/java/com/auth0/json/mgmt/users/UserTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@
99
import static org.hamcrest.MatcherAssert.assertThat;
1010
import static org.hamcrest.Matchers.is;
1111
import static org.hamcrest.Matchers.notNullValue;
12+
import static org.hamcrest.collection.IsMapContaining.hasEntry;
1213

1314
public class UserTest extends JsonTest<User> {
1415

15-
private static final String json = "{\"connection\":\"auth0\",\"client_id\":\"client123\",\"password\":\"pwd\",\"verify_password\":true,\"username\":\"usr\",\"email\":\"me@auth0.com\",\"email_verified\":true,\"verify_email\":true,\"phone_number\":\"1234567890\",\"phone_verified\":true,\"verify_phone_number\":true,\"picture\":\"https://pic.ture/12\",\"name\":\"John\",\"nickname\":\"Johny\",\"given_name\":\"John\",\"family_name\":\"Walker\",\"app_metadata\":{},\"user_metadata\":{},\"blocked\":true}";
16+
private static final String json = "{\"connection\":\"auth0\",\"client_id\":\"client123\",\"password\":\"pwd\",\"verify_password\":true,\"username\":\"usr\",\"email\":\"me@auth0.com\",\"email_verified\":true,\"verify_email\":true,\"phone_number\":\"1234567890\",\"phone_verified\":true,\"verify_phone_number\":true,\"picture\":\"https://pic.ture/12\",\"name\":\"John\",\"nickname\":\"Johny\",\"given_name\":\"John\",\"family_name\":\"Walker\",\"app_metadata\":{},\"user_metadata\":{},\"blocked\":true,\"context\":\"extra information\"}";
1617
private static final String readOnlyJson = "{\"user_id\":\"user|123\",\"last_ip\":\"10.0.0.1\",\"last_login\":\"2016-02-23T19:57:29.532Z\",\"logins_count\":10,\"created_at\":\"2016-02-23T19:57:29.532Z\",\"updated_at\":\"2016-02-23T19:57:29.532Z\",\"identities\":[]}";
1718

19+
@Test
20+
public void shouldHaveEmptyValuesByDefault() throws Exception{
21+
User user = new User();
22+
assertThat(user.getValues(), is(notNullValue()));
23+
24+
User user2 = new User("my-connection");
25+
assertThat(user2.getConnection(), is("my-connection"));
26+
assertThat(user2.getValues(), is(notNullValue()));
27+
}
28+
1829
@Test
1930
public void shouldSerialize() throws Exception {
2031
User user = new User("auth0");
@@ -85,6 +96,8 @@ public void shouldDeserialize() throws Exception {
8596
assertThat(user.getUserMetadata(), is(notNullValue()));
8697
assertThat(user.getAppMetadata(), is(notNullValue()));
8798
assertThat(user.isBlocked(), is(true));
99+
assertThat(user.getValues(), is(notNullValue()));
100+
assertThat(user.getValues(), hasEntry("context", (Object) "extra information"));
88101
}
89102

90103
@Test

src/test/resources/mgmt/user.json

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,27 @@
99
"updated_at": "",
1010
"identities": [
1111
{
12-
"connection": "Initial-Connection",
13-
"user_id": "5457edea1b8f22891a000004",
14-
"provider": "auth0",
15-
"isSocial": false
12+
"provider": "facebook",
13+
"user_id": "5457edea1b8f2289",
14+
"connection": "facebook",
15+
"isSocial": true
16+
},
17+
{
18+
"profileData": {
19+
"name": "Auth0️",
20+
"picture": "https://pbs.twimg.com/profile_images/auth0/5457ed_normal.jpg",
21+
"created_at": "Fri May 20 17:13:23 +0000 2011",
22+
"description": "My twitter bio",
23+
"lang": "es",
24+
"location": "Palermo, Buenos Aires.",
25+
"screen_name": "auth0",
26+
"time_zone": "Buenos Aires",
27+
"utc_offset": -10800
28+
},
29+
"provider": "twitter",
30+
"user_id": "5457ed",
31+
"connection": "twitter",
32+
"isSocial": true
1633
}
1734
],
1835
"app_metadata": {},

src/test/resources/mgmt/users_list.json

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,27 @@
1010
"updated_at": "",
1111
"identities": [
1212
{
13-
"connection": "Initial-Connection",
14-
"user_id": "5457edea1b8f22891a000004",
15-
"provider": "auth0",
16-
"isSocial": false
13+
"provider": "facebook",
14+
"user_id": "5457edea1b8f2289",
15+
"connection": "facebook",
16+
"isSocial": true
17+
},
18+
{
19+
"profileData": {
20+
"name": "Auth0️",
21+
"picture": "https://pbs.twimg.com/profile_images/auth0/5457ed_normal.jpg",
22+
"created_at": "Fri May 20 17:13:23 +0000 2011",
23+
"description": "My twitter bio",
24+
"lang": "es",
25+
"location": "Palermo, Buenos Aires.",
26+
"screen_name": "auth0",
27+
"time_zone": "Buenos Aires",
28+
"utc_offset": -10800
29+
},
30+
"provider": "twitter",
31+
"user_id": "5457ed",
32+
"connection": "twitter",
33+
"isSocial": true
1734
}
1835
],
1936
"app_metadata": {},
@@ -40,10 +57,27 @@
4057
"updated_at": "",
4158
"identities": [
4259
{
43-
"connection": "Initial-Connection",
44-
"user_id": "5457edea1b8f22891a000004",
45-
"provider": "auth0",
46-
"isSocial": false
60+
"provider": "facebook",
61+
"user_id": "5457edea1b8f2289",
62+
"connection": "facebook",
63+
"isSocial": true
64+
},
65+
{
66+
"profileData": {
67+
"name": "Auth0️",
68+
"picture": "https://pbs.twimg.com/profile_images/auth0/5457ed_normal.jpg",
69+
"created_at": "Fri May 20 17:13:23 +0000 2011",
70+
"description": "My twitter bio",
71+
"lang": "es",
72+
"location": "Palermo, Buenos Aires.",
73+
"screen_name": "auth0",
74+
"time_zone": "Buenos Aires",
75+
"utc_offset": -10800
76+
},
77+
"provider": "twitter",
78+
"user_id": "5457ed",
79+
"connection": "twitter",
80+
"isSocial": true
4781
}
4882
],
4983
"app_metadata": {},

src/test/resources/mgmt/users_paged_list.json

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@
1515
"updated_at": "",
1616
"identities": [
1717
{
18-
"connection": "Initial-Connection",
19-
"user_id": "5457edea1b8f22891a000004",
20-
"provider": "auth0",
21-
"isSocial": false
18+
"provider": "facebook",
19+
"user_id": "5457edea1b8f2289",
20+
"connection": "facebook",
21+
"isSocial": true
22+
},
23+
{
24+
"profileData": {
25+
"name": "Auth0️",
26+
"picture": "https://pbs.twimg.com/profile_images/auth0/5457ed_normal.jpg",
27+
"created_at": "Fri May 20 17:13:23 +0000 2011",
28+
"description": "My twitter bio",
29+
"lang": "es",
30+
"location": "Palermo, Buenos Aires.",
31+
"screen_name": "auth0",
32+
"time_zone": "Buenos Aires",
33+
"utc_offset": -10800
34+
},
35+
"provider": "twitter",
36+
"user_id": "5457ed",
37+
"connection": "twitter",
38+
"isSocial": true
2239
}
2340
],
2441
"app_metadata": {},
@@ -45,10 +62,27 @@
4562
"updated_at": "",
4663
"identities": [
4764
{
48-
"connection": "Initial-Connection",
49-
"user_id": "5457edea1b8f22891a000004",
50-
"provider": "auth0",
51-
"isSocial": false
65+
"provider": "facebook",
66+
"user_id": "5457edea1b8f2289",
67+
"connection": "facebook",
68+
"isSocial": true
69+
},
70+
{
71+
"profileData": {
72+
"name": "Auth0️",
73+
"picture": "https://pbs.twimg.com/profile_images/auth0/5457ed_normal.jpg",
74+
"created_at": "Fri May 20 17:13:23 +0000 2011",
75+
"description": "My twitter bio",
76+
"lang": "es",
77+
"location": "Palermo, Buenos Aires.",
78+
"screen_name": "auth0",
79+
"time_zone": "Buenos Aires",
80+
"utc_offset": -10800
81+
},
82+
"provider": "twitter",
83+
"user_id": "5457ed",
84+
"connection": "twitter",
85+
"isSocial": true
5286
}
5387
],
5488
"app_metadata": {},

0 commit comments

Comments
 (0)