Skip to content

Instantly share code, notes, and snippets.

@rwheadon
Created July 26, 2016 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwheadon/d42480939c30c30cff721bb6deb018b0 to your computer and use it in GitHub Desktop.
Save rwheadon/d42480939c30c30cff721bb6deb018b0 to your computer and use it in GitHub Desktop.
Getting machine owner's email address
public static void main(String[] args) throws IOException {
for (CatalogResource machine : machines) {
example.viewDetails(machine);
List<CatalogPrincipal> owners = machine.getOwners();
for( CatalogPrincipal owner : owners ){
String ownerEmail = example.getUserEmail(owner.getRef());
System.out.println("OWNER: " + owner.getValue()
+ " (" + owner.getType()
+ ") : Username" + owner.getRef()
+ "OWNER: email is " + ownerEmail);
}
}
...
}
//Pass the machine owners getRef() value in the userName param
private String getUserEmail(String userName) {
if (!isAuthenticated()) {
throw new IllegalStateException("You must call login() first to authenticate");
}
String userEmail = "";
RestClient rcService = consumerService
.getDefaultRestClientForService("identity");
IdentityStoreClientServiceImpl iscs = new IdentityStoreClientServiceImpl(rcService);
OdataQuery orderByName = OdataQuery.query().addAscOrderBy("name");
Pageable page = PageOdataRequest.page(1, 100, orderByName);
Set<IdentityStore> identityStores = iscs.getIdentityStores(tenant, page);
for (IdentityStore item : identityStores) {
if( userEmail.equals("")){
RestClient principalService = consumerService.getDefaultRestClientForService("identity");
PrincipalService psvc = new PrincipalService(principalService);
User wkgUser = psvc.getPrincipal(tenant,userName);
userEmail=wkgUser.getEmailAddress();
}
}
return userEmail;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment