Want to get list of all IAM users using sdk aws java. Class that we are using is AmazonIdentityManagementClient and method used is listuser(). API doc suggest pass parameter MaxItem and Marker. Whereas method do not recognize the parameter. Can anyone suggest how to do pagination here.
AmazonIdentityManagementClient amazonidentitymanagmentclient = new AmazonIdentityManagementClient();
ListUsersResult listuserresult = new ListUsersResult();
try {
listuserresult=amazonidentitymanagmentclient.listUsers();
List<User> listuser = new ArrayList<User>();
listuser = listuserresult.getUsers() //need to pass maxitems,marker here
}
} catch (Exception e) {
return null;
}
You need to use
ListUsersResult listUsers(ListUsersRequest listUsersRequest)
throws AmazonServiceException,
AmazonClientException
to use the marker feature.
You can set the marker in the ListUsersRequest . You need to get the marker from the results ( ListUsersResult ) of previous call of the listusers. The ListUsersResult has a method getMarker which can be used to get the marker to be used for next call. Then use the object ListUsesrsRequest. set the marker with the value got from getMarker and then call this listusers . Do this in a loop till the isTruncated method in the ListUsersResults indicates there are no more elements to return. If you don't set maxitem, by default it will return 100 items as per documentation. You can set that in your ListUsersRequest to a different value based on how much you want to display in a page.
Related
I have successfully followed this MS Graph Java tutorial all the way through: https://learn.microsoft.com/en-gb/graph/tutorials/java?tabs=aad
I have added my own Graph API call that returns the Groups that a given User is a member of using this code:
In App.java file
private static void makeGraphCall() {
try {
final DirectoryObjectCollectionWithReferencesPage memberof = Graph.makeGraphCall();
for (DirectoryObject group : memberof.getCurrentPage()) {
System.out.println(group.id);
}
} catch (Exception e) {
System.out.println("Error making Graph call");
System.out.println(e.getMessage());
}
}
In Graph.java file
public static DirectoryObjectCollectionWithReferencesPage makeGraphCall() throws Exception {
ensureGraphForAppOnlyAuth();
return _appClient.users("{here I enter the User ID}").memberOf()
.buildRequest()
.get();
}
I used this reference to help writing the above code: https://learn.microsoft.com/en-us/graph/api/user-list-memberof?view=graph-rest-1.0&tabs=http in particular this part:
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
DirectoryObjectCollectionWithReferencesPage memberOf = graphClient.users("{id}").memberOf()
.buildRequest()
.get();
When I run my code I get the id's of the Groups the given User is a member of which is great. However, I want to get the displayName of each Group. If I add:
System.out.println(group.displayName);
to my code in App.java, I get an error stating:
error: cannot find symbol
System.out.println(group.displayName);
^
symbol: variable displayName
location: variable group of type DirectoryObject
I understand that my call to the Graph API is made using the _appClient (as opposed to the _userClient) and I have therefore made sure that my application registered in Azure has Directory.Read.All and Directory.ReadWrite.All application permissions.
I have also tested my call to the Graph API in the Graph Explorer using the same User id i.e.
GET https://graph.microsoft.com/v1.0/users/{here i enter the User's id}/memberOf
and it returns full details of that User's Group memberships including the displayName of each Group.
I have been searching for an answer for several days now and cannot understand where I am going wrong. Please could anyone help with my understanding and tell me how (and ideally explain why) I am not able to show the displayName of each Group the User is a member of?
Thanks for your help
You are casting the results to directoryObject but directoryObject has no property displayName.
for (DirectoryObject group : memberof.getCurrentPage()) {
System.out.println(group.id);
}
Try to cast the results to group and you should be able to read displayName.
for (DirectoryObject directoryObject : memberof.getCurrentPage()) {
if ( directoryObject instanceof Group) {
Group group = (Group)directoryObject;
System.out.println(group.id);
System.out.println(group.displayName);
}
}
i try making a plugin where i need to display heads on a GUI, i found these heads on minecraft-heads in the custom heads section, but those aren't normal player's head , they're stocked in a plugin, head database, so i can't obtain them with a SkullMeta#setOwner("Player"). My question is: how can i obtain those heads ?
To know: In the website i can obtain them without the head database plugin, but the commands are like: /give #p skull 1 3 {display:{Name:"Earth"},SkullOwner:{Id:"e3ae97fb-b688-4dfd-8ee6-247790f22ecd",Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTI4OWQ1YjE3ODYyNmVhMjNkMGIwYzNkMmRmNWMwODVlODM3NTA1NmJmNjg1YjVlZDViYjQ3N2ZlODQ3MmQ5NCJ9fX0="}]}}} so i have the possibility to place a NPC with the skin, then obtain his head, or /give the item to the player then change it position but that isn't anyway optimized.
Can you help me ?
Edit: i have to access to the head URL
Edit: One of my friends found the solution using the URL, here is it:
public static void setHead(ItemMeta im, String playerSkullUrl) {
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", playerSkullUrl).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
Field profileField = null;
try {
profileField = im.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(im, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace();
}
}
That's all ^^
First, the HeadDatabase resource contains heads with skins that contain newly registered players, and therefore also created skins. There is no need to have the HeadDatabase API available, as you can easily retrieve heads with skins using the Bukkit API.
To be able to retrieve heads, you need the SkullMeta interface, which provides the necessary properties to call the correct head.
An example code how to retrieve a head using Bukkit API:
ItemMeta itemMeta = new ItemStack(Material.PLAYER_HEAD).getItemMeta();
if (itemMeta instanceof SkullMeta) {
return; // This check is not necessary, but for safe cast usually better
}
SkullMeta meta = (SkullMeta) itemMeta;
OfflinePlayer player = ...; // Get one of offline player using Bukkit#getOfflinePlayer
// Version check above 1.12+
if (Version.isCurrentHigher(Version.v1_12_R1)) {
meta.setOwningPlayer(player); // Player can be online or offline
} else {
meta.setOwner(player.getName()); // SkullMeta#setOwner is deprecated
}
If you use Paper API, you could use Player#setPlayerProfile and set the existing profile to this Player object.
If you already have an existing skin and UUID, like you mentioned the Properties you can use SessionServer from Mojang and retrieving player informations as a Json object. You could use my workaround for this, which is thread safe.
Given a query for members of a particular directory role, I would like to return a list of corresponding users. What I have is this:
IDirectoryObjectCollectionWithReferencesRequest request = graphServiceClient.directoryRoles(roleId).members().buildRequest();
IDirectoryObjectCollectionWithReferencesPage page = request.select(USER_FIELDS_TO_RETURN).get();
List<DirectoryObject> objects = page.getCurrentPage();
IDirectoryObjectCollectionWithReferencesRequestBuilder builder = page.getNextPage();
while (builder != null) {
request = builder.buildRequest();
page = request.select(USER_FIELDS_TO_RETURN).get();
objects.addAll(page.getCurrentPage());
builder = page.getNextPage();
}
return objects.stream().filter(o -> o.oDataType.equals("#microsoft.graph.user")).map(o -> new User()).collect(Collectors.toList());
The question lies in the return statement. Filter on only user objects (couldn't find a more elegant way of doing this than comparing the oDataType) and return the user object with the contents of o:
objects.stream().filter(o -> o.oDataType.equals("#microsoft.graph.user")).map(o -> {
// the only thing that I could think of is to do some weird
// serialization/deserialization logic here which is a bad solution
// for anything other than a small number of elements
}).collect(Collectors.toList());
what is the correct way of converting DirectoryObject to User
Microsoft Graph does not currently support this requirement.
If you're checking a specific directoryRole, you could come at this from the other direction. The /members endpoint does support filtering by member id:
v1.0/directoryRoles/{role-id}/members?$filter=id eq '{user-id}'
Please check the answers and workarounds provided in this thread. How to get admin roles that I am a member of, from Microsoft Graph using .Net Client SDK?
I know this is an old question, but I had the same problem and found a better solution.
You can actually convert it to a user after you have the list. So if you are iterating through the list:
var myDirectoryList = (List<DirectoryObject>)myRetrievedList;
foreach(var item in myDirectoryList)
{
var myUser = (User)item;
Console.WriteLine($"My name is {myUser.GivenName}");
}
Where DirectoryObject is Microsoft.Graph.DirectoryObject and User is Microsoft.Graph.User.
Just had the same problem, so, for anyone getting there, here is what i did (And i could not find any other simple solution...).
What you call "some weird serialization/deserialization logic" can actually be done this way using the DefaultSerializer :
private ISerializer serializer = new DefaultSerializer(new DefaultLogger());
...
objects.stream().filter(o -> o.oDataType.equals("#microsoft.graph.user")).map(o -> {
return serializer.deserializeObject(o.getRawObject().toString(), User.class)
}).collect(Collectors.toList());
I am currently working with JEST:
https://github.com/searchbox-io/Jest
Is it possible to do scan&scroll with this API?
http://www.elasticsearch.org/guide/reference/api/search/search-type/
I am currently using the Search command:
Search search = new Search("{\"size\" : "+RESULT_SIZE+", \"query\":{\"match_all\":{}}}");
but am worried about large result sets. If you use the Search command for this how do you set the "search_type=scan&scroll=10m&size=50" arguments?
Is it possible to do scan&scroll with this API?
Yes it is. My implementation it's working like this.
Start the scroll search on elastic search:
public SearchResult startScrollSearch (String type, Long size) throws IOException {
String query = ConfigurationFactory.loadElasticScript("my_es_search_script.json");
Search search = new Search.Builder(query)
// multiple index or types can be added.
.addIndex("myIndex")
.addType(type)
.setParameter(Parameters.SIZE, size)
.setParameter(Parameters.SCROLL, "1m")
.build();
SearchResult searchResult = EsClientConn.getJestClient().execute(search);
return searchResult;
}
SearchResult object will return the first (size) itens off the search as usual but will return to a scrollId parameter that is a reference to remain resultSet that elasticSearch keeps in memory for you. Parameters.SCROLL, will define the time that this search will be keeped on memory.
For read the scrollId:
scrollId = searchResult.getJsonObject().get("_scroll_id").getAsString();
For read more items from the resultSet you should use something like follow:
public JestResult readMoreFromSearch(String scrollId, Long size) throws IOException {
SearchScroll scroll = new SearchScroll.Builder(scrollId, "1m")
.setParameter(Parameters.SIZE, size).build();
JestResult searchResult = EsClientConn.getJestClient().execute(scroll);
return searchResult;
}
Don't forget that each time you read from the result set a new scrollId is returned from elastic.
Please tell me if you have any doubt.
Agreed we need to catch up however please open an issue if you need a feature.
Please check https://github.com/searchbox-io/Jest/blob/master/jest/src/test/java/io/searchbox/core/SearchScrollIntegrationTest.java at master
EDIT:
It doesn't appear that JEST currently supports the "Scan" search type: In a wicked fast turnaround, it appears that JEST now supports Scan type searches! Props to #Ferhat for the quick turnaround! JEST - SearchType.java
Have you considered just using the ElasticSearch Transport client? I could understand if you like the JEST API a little better, but as new features roll out for ElasticSearch (Exhibit A: ElasticSearch 0.90 is fantastic!), you'll get to have them as soon as they pop out instead of waiting for JEST to catch up.
My $0.02.
I set up ext direct for my Spring MVC app using extdirectspring. I am able to retrieve primitives and Strings and use them in ext.js. When I try to retrieve a list of objects, I am getting "undefined" on the javascript side. Is there anything special that I need to do to the Person class to get it to work?
I annotated the following code:
#ExtDirectMethod(ExtDirectMethodType.STORE_READ)
#Override
public Collection<Person> getPeople(String groupId) {
Group group = GroupManager.getGroup(groupId);
return group.getPeopleList();
}
This is what I am using on the client side:
directory.getPeople(id, function(result) {
console.log(result);
});
Here is what app.js looks like:
Ext.ns('Ext.app');
Ext.app.REMOTING_API = {
"actions":{
"directory":[{
"name":"getID","len":0
},{
"name":"getPeople","len":1
}
]},
"type":"remoting",
"url":"/test/action/router"
};
Have you tried using the ExtDirectStoreResponse class? It does use a collection but also manages some useful values for use in the store.
#ExtDirectMethod(ExtDirectMethodType.STORE_READ)
public ExtDirectStoreResponse<Person> load()
{
Group group = GroupManager.getGroup(groupId);
Collection<Person> people = group.getPeopleList();
return new ExtDirectStoreResponse<Person>(people.size(), people);
}
This is the approach to use when using the STORE_READ. That method annotation is expecting the request to come in matching values in the ExtDirectStoreReadRequest class. This is the reference to use when doing a store read. https://github.com/ralscha/extdirectspring/wiki/Store-Read-Method
Also, instead of calling the method directly, you would set up an ExtJs store and call
store.load();