How do I Get memberOf attribute from ldap DirContextOperations - java
I am tring to get a list of groups a user is a member of, currently I can get most attributes as follows
CustomLdapUserDetails.Essence essence = new CustomLdapUserDetails.Essence();
essence.setDn(dn);
Object passwordValue = ctx.getObjectAttribute(passwordAttributeName);
String givennameValue = (String)ctx.getObjectAttribute("givenname");
String snValue = (String)ctx.getObjectAttribute("sn");
String titleValue = (String)ctx.getObjectAttribute("title");
essence.setFirstname(givennameValue);
essence.setLastname(snValue);
but I cannot figure out how to get the memberOf attribute. If I output the whole DirContextOperations as a String I get the following
org.springframework.ldap.core.DirContextAdapter: dn=uid=emp123 {rdn=uid=emp123,
whenCreated=20110816063203.0Z,
objectCategory=CN=fompanyPerson,CN=Schema,CN=Configuration,CN={9F17F445-56C4-42D9-
B7C6-B630FFEA7F07}, badPwdCount=0, otherTelephone=123-456789, businessUnit=IREIRE BU,
ntAccount=DMN1\emp123, managerID=emp987, objectGUID=5?
?e6A??????/, mail=emp123#somewhere.com, uid=emp123, companyWorkRelationship=EMP,
memberOf[0]=CN=ABC IREIRE,OU=AutoGroups,DC=entdir,DC=gtn,DC=com,
memberOf[1]=CN=azgEntJazzUsers,OU=AutoGroups,DC=entdir,DC=gtn,DC=com, companySite=DBL,
companyCostCenter=91827, companyBusinessGroup=IREIRE BG, ntDomain=DMN1, instanceType=4,
corpID=emp123, objectSid= I???&?C?k?J???????, st=XX, badPasswordTime=0, vdejoindn=P-
ENTDIRXXX-1:uid=emp123,DC=entdirXXX,DC=gtn,DC=com, companySourceSystem=C-WORKSYSTEM,
objectClass[0]=top, objectClass[1]=person, objectClass[2]=organizationalPerson,
objectClass[3]=user, objectClass[4]=inetOrgPerson, objectClass[5]=fompanyPerson,
company=ABC DEV, name=emp123, sn=Smith, exchangeAlias=emp123, telephoneNumber=1-987-6543,
ntDomainRelative=DMN1, uSNChanged=999111, physicalDeliveryOfficeName=DXI,
ntAccountRelative=DMN1\emp123, cn=Smith, John, exchangeServer=someServer,
documentumUserName=Smith JOHN emp123, title=SOFTWARE ENGINEER/DEVELOPER,
otherCertMailbox=emp123#xyz.somewhere.com, msDS-UserAccountDisabled=TRUE,
managerName=Bloggs, Joe, givenName=John, uSNCreated=18418957, displayName=Smith, John,
pwdLastSet=629579433359695509, fompanyPersonStatus=A, whenChanged=20120266070711.0Z,
o=IREIRE BU, distinguishedName=uid=emp123,DC=entdirXXX,DC=gtn,DC=com, eDARevoke=N,
division=SEF-GL , manager=uid=emp987,DC=entdirXXX,DC=gtn,DC=com,
exchangeDirectory=SMXZG1DB, samAccountName=emp123, sametimeServer=cvxcluster}
What I need to get is the CN value of each memberOf into an array of Strings, I have tried:
ctx.getObjectAttribute("memberOf[1]"))
ctx.getObjectAttribute("memberOf"))
ctx.getObjectAttribute("memberOf=CN"))
I've seen examples online of setting but I could not find any examples of getting, is it really that much more complex then getting the other Attributes?
Any advice would be greatly appreciated
You probably only miss one "s" from the end. Try:
ctx.getObjectAttributes("memberOf")
The javadoc clarifies what's the difference between the singular and plural form method. (The former only returns the first value even if the given attribute is multi-valued.)
Are you using Active Directory as your LDAP provider?
Not all LDAP providers have a memberOF attribute on the user.
The proper method to get groups of a user would be to search groups for a filter like:
(member=<fully distinguished name of user>)
Returning attribute "CN".
Related
How to get specific data from collection? (Debugger)
I am beginner with debbuger. Can someone tell me how can i get this data: I am trying to achieve variable String which will have role name. Here is my code: SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = context.getAuthentication(); Can someone help? :<
Try authentication.getAuthorities() . Usually the way in which you can get the information you want is to simply add a get in front of the attribute name and cast the first letter to upper case.
Redisearch query with "begin with" instead of "contains"
I am trying to understand on how to perform queries in Redisearch strictly with "begins with" and I keep getting "contains". For example if I have fields with values like 'football', 'myfootball', 'greenfootball' and would provide a search term like this: > FT.SEARCH myIdx #myfield:foot* I want just to get 'football' but I keep getting other fields that contain the word instead of beginning with that word. Is there a way to avoid this? I was trying to use VERBATIM and things like #myfield:^foot* but nothing. I am using JRedisearch as a client but eventually I had to enter the DB and perform these queries manually in order to figure out what's happening. That being said, is this possible to do with this client at the moment? Thanks EDIT A sample of my index setup: Client client = new Client(INDEX_NAME, url, PORT); Schema sc = new Schema().addSortableTextField("url", 1.0); // using this field for query client.dropIndex(true); client.createIndex(sc, Client.IndexOptions.Default()); return client; Sample document: id: // random uuid urlPath: myfootbal application: web market: Europe
After checking the RDB provided I see that when searching foot* you are not getting myfootbal. The replies look like this: /dot-com/plp/football/x/index.html. You are getting those replies because this url is tokenized, and '/' is one of the tokenize chars. If you do not want those urls to be tokenized you need to declare them as TAGS and not as TEXT. This way the entire url will be indexed as is and when search for foot* it will not appear in the results. For more information about TAGS see the FT.CREATE documentation: https://oss.redislabs.com/redisearch/Commands.html
Rest assured : Illegal character in path
I am using response retrieved from one endpoint as path param in another endpoint. However, when used in URI, it throws java.net.URISyntaxException: Illegal character in path. //Post the endpoint Response resp2 = RestAssured.given(). pathParam("id", build). log().all(). when().urlEncodingEnabled(false).post("https://abc/{id}"); This is because the value of id used in uri is with double quotes like :- https://abc/"id". How can I get rid of these double quotes so as to use the value of id in uri , please advise.
First talk to the developer about this, because the nature of path param (/{id}) is to be replaced by a legitimate value (not enclosed in quotes); something like https://abc/23 or https://abc/param I would not suggest any work-around for this as this is implemented in a wrong way from REST end point definition. You might go ahead and raise a defect against this.
Taking a shot in the dark here because I feel like the issue could possibly be coming from how you're getting the string from that response. If you're pulling it from a JSON using GSON or similar: String name = myResponseJsonObject.get("member_name") System.out.Println(name); will print "John" whereas String name = myResponseJsonObject.get("member_name").getAsString() System.out.Println(name); will give you John A small detail but this has tripped me up when using GSON and others when working with JSONs in java.
Thank you John and Mohan for your time , I really appreciate it. I resolved this issue yesterday evening using Stringof function which removed the double quotes and provided me the String like value.
How to get the Chinese name of a security in blpapi?
I have a BDP function that looks like this. BDP("Glen Ln Equity","NAME_CHINESE_SIMPLIFIED") It is to update the Chinese name of a security. I have to translate it to Java blpapi but I am not sure how. Since this is a BDP function, I think I should use Reference Data Request but you can only specify the ticker and field mnemonic when creating a Reference Data Request. I also know I can use override but to use an override, based on my understanding, I will need a fieldID so that I can set that fieldID's value to be "NAME_CHINESE_SIMPLIFIED". However, I am not sure what fieldID to use. What fieldID should I use for the override? Also, where can I find a list of fieldIDs that can set for overrides?
It should work fine with a reference data request - you don't need to override anything here: Element security = request.getElement("securities"); security.appendValue("GLEN LN Equity"); Element field = request.getElement("fields"); field.appendValue("NAME_CHINESE_SIMPLIFIED ");
how to list all the indices' name of elasticsearch using java?
In my elasticsearch I want to get all the indices' name of the cluster. How can I do using java? I search the internet but there's no much useful information.
You can definitely do it with the following simple Java code: List<IndexMetaData> indices = client.admin().cluster() .prepareState().get().getState() .getMetaData().getIndices(); The list you obtain contains the details on all the indices available in your ES cluster.
You can use: client.admin().indices().prepareGetIndex().setFeatures().get().getIndices(); Use setFeatures() without parameter to just get index name. Otherwise, other data, such as MAPPINGS and SETTINGS of index, will also be returned by default.
Thanks for #Val's answer. According to your method, I use it in my projects, the code is: ClusterStateResponse response = transportClient.admin().cluster() .prepareState() .execute().actionGet(); String[] indices=response.getState().getMetaData().getConcreteAllIndices(); This method can put all the indices name into a String array. The method works. there's another method I think but not tried: ImmutableOpenMap<String, MappingMetaData> mappings = node.client().admin().cluster() .prepareState().execute().actionGet().getState().getMetaData().getIndices(). then, we can get the keys of mappings to get all the indices. Thanks again!