use of com.microsoft.graph.http.GraphServiceException in project msgraph-sdk-java-core by microsoftgraph.
the class BatchResponseContentTest method doesNotIncludeVerboseInformation.
@Test
public void doesNotIncludeVerboseInformation() {
String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}";
ISerializer serializer = new DefaultSerializer(new DefaultLogger() {
{
setLoggingLevel(LoggerLevel.ERROR);
}
});
BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class);
if (batchresponse != null) {
if (// this is done by the batch request in the fluent API
batchresponse.responses != null)
for (final BatchResponseStep<?> step : batchresponse.responses) {
step.serializer = serializer;
}
try {
batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class);
} catch (GraphServiceException ex) {
final GraphErrorResponse response = ex.getError();
assertNotNull(response);
assertNotNull(response.error);
assertNotNull(response.error.message);
assertEquals(ex.getMessage(false), ex.getMessage());
}
} else
fail("batch response was null");
}
use of com.microsoft.graph.http.GraphServiceException in project msgraph-sdk-java-core by microsoftgraph.
the class BatchResponseContentTest method includeVerboseInformation.
@Test
public void includeVerboseInformation() {
String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}";
ISerializer serializer = new DefaultSerializer(new DefaultLogger() {
{
setLoggingLevel(LoggerLevel.DEBUG);
}
});
BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class);
if (batchresponse != null) {
if (// this is done by the batch request in the fluent API
batchresponse.responses != null)
for (final BatchResponseStep<?> step : batchresponse.responses) {
step.serializer = serializer;
}
try {
batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class);
} catch (GraphServiceException ex) {
final GraphErrorResponse response = ex.getError();
assertNotNull(response);
assertNotNull(response.error);
assertNotNull(response.error.message);
assertEquals(ex.getMessage(true), ex.getMessage());
}
} else
fail("batch response was null");
}
use of com.microsoft.graph.http.GraphServiceException in project opencga by opencb.
the class AzureADAuthenticationManager method getUsersFromRemoteGroup.
@Override
public List<User> getUsersFromRemoteGroup(String groupId) throws CatalogException {
IDirectoryObjectCollectionWithReferencesPage membersPage;
try {
membersPage = graphServiceClient.groups(groupId).members().buildRequest().get();
} catch (GraphServiceException e) {
logger.error("Group '{}' not found.", groupId);
throw new CatalogException("Group '" + groupId + "' not found");
} catch (ClientException e) {
logger.error("Graph query could not be performed: {}", e.getMessage());
throw e;
}
List<com.microsoft.graph.models.extensions.User> graphUserList = new ArrayList<>();
ObjectMapper jsonObjectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
boolean moreElems = true;
while (membersPage.getCurrentPage() != null && moreElems) {
for (DirectoryObject directoryObject : membersPage.getCurrentPage()) {
com.microsoft.graph.models.extensions.User graphUser;
if ("#microsoft.graph.user".equals(directoryObject.oDataType)) {
try {
graphUser = jsonObjectMapper.readValue(String.valueOf(directoryObject.getRawObject()), com.microsoft.graph.models.extensions.User.class);
graphUserList.add(graphUser);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (membersPage.getNextPage() != null) {
membersPage = membersPage.getNextPage().buildRequest().get();
} else {
moreElems = false;
}
}
return extractUserInformation(graphUserList);
}
use of com.microsoft.graph.http.GraphServiceException in project azure-ad-plugin by jenkinsci.
the class AzureSecurityRealm method createSecurityComponents.
@Override
public SecurityComponents createSecurityComponents() {
return new SecurityComponents((AuthenticationManager) authentication -> {
if (authentication instanceof AzureAuthenticationToken) {
return authentication;
}
throw new BadCredentialsException("Unexpected authentication type: " + authentication);
}, username -> {
if (username == null) {
throw new UserMayOrMayNotExistException2("Can't find a user with no username");
}
if (isDisableGraphIntegration()) {
throw new UserMayOrMayNotExistException2("Can't lookup a user if graph integration is disabled");
}
AzureAdUser azureAdUser = caches.get(username, (cacheKey) -> {
GraphServiceClient<Request> azureClient = getAzureClient();
String userId = ObjId2FullSidMap.extractObjectId(username);
if (userId == null) {
userId = username;
}
// as we look up by object id we don't know if it's a user or a group :(
try {
com.microsoft.graph.models.User activeDirectoryUser = azureClient.users(userId).buildRequest().get();
if (activeDirectoryUser != null & activeDirectoryUser.id == null) {
// known to happen when subject is a group with display name only and starts with a #
return null;
}
AzureAdUser user = requireNonNull(AzureAdUser.createFromActiveDirectoryUser(activeDirectoryUser));
List<AzureAdGroup> groups = AzureCachePool.get(azureClient).getBelongingGroupsByOid(user.getObjectID());
user.setAuthorities(groups);
return user;
} catch (GraphServiceException e) {
if (e.getResponseCode() == NOT_FOUND) {
return null;
} else if (e.getResponseCode() == BAD_REQUEST) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Failed to lookup user with userid '" + userId, e);
} else {
LOGGER.log(Level.WARNING, "Failed to lookup user with userid '" + userId + "'." + " Enable 'Fine' Logging for more information.");
}
return null;
}
throw e;
}
});
if (azureAdUser == null) {
throw new UsernameNotFoundException("Cannot find user: " + username);
}
return azureAdUser;
});
}
use of com.microsoft.graph.http.GraphServiceException in project msgraph-sdk-java-core by microsoftgraph.
the class BatchResponseContentTest method deserializesErrorsProperly.
@Test
public void deserializesErrorsProperly() {
String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}";
ISerializer serializer = new DefaultSerializer(mock(ILogger.class));
BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class);
if (batchresponse != null) {
if (// this is done by the batch request in the fluent API
batchresponse.responses != null)
for (final BatchResponseStep<?> step : batchresponse.responses) {
step.serializer = serializer;
}
assertThrows(GraphServiceException.class, () -> {
batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class);
});
try {
batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class);
} catch (GraphServiceException ex) {
final GraphErrorResponse response = ex.getError();
assertNotNull(response);
assertNotNull(response.error);
assertNotNull(response.error.message);
}
} else
fail("batch response was null");
}
Aggregations