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.
Related
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.
I am new to JSP. Have tried a lot of things to no avail. Please help me know what can be the possible problem in this code?
Servlet Code
request.setAttribute("list", list);
request.setAttribute("rows",totalRows);
request.getRequestDispatcher("sample.jsp").forward(request, response);
Here, list is a collection of a custom datatype and totalRows holds an integer number. I am trying to set these attributes to the request so as to be able to manipulate them on my JSP, sample.jsp:
Sample.jsp
List rulesList = (List) request.getAttribute("list");
request.setAttribute("rulesList", rulesList);
String rowCount=(String)request.getAttribute("rows");
request.setAttribute("rowCount",rowCount);
I am unable to fetch the rowCount on JSP . rulesList works fine. Please help.
you need to use .toString(); like.... String rowCount=request.getAttribute("rows").toString();
and for list you can refer bellow sample code :-
List<String> result = (List) request.getAttribute("redultList");
i have thrift service with a function returning list of Object ABC:
struct ABC
{
1: string user_id;
2: string foo;
3: optional list<string> data;
}
list<ABC> getABCByUser(1:required string user_id, 2:i32 limit,3:i32 pageId, 4:string lastDocID)
throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te)
server side written by c++
I print out result returned by server side, data in ABC instance is NOT null in the response of getABCByUser.
How ever on client side which is written by java:
I set break point in the code generated by thrift on java side, data in ABC instance is null, other fields are not null.
it looks like a issue on the client side. Any idea how to fix this issue?
thanks in advance!
I encounter the same problem with you. I found that if delete the "optional" modifier before list, the return value will be right. But I don't know why we can't use "optional" before list.
If you think you may have found a bug, please open a JIRA ticket and add your reproducible test case. This makes it easier for others to have a look at it. Thank you!
I read all my likes using FQL with Spring Social Facebook
here is the method:
public List<LikeObject> startF(String token){
Facebook facebook = new FacebookTemplate(token);
FacebookProfile profile = facebook.userOperations().getUserProfile();
//System.out.println(facebook.isAuthorized());
System.out.println("Authenticcated user: "+profile.getFirstName()+" "+profile.getLastName());
PagedList<String> friendListIds = facebook.friendOperations().getFriendIds();
List<LikeObject> resultsLikes = facebook.fqlOperations().query("SELECT object_id, object_id_cursor,object_type, post_id, post_id_cursor, user_id "+
"FROM like "+
"WHERE user_id =me() ", new FqlResultMapper<LikeObject>(){
public LikeObject mapObject(FqlResult result) {
LikeObject like = new LikeObject();
like.object_id = result.getString("object_id");
like.object_id_cursor = result.getString("object_id_cursor");
like.object_type = result.getString("object_type");
like.post_id = result.getString("post_id");
like.post_id_cursor = result.getString("post_id_cursor");
like.user_id = result.getString("user_id");
return like;
}
});
return resultsLikes;
}
Here results:
LikeObject [object_id=578416.., object_id_cursor=null,
object_type=status, post_id=, post_id_cursor=null, user_id=10217..]
Then I would like to parse like.object_id and convert it to java object. But I've no idea how to do it using spring social facebook.
I've tried facebook.fetchObject(like.object_id, PostType.STATUS) . But it seems to be a wrong way.
Is there any possible way to parse an "object_id" in spring social without parsing raw JSON response from GET query?
I've tried this:
LinkPost post = facebook.fetchObject(obj_id, LinkPost.class);
I believe that obj_id has type link, I've checked it
and it cause following exception:
Exception in thread "main" org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'postType' that is to contain type id (for class org.springframework.social.facebook.api.LinkPost)
at [Source: java.io.ByteArrayInputStream#6ca79a6a; line: 1, column: 11114]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'postType' that is to contain type id (for class org.springframework.social.facebook.api.LinkPost)
at [Source: java.io.ByteArrayInputStream#6ca79a6a; line: 1, column: 11114]
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:171)
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.read(MappingJackson2HttpMessageConverter.java:163)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:94)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:491)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:460)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:228)
at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:202)
at com.repost.facebook.FbConnection.getLikedPosts(FbConnection.java:58)
at com.repost.facebook.MainClass.main(MainClass.java:15)
I'm still unclear what you mean by "parse". But let me attempt to answer this anyway...
I think you simply want to be able to fetch the object as a Post (or LinkPost) object...is that right? If so, then there's some special magic that I unfortunately had to bake into the API to be able to both grab the post type and do polymorphic deserialization into a specific type of Post (e.g., LinkPost, StatusPost, etc).
You can see the setup taking place in https://github.com/SpringSource/spring-social-facebook/blob/master/spring-social-facebook/src/main/java/org/springframework/social/facebook/api/impl/FeedTemplate.java. In the deserializePost() method, you see that I read the "type" property and copy it into a new "postType" field. One of those fields is used to populate the Post's type property and the other is used to determine which specific subclass of Post should be created. It's a hack to work around a problem I had with Jackson 1.9.x...I think that Jackson 2 will make that hack unnecessary, but I've not tried it yet.
Therefore, I see only one practical way of doing this: Don't do all the work yourself. Instead use facebook.feedOperations().getPost(objectId). It knows how to do the magic under the covers to give you a Post object. From there, if you know the specific kind of Post, you can cast it as (and if) needed to LinkPost, StatusPost, etc.
The only other option I see is to go even lower level and make the request through facebook.restOperations() and to handle the binding for yourself. That's obviously a lot more work on your part.
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".