I created a java swing applet and inserted it in to a web page but I can't connect to the database through the web page how can I solve it? Please help.
You're facing several things here:
your applet by design can't connect to any resources except those hosted on the same host as the applet itself
your applet when run directly from a webbrowser (so not called from an http server but loading the html page it sits in from your harddisk) has no host so can't connect to anything at all
as mentioned in comments, having an applet contain account information for a database (or indeed anything) is a massive security risk
not even mentioning scalability concerns here, at your level of competence you'll not run into problems with that as not enough people will ever access your applet (no insult intended, but if you don't know this you're not going to be working for a high traffic website as they'd never have hired you)
Best thing to do is have the applet call a servlet using HTTP calls, then have the servlet do the database work and return the results to the applet, NOT the ResultSet or other JDBC entities, but turn the result into something like an XML document or CSV and send that back in the HTTP response.
The database code is below:
Class.forName("Driver Name");//example Driver Name="sun.jdbc.odbc.JdbcOdbcBridge" if your are using ODBC Driver
Connection con=DriverManager.getConnection("Connection String");
Related
Our java web application uses Alfresco as DMS. The application uses one single systemuser to connect to Alfresco. The application manages the access rights itself with some Business Logic.
Now what I'd like to accomplish, is to be able to use the MS Office URIs to do online editing of Word documents that live in Alfresco. So that's for example an URL that looks like ms-word:ofe|u|https://ourwebapp.com/documents/mydocument.docx
However if we open our documents like this, the user would end up being able to do stuff on Alfresco that we don't want them to do.
Because we want to keep our documents safe and secure, we don't want the users to be able to get the Alfresco documents "directly", but through our app. Opening Alfresco documents directly would mean that each individual user should get a unique Alfresco username/password and we don't have that and we don't want that because we already have lots and lots of documents living in Alfresco.
Surely there are other companies running into this problem? I.e. using their DMS with one single system user?
What I've already tried is to make REST endpoint. A Spring Filter ensures that an authorisation header with username/password is added and the request is forwarded to Alfresco. Then the response from Alfresco is passed back to the user. However this results in a document that's opened in read-only modus at best. Further more, it doesn't seem very secure to set up a connection with the user, using this system user credentials. For all I know, the user will be able to do stuff in Alfresco he isn't supposed to do. Like editing or even viewing other documents. A little bit like this:
There's very little documentation on how the ms-word protocol exactly works, maybe you can point me in the right direction? Or suggest some workarounds I might try out?
For this to work using sharepoint protocol (SPP) you woud have to reimplement the whole protocol server in front of your application since you control the access. There is no free or even available SPP implementation I know of you can (re)use for this.
The Alfresco protocol server may not be an option since you can't / want mirror access control from your app into alfresco. If you get access to a system like Alfresco or Sharepoint using file protocol you will get too much access rights as you already described. By following a concept of an application user you may be locked out from Alfresco concepts for end users if you can't mirror the access logic into alfresco.
Years ago we implemented a dynamic low level access voter to up- or downgrade access inside Alfresco's node service to allow specific permissions based on types and metadata. The same way someone could implement an interface to another system to delegate permission checks based on external data but this would slow down all the systems involved dramatically.
We have a similar requirement since we access documents and data from several enterprise sources including Alfresco from our own business process product having a rule and process based access concept based on cases, processes the documents are involved in- not on folders or document's static ACLs. We use a local service installed on the client partnering with the browser app for downloading, opening and saving back documents after closing the file from a local temporay (checked out) path. Our local client has no idea from Alfresco and is authenticated only against our services using JSON Web Tokens.
So my answer is more a concept not a ready to go solution in the hope to be helpful.
I am working with a small webpage using java and servlets. From my webpage I want to open a third party website without showing its login page. I mean to say authenticating it from Java and entering its home page. Can anyone help me with it?
You have to distinguish between the server (your app) and the client (the browser). Even if you (the server) would authenticate successfully, the client still wouldn't be authenticated, as you have no way to pass the authentication data to the client (cookie restrictions etc.).
So what you could do is read the HTML data of the foreign site on your server and stream it out to your client. But the performance would be miserable, you would have to rewrite every single link on the pages and most of all: you would probably violate copyright laws. Don't do it!
I don't think there is a sane solution for you, unless the author of the other site agrees on a shared authentication mechanism with you.
I a deveveloping a web site that comunicates with a custom made webserver by me in Java. The web site is made in PHP/JavaScript/JQuery running on Apache and i made a simple second webserver in Java to support some designed features by me, and this server runs under another port XXXXX. The problem is, i want to make requests in jQuery to second server the domain is diferent, the page runs on domain and the $.getJSON function calls domain:XXXXX wich is not allowed. I thought user $.getJSONP but im concerning concerned issues. The connections between two points is authed (i was think by passing a token beyond the callback generated by jquery). The two poins are supported by. Is there safe in this case use $.getJSONP or exists other alternatives thinking in browsers support(IE7+ and FF3+).
Sorry for my english :)
Best regards lealoureiro
JSONP should work for your needs, however your other option would be to have a proxy service on your second server that would make the request server side. Your client-side code could then access all the data natively via json instead of jsonp.
I want to use a Java EE application server (GlassFish 3) as SSO service for both Java applications and PHP applications. If a user gets authenticated by GlassFish he should also be logged into the PHP applications.
Is there a best practise to share the Servlet session (more precise: authentication status) with PHP?
Have a look at PHP / Java Integration. You can either integrate PHP into a servlet environment or have PHP call Java. Now I'm not 100% sure this will specifically solve your problem and the integration is deemed experimental.
What you're probably better off doing is using something else to share session data. Something like memcache. Both Java and PHP can freely talk to memcache. That will be a far more robust solution.
I have no experience with connecting PHP and a Java app server, but on integration in general:
A common way to do a single sign on is reading a session ID (e.g. a cookie set by the Java Server) in the PHP script, passing it to the app server internally (e.g. through the command line, by making a HTTP call or a shared cache instance) and getting back the authentication status.
If this is not possible, e.g. because the services are running on different domains, you would pass your app server's session ID to the PHP application the first time it gets called. The PHP app will then create a session of its own, and store the session ID from the app server in it. The internal verification of the app server's session would work as outlined above.
If you need to exchange more than just a "logged in / not logged in" flag, you could also look into replacing PHP's standard session handling using session_set_save_handler(). Your custom session function would, instead of storing the session data to a file, get its data from your app server, which can pre-fill session data with things like authentication status, user name, and so on. This would allow for some amount of easy inter-application communication as well.
Of course, first check whether the built-in Java/PHP integration functions mentioned by cletus don't already do the trick.
i dont know about best practice... but usually if it works and is not ridiculously expensive and does not compromise security, it can be an acceptable practice.
when the user visits a php page without having a php session, that php page redirect to a specific jsp page. the jsp page will see if the user has an active session. if not the jsp page will allow the user to log in. the jsp page will redirect to a specific php page, passing it things like authentication tokens and so on, as well as the url of the original page. the php page creates the php session and redirects to the original page requested. these pages could be in different domains and running on different servers. this can also be replicated and implemented across different servers running java or php or anything else.
acc.intt/page.php -> sso.intt/cosession.jsp -> acc.intt/cosession.php -> acc.intt/page.php
Does the server know the page URL of the applet without asking the applet?
There's Applet.getDocumentBase() to handle that from the applet itself but I was wondering if there was a way on the server without referring to the applet.
There isn't a simple way to get an applet page from the server even with client server communication. I tested HTTP connection and it did not set the referrer page when it connected (it may work of other machines but it looks like it cannot be relied on). Any other connection will not have any idea of web pages. Therefore the best guarantee of knowing what page the applet is used on is your current way - sending it from the applet.
I'm unsure why you would want to do this really.
If you're interested in tracking users from different pages you should probably use web logging.
If you wish to have different applet functionality according to web page then parameters are probably a better option.
If you want to ensure that someone doesn't steal your applet to use on another site it shouldn't be of concern - an applet can only connect to the same domain it was loaded from. (Someone could in theory modify the settings on their own machine to get round this though.)