<div dir="ltr">Oh,Thanks for your detailed answers,I think I know how to resolve my problem.<div><br></div><div> Thanks again!</div><div><br></div><div>Best Regards!</div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-12-05 0:19 GMT+08:00 Alexander Wels <span dir="ltr"><<a href="mailto:awels@redhat.com" target="_blank">awels@redhat.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thursday, December 04, 2014 10:57:43 AM 王成俊 wrote:<br>
> I'm sorry I did not explain my needs clearly.<br>
><br>
> In my case,I want to redesign the WebAdmin login GUI and add some<br>
> javascript in my WebAdmin login page to do many own logic.At present I<br>
> don't know how to add javascript in gwt framework,so I have to make a<br>
> servlet to alternative the original WebAdmin login GUI.<br>
><br>
> After admin user log in the WebAdmin Portal through my servlet,UIPlugin<br>
> which use restapi to get data in the portal cannot automate get the<br>
> user's certificate,the uiplugin show me a prompt to input the username and<br>
> password.<br>
><br>
<br>
</span>Okay so if I understand correctly there are 2 parts to your issue.<br>
<br>
1. You want an alternate login screen for which you wrote your own servlet<br>
that displays your login screen.<br>
2. You have a UI plugin that needs the rest api credentials to make calls to<br>
the REST api.<br>
<br>
- For 1, A consequence of what you are describing to me, is that you will need<br>
to compile and package ovirt with your custom extension yourself. Which may<br>
potentially break if we ever make changes to the code. I highly suggest you<br>
keep an eye out for the SSO capability we are working on in 3.6. But for now I<br>
guess you can do the following, which can and probably will break with each<br>
version of ovirt.<br>
<br>
The source code for the login window in webadmin is in:<br>
rontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/login/presenter<br>
and view. You can alter it whatever way you want to do your custom stuff.<br>
However this requires you to know GWT.<br>
<br>
If you want to do the servlet approach:<br>
look in<br>
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/server/gwt/GenericApiGWTServiceImpl.java<br>
at the login and logOff methods. Do something similar to that in your servlet<br>
when you submit the form from your servlet. After you login, you can redirect<br>
the browser to the webadmin URL, at that point it should recognize you are<br>
logged in and show the webadmin while bypassing the original login screen.<br>
This will work if you servlet lives in the same context as the webadmin<br>
servlet.<br>
<br>
Again, both of these approached will probably work, but depend on internal<br>
code which can and will change over time, so you will have to maintain your<br>
code to match. When the SSO capability is fully rolled out you should be able<br>
to write your own login screen that doesn't depend on internal structures<br>
which will make maintaining that much easier for you. I believe this is<br>
scheduled for the 3.6 timeframe.<br>
<br>
- For 2, in your UI plugin, you need to hook into the RestApiSessionAcquired<br>
event. Its use is described here [1]. You can pass the session id in that<br>
event as a header to your request to the REST api and that makes the requests<br>
succeed. Examples of code that do that are available in the sample UI plugins<br>
on that page.<br>
<br>
Alexander<br>
<br>
[1] <a href="http://www.ovirt.org/Features/UIPlugins#REST_API_integration" target="_blank">http://www.ovirt.org/Features/UIPlugins#REST_API_integration</a><br>
<div class="HOEnZb"><div class="h5"><br>
> I am looking forward to your guide!<br>
><br>
> Thanks!<br>
><br>
> Best regards!<br>
><br>
> 2014-12-03 1:04 GMT+08:00 Vojtech Szocs <<a href="mailto:vszocs@redhat.com">vszocs@redhat.com</a>>:<br>
> > ----- Original Message -----<br>
> ><br>
> > > From: "Alexander Wels" <<a href="mailto:awels@redhat.com">awels@redhat.com</a>><br>
> > > To: "王成俊" <<a href="mailto:wcj2007@gmail.com">wcj2007@gmail.com</a>><br>
> > > Cc: <a href="mailto:devel@ovirt.org">devel@ovirt.org</a><br>
> > > Sent: Tuesday, December 2, 2014 1:59:21 PM<br>
> > > Subject: Re: [ovirt-devel] How To Auto Set oVirt RESTApi Session?<br>
> > ><br>
> > > On Tuesday, December 02, 2014 09:45:49 AM 王成俊 wrote:<br>
> > > > Hi,awels:<br>
> > > > Thanks for your reply!<br>
> > > ><br>
> > > > I make this servlet to run the backend action which<br>
> > > ><br>
> > > > names "LoginAdminUser", because I want to check admin log in with<br>
> > > > it,so<br>
> > > > that my engine no need to log in through engine's loginpopupview.<br>
> ><br>
> > Hm, so you're trying to automate WebAdmin GUI login? Can you please<br>
> > explain your use case without any technical (servlet etc.) details?<br>
> ><br>
> > > > But when I log in through my servlet,the restapi can not get the<br>
> > > ><br>
> > > > user's certificate.<br>
> > > ><br>
> > > > Can you tell me how to set and resume the restapi session in my<br>
> ><br>
> > case?<br>
> ><br>
> > > > Thanks!<br>
> > > ><br>
> > > > Best Regards!<br>
> > ><br>
> > > You can login to the REST api using standard http connection techniques.<br>
> ><br>
> > For<br>
> ><br>
> > > instance basic auth you can login doing the following:<br>
> > ><br>
> > > http://<user>%40<domain>:<password>@<engine_host>/ovirt-engine/api<br>
> > ><br>
> > > Will list the available REST api.<br>
> > ><br>
> > > But I am still not clear on what you are trying to do. Are you trying to<br>
> > > write<br>
> > > your own external servlet, that calls the REST api to do things for you?<br>
> ><br>
> > Or<br>
> ><br>
> > > are you trying to write a servlet that lives inside the context of the<br>
> ><br>
> > engine<br>
> ><br>
> > > and implements a new action?<br>
> > ><br>
> > > Also please reply all, so we can keep the discussion on the mailing list<br>
> ><br>
> > so<br>
> ><br>
> > > other people can find it in the future.<br>
> > ><br>
> > > Alexander<br>
> > ><br>
> > > > 2014-12-02 5:42 GMT+08:00 Alexander Wels <<a href="mailto:awels@redhat.com">awels@redhat.com</a>>:<br>
> > > > > On Monday, December 01, 2014 04:56:04 PM 王成俊 wrote:<br>
> > > > > > Dear Sir:<br>
> > > > > ><br>
> > > > > > I am a new one in studing ovirt engine.Now,I have a<br>
> ><br>
> > Servlet in<br>
> ><br>
> > > > > > org.ovirt.engine.ui.frontend.server.gwt package.<br>
> > > > > ><br>
> > > > > > I want to call<br>
> ><br>
> > *Frontend.getInstance().getLoginHandler().**onLoginSuccess(userName,<br>
> ><br>
> > > > > > password, domain)* to set session for restapi in this servlet.<br>
> > > > > ><br>
> > > > > > But when I visit this servlet,it occur to show me an<br>
> > > > > > error<br>
> > > > > > which<br>
> > > > > ><br>
> > > > > > just like "*JBWEB000071: root cause<br>
> ><br>
> > java.lang.ClassNotFoundException:<br>
> > > > > > org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback from<br>
> ><br>
> > [Module<br>
> ><br>
> > > > > > &quot;deployment.engine.ear.webadmin.war:main&quot; from Service<br>
> ><br>
> > Module<br>
> ><br>
> > > > > > Loader]*". I found that this error is occured by calling*<br>
> > > > > > Frontend.getInstance()*.<br>
> > > > > ><br>
> > > > > > Can you tell me how to resolve this problem or a new way<br>
> ><br>
> > to<br>
> ><br>
> > > > > > set<br>
> > > > > ><br>
> > > > > > and resume restapi session in a servlet package of<br>
> > > > > > org.ovirt.engine.ui.front.server.gwt like the<br>
> ><br>
> > RestApiSessionManager in<br>
> ><br>
> > > > > > org.ovirt.engine.ui.webadmin.plugin.restapi package?<br>
> > > > > ><br>
> > > > > > thanks!<br>
> > > > > ><br>
> > > > > > Best Regards!<br>
> > > > ><br>
> > > > > Hi,<br>
> > > > ><br>
> > > > > The problem you are experiencing is the fact the<br>
> ><br>
> > Frontend.getInstance()<br>
> ><br>
> > > > > is<br>
> > > > > a<br>
> > > > > frontend (client, which get compiled to javascript) class, and the<br>
> > > > > servlet<br>
> > > > > is<br>
> > > > > on the server side where this class is not defined (as it is<br>
> > > > > frontend<br>
> > > > > only).<br>
> > > > > Maybe if you could explain what you are trying to do we could assist<br>
> > > > > better.<br>
> > > > ><br>
> > > > > We have a mechanism of getting the REST api session on the front end<br>
> ><br>
> > when<br>
> ><br>
> > > > > you<br>
> > > > > log in. On the backend you don't really need that, since you are on<br>
> ><br>
> > the<br>
> ><br>
> > > > > backend. So your question sort of confuses me at this point.<br>
> > > > ><br>
> > > > > Alexander<br>
> > ><br>
> > > _______________________________________________<br>
> > > Devel mailing list<br>
> > > <a href="mailto:Devel@ovirt.org">Devel@ovirt.org</a><br>
> > > <a href="http://lists.ovirt.org/mailman/listinfo/devel" target="_blank">http://lists.ovirt.org/mailman/listinfo/devel</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><strong><font color="#009900">用心体会,生活本来有滋有味!</font></strong></div>
</div>