use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ClientAdminEndpointsMockMvcTests method testApprovalsAreDeleted2.
@Test
void testApprovalsAreDeleted2() throws Exception {
ClientDetails details = createClient(adminToken, new RandomValueStringGenerator().generate(), SECRET, Collections.singleton("password"));
String userToken = testClient.getUserOAuthAccessToken(details.getClientId(), "secret", testUser.getUserName(), testPassword, "oauth.approvals");
Approval[] approvals = getApprovals(details.getClientId());
assertEquals(0, approvals.length);
addApprovals(userToken, details.getClientId());
approvals = getApprovals(details.getClientId());
assertEquals(3, approvals.length);
MockHttpServletRequestBuilder deleteClientsPost = delete("/oauth/clients/" + details.getClientId()).header("Authorization", "Bearer " + adminToken).accept(APPLICATION_JSON);
ResultActions result = mockMvc.perform(deleteClientsPost);
result.andExpect(status().isOk());
ClientDetails approvalsClient = createApprovalsLoginClient(adminToken);
String loginToken = testClient.getUserOAuthAccessToken(approvalsClient.getClientId(), "secret", testUser.getUserName(), testPassword, "oauth.approvals");
approvals = getApprovals(details.getClientId());
assertEquals(0, approvals.length);
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ScimUserJsonDeserializer method deserialize.
@Override
public ScimUser deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
ScimUser user = new ScimUser();
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
String fieldName = jp.getCurrentName();
jp.nextToken();
if ("id".equalsIgnoreCase(fieldName)) {
user.setId(jp.readValueAs(String.class));
} else if ("userName".equalsIgnoreCase(fieldName)) {
user.setUserName(jp.readValueAs(String.class));
} else if ("externalId".equalsIgnoreCase(fieldName)) {
user.setExternalId(jp.readValueAs(String.class));
} else if ("meta".equalsIgnoreCase(fieldName)) {
user.setMeta(jp.readValueAs(ScimMeta.class));
} else if ("schemas".equalsIgnoreCase(fieldName)) {
user.setSchemas(jp.readValueAs(String[].class));
} else if ("userType".equalsIgnoreCase(fieldName)) {
user.setUserType(jp.readValueAs(String.class));
} else if ("title".equalsIgnoreCase(fieldName)) {
user.setTitle(jp.readValueAs(String.class));
} else if ("timezone".equalsIgnoreCase(fieldName)) {
user.setTimezone(jp.readValueAs(String.class));
} else if ("profileUrl".equalsIgnoreCase(fieldName)) {
user.setProfileUrl(jp.readValueAs(String.class));
} else if ("preferredLanguage".equalsIgnoreCase(fieldName)) {
user.setPreferredLanguage(jp.readValueAs(String.class));
} else if ("phoneNumbers".equalsIgnoreCase(fieldName)) {
ScimUser.PhoneNumber[] phoneNumbers = jp.readValueAs(ScimUser.PhoneNumber[].class);
if (phoneNumbers != null) {
user.setPhoneNumbers(Arrays.asList(phoneNumbers));
} else {
user.setPhoneNumbers(new ArrayList<>());
}
} else if ("password".equalsIgnoreCase(fieldName)) {
user.setPassword(jp.readValueAs(String.class));
} else if ("nickname".equalsIgnoreCase(fieldName)) {
user.setNickName(jp.readValueAs(String.class));
} else if ("name".equalsIgnoreCase(fieldName)) {
user.setName(jp.readValueAs(ScimUser.Name.class));
} else if ("locale".equalsIgnoreCase(fieldName)) {
user.setLocale(jp.readValueAs(String.class));
} else if ("emails".equalsIgnoreCase(fieldName)) {
user.setEmails(Arrays.asList(jp.readValueAs(ScimUser.Email[].class)));
} else if ("groups".equalsIgnoreCase(fieldName)) {
user.setGroups(Arrays.asList(jp.readValueAs(ScimUser.Group[].class)));
} else if ("displayName".equalsIgnoreCase(fieldName)) {
user.setDisplayName(jp.readValueAs(String.class));
} else if ("active".equalsIgnoreCase(fieldName)) {
user.setActive(jp.readValueAs(Boolean.class));
} else if ("verified".equalsIgnoreCase(fieldName)) {
user.setVerified(jp.readValueAs(Boolean.class));
} else if (OriginKeys.ORIGIN.equalsIgnoreCase(fieldName)) {
user.setOrigin(jp.readValueAs(String.class));
} else if ("externalId".equalsIgnoreCase(fieldName)) {
user.setExternalId(jp.readValueAs(String.class));
} else if ("zoneId".equalsIgnoreCase(fieldName)) {
user.setZoneId(jp.readValueAs(String.class));
} else if ("salt".equalsIgnoreCase(fieldName)) {
user.setSalt(jp.readValueAs(String.class));
} else if ("passwordLastModified".equalsIgnoreCase(fieldName)) {
if (jp.getValueAsString() != null) {
user.setPasswordLastModified(JsonDateDeserializer.getDate(jp.getValueAsString(), jp.getCurrentLocation()));
}
} else if ("approvals".equalsIgnoreCase(fieldName)) {
user.setApprovals(new HashSet<>(Arrays.asList(jp.readValueAs(Approval[].class))));
} else if ("lastLogonTime".equalsIgnoreCase(fieldName)) {
if (jp.getValueAsString() != null) {
user.setLastLogonTime(jp.getValueAsLong());
}
} else if ("previousLogonTime".equalsIgnoreCase(fieldName)) {
if (jp.getValueAsString() != null) {
user.setPreviousLogonTime(jp.getValueAsLong());
}
} else {
throw new UnrecognizedPropertyException("unrecognized field", jp.getCurrentLocation(), ScimUser.class, fieldName, Collections.emptySet());
}
}
}
return user;
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ApprovalsJsonDeserializer method deserialize.
@Override
public Approval deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
Approval approval = new Approval();
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
String fieldName = jp.getCurrentName();
jp.nextToken();
if ("userId".equalsIgnoreCase(fieldName)) {
approval.setUserId(jp.readValueAs(String.class));
} else if ("clientId".equalsIgnoreCase(fieldName)) {
approval.setClientId(jp.readValueAs(String.class));
} else if ("scope".equalsIgnoreCase(fieldName)) {
approval.setScope(jp.readValueAs(String.class));
} else if ("status".equalsIgnoreCase(fieldName)) {
approval.setStatus(jp.readValueAs(ApprovalStatus.class));
} else if ("expiresAt".equalsIgnoreCase(fieldName)) {
approval.setExpiresAt(jp.readValueAs(Date.class));
} else if ("lastUpdatedAt".equalsIgnoreCase(fieldName)) {
approval.setLastUpdatedAt(jp.readValueAs(Date.class));
}
}
}
return approval;
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ScimUserEndpointsTests method approvalsIsSyncedCorrectlyOnUpdate.
@Test
void approvalsIsSyncedCorrectlyOnUpdate() {
ScimUser user = new ScimUser(null, "vidya", "Vidya", "V");
user.addEmail("vidya@vmware.com");
user.setPassword("password");
user.setApprovals(Collections.singleton(new Approval().setUserId("vidya").setClientId("c1").setScope("s1").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.APPROVED)));
ScimUser created = scimUserEndpoints.createUser(user, new MockHttpServletRequest(), new MockHttpServletResponse());
final Approval approval1 = new Approval().setUserId(created.getId()).setClientId("c1").setScope("s1").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.APPROVED);
final Approval approval2 = new Approval().setUserId(created.getId()).setClientId("c1").setScope("s2").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.DENIED);
when(mockApprovalStore.getApprovalsForUser(anyString(), anyString())).thenReturn(Arrays.asList(approval1, approval2));
created.setApprovals(Collections.singleton(new Approval().setUserId("vidya").setClientId("c1").setScope("s1").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.APPROVED)));
ScimUser updated = scimUserEndpoints.updateUser(created, created.getId(), "*", new MockHttpServletRequest(), new MockHttpServletResponse(), null);
assertEquals(2, updated.getApprovals().size());
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ScimUserEndpointsTests method approvalsIsSyncedCorrectlyOnGet.
@Test
void approvalsIsSyncedCorrectlyOnGet() {
assertEquals(0, scimUserEndpoints.getUser(joel.getId(), new MockHttpServletResponse()).getApprovals().size());
final Approval approval1 = new Approval().setUserId(joel.getId()).setClientId("c1").setScope("s1").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.APPROVED);
final Approval approval2 = new Approval().setUserId(joel.getId()).setClientId("c1").setScope("s2").setExpiresAt(Approval.timeFromNow(6000)).setStatus(Approval.ApprovalStatus.DENIED);
when(mockApprovalStore.getApprovalsForUser(anyString(), anyString())).thenReturn(Arrays.asList(approval1, approval2));
assertEquals(2, scimUserEndpoints.getUser(joel.getId(), new MockHttpServletResponse()).getApprovals().size());
}
Aggregations