Passing session information with WebObjects - java

My team's lead developer is trying to figure out a way to pass session information in some other way than via the URL when using WebObjects.
Our site was built using web objects, but the problem we're now having is that when bloggers blog about us and post links from our site in their blog posts, the URL typically includes session information it and isn't valid for anyone other than the person who copied the link in the first place, Bloggers trying to point people to www.example-dot-com are instead blogging links such as
www.example-dot-com/cgi-bin/WebObjects/example.woa/wo/0.11.3.8
Anyone have any suggestions? Thanks!

There are a couple of issues here. Firstly, if you want to remove the session ID from the URL (which is the default), you override WOSession.setStoresIDsInCookies() to return true and WOSession.setStoresIDsInURLs() to return false.
However, your example URL doesn't have a session ID, so presumably you've figured that out. There are then a number of ways to get friendlier URLs, the easiest of which is probably to use direct actions. You could then have a URL more like www.example-dot-com/cgi-bin/WebObjects/example.woa/wa/someTarget.
Finally, Project Wonder provides full support for URL re-writing, to the extent that you could have something more like www.example-dot-com/someTarget.

Related

How to handle filtering in restlet resource

Hi i am pretty new to Restlet, and generally building web servers. I need to support filtering like this:
http://deviceip:port/resource?id=id
So far i know how to return a json message when user invokes different resources, based on my web server state. I would attach it to router, and add class which handles that resource. But how can i return only one resource from collection based on id? What i need to change in my class which is responsible from handling of that resource. Also how can i attach this resource to router? Any help is welcome, if you can write some code snippet to help me, that would be great.
Thanks
So as i understand you can approach to this in two ways. One is explained by link above and another one is using query. So basically you font have to create another resource like in the answer from link above, instead you can just extract query with this.getQuery()
and than call method getFirstValue("id"), which will return entered id.

Url with tenant id on it, alternatives to pass it as a param?

I'm trying to map an url like www.host.com/{tenant-id}/home to something like www.host.com/home.xhtml?tenantId={tenant-id} where "tenant-id" is the name of the tenant that is using the app, and could be almost anything.
After some research I found many alternatives, but none of them convinces me. I'll list the alternatives so maybe I can help anyone and get some feedback on missing alternatives at the same time.
Furthermore, my app is written in java.
Pretty Faces (or Rewrite). http://www.ocpsoft.org/prettyfaces/
Htmleasy (Resteasy) https://github.com/voodoodyne/htmleasy
A filter, handmade.
URL rewrite trough proxy (Apache / HaProxy)
I tried pretty faces and get it to work. But I'm concerned about some performance issues with high load. I don't know what PF do internally, and I'm afraid that processing every request and applying filters could be bad.
A handmade filter, would be impossible to maintain.
Does anyone have experience with Htmleasy?
Do you know any other alternative?
Thanks in advance
Cristian.
Not sure if I can get a right approach for Java. I am from a .Net background. If this were given to me, i would like to create a httpmodule that intercepts each request and then translates the uri accordingly. However, it will not be required to enable the tenant code in the uri for each request, I would suggest that you initially create a tenant context from within your app and then use it for tenant identification.
This will be far more secure and easy than handling the uri changes per request.
HTH

Access Control-j2ee

I am a beginner in the world of ACL coding.I have no prior knowledge of filters and other concepts and cannot learn that because of time constraints.So I found an alternative way to implement ACL.
I have only 3 users suppose user,admin and sys.
So I just create jsp pages starting with the respective user types and the name of the page.
eg:- "userCheckStatus.jsp" and "sysCreateUser.jsp"
And then i check whether the usertype which is stored in the session matches with the respective page the user is trying to access. I just want to know that is this a good practise and will it provide me with the thing which I am trying to achieve. If not then what is lacking in the above method and please advise me for the same.
Thanks in advance!!!
Your approach may work. One drawback is if you change your mind and you will want to give access rights to another user or introduce new role, you will have to rewrite it completely. For example you will have to find all references to that jsp and fix the links. If user bookmarked the jsp, it will be not found anymore. Some kind of indirection (mapping access to jsp in configuration file) would be better.
Standard servlet security is not so hard to try. See Oracle documentation. The good news is that servlet API has direct support for it.

Extracting url by specifying a keyword

I want to extract url of a facebook page by giving a keyword. Eg if I specify a keyword like "gulab jamun" on facebook can I get the url of that page.I tried different ways but I don't even know that is it possible. So can anyone help me for resolving this issue.I tried that using existing API's too restfb and facebook4j but I think it's not possible through that. can any one help me
I think you'll have no success with how you tried it... The RegEx should be passed where?
A solution might be to use the Search API for Pages (https://developers.facebook.com/docs/reference/api/search/#types), for example like this:
https://graph.facebook.com/search?q=gulab+jamun&type=page&access_token={YOUR_APP_ACCESS_TOKEN}
Then you can filter the results for the Page names of interest. To get the URL, you need to request the Page details per Page as follows:
https://graph.facebook.com/{PAGE_ID_FROM_RESULT}?fields=id,name,link
A one-step solution is as far as I know not possible.

Liferay: get PortletID and companyID from init()

Maybe trough PortletConfig in init(PortletConfig)
The thing is that using
((PortletConfigImpl) portletConfig).getPortletId();
is not allowed anymore because adding portal-impl.jar in package.properties gives throws an exception when trying to execute build ant target, saying that this is not allowed anymore
For companyID I directly have no idea where to start. I am using currently
long companyId = CompanyLocalServiceUtil.getCompanies().get(0).getCompanyId();
but as soon as I got more than one company it will fail
If only I could get Portlet object somehow, I think it would be enough to get both portletId and companyId
I'm not one 100% sure what you need, but if you have just one company, you can use the following code to get the company id:
PortalUtil.getDefaultCompanyId()
Adding portal-impl.jar to plugins has always been a source of problems and has never been the correct way to do. With that I'm quite happy to see that it actually seems to be actively prohibited now by the build scripts. As discussed in this question you should not do this and the portlet API does not support what you want. You strictly don't have the context necessary for knowing which company a portlet instance has been added to.
Keep in mind: There might (and typically is) only one instance of your portlet class ever, no matter if a portlet instance is placed on any page - and independent of how many portlet instances are around in the whole portal, across all companies and sites.
You should not follow this path, instead explain what you're trying to achieve with it. We might help you with that, but cannot help you learning how to implement something that is impossible, or, if you find a loophole, will be unmaintainable and randomly break with the next update because it's far outside the specification.
You can get the Portlet from PortletConfig through the portletId got from the method Portletconfig.getPortletName() and then using PortletLocalServiceUtil.getPortletById(String):
// I have not tried this but I think it should work
String portletName = Portletconfig.getPortletName();
Portlet portlet = PortletLocalServiceUtil.getPortletById(portletName);
long companyId = portlet.getCompanyId();
And then from the Portlet you can easily get the companyId.
A word of caution as stated by Olaf Kock in his answer, hence here is another answer which gives you some alternative to fetch the companyId if you know some aspect of the company. This approach does not fetch the companyId from the portlet instance for the reasons as explained by Olaf Kock.
Try this approach and see if this helps.

Categories