how do i check for errors in spring - security? - spring

I have an application that supports multiple types of login using username+password, using open id, etc.
Technology used : GWT.
Login url = Login.html and Login Failure url = Login.html?error=true
as shown above, the login page (made in GWT) can determine that whether its just opened for first time or whether its opened after an error.
However, i am not able to determine the type of error
a similar post here: Post link shows how to set the message to a custom one,
But i require a programming approach:
eg if open id login fails, I must show user a panel to enter his name, etc.
Is there any way to achieve this ?
For those not knowing GWT:
Let me change the problem a bit, suppose that my login page is not a JSP but a servlet, how do i write code in my servlet that is able to access the type of error occured during login? (Actually this does not solve the GWT issue, but it may give me a 'heads up' of what is needed to be done.)

Well you don't have to redirect your failed login to a jsp - it can be any URI. For instance you can redirect them to the URI http:/www.myserver.com/failed which is a completely different servlet (could be a servlet that does nothing but sends a redirect to a new URL even).

Related

How do I Create a Custom Connector in Microsoft Flow with the correct request URL?

I am attempting to create a custom connector for the Clio API (https://app.clio.com/api/v4/documentation). I was able to successfully authenticate and access the API in Postman, testing out quite a few different types of requests with good results.
Then I exported the collection to a Postman file and imported it into a new custom connector in my MS Flow account as instructed at https://learn.microsoft.com/en-us/connectors/custom-connectors/define-postman-collection. As part of that process, I entered the following settings:
Scheme: HTTPS
host: app.clio.com
Base URL: /
Within the custom connector requests, all the definitions looked acceptable, except that instead of having the fully qualified request URL, they did not include https://app.clio.com.
For example, one request should use the following address:
https://app.clio.com/api/v4/contacts.json
The field in MS Flow, where URL should be entered, is grayed out and only includes /api/v4/contacts.json and looks like this:
The grayed out field cannot be typed in. Instead, I have clicked "Import from sample," which leads to a window where I can type in the fully qualified URL. After I do that and click the "import" button, the window still lists the partial URL as shown above.
At first I thought that was intentional, since I had entered the host elsewhere for the connector, and I thought that Flow would put them together to send the request to the right URL. But it did not: when I tested the operation, I got a 404 error:
{
"error": "{\r\n \"code\": 404,\r\n \"message\": \"Unable to match incoming request to an operation.\",\r\n \"source\": \"msmanaged-na.azure-apim.net\",\r\n \"path\": \"\",\r\n \"clientRequestId\": \"500779d5-356d-4c79-bf96-caf2-f5bc2919\"\r\n}"
}
When I looked at the request, this is the URL:
https://msmanaged-na.azure-apim.net/apim/clio2.5fb03ce8462066f352.5fdeb6bc35b813689d/92053762-68ce-4c1d-9085-0785-0fd98c3b/api/v4/contacts.json?type=Person
So obviously Flow is not using the correct request URL, and I cannot figure out how to enter the fully qualified request URL. Can anybody tell me what I am doing wrong?
I found another comment where someone else is having the same problem: https://stackoverflow.com/a/48813209/7191369 so I'm not the only one. Thanks in advance for your help.
Edit:
After some additional searching, the address in the request (with https://msmanaged-na.azure-apim.net) is the required redirect URL for the proxy per this post: https://powerapps.microsoft.com/en-us/blog/custom-api-with-authentication/, and is used when processing OAuth. But the crappy part of this is that I can't see the request URL so I can't troubleshoot. Is there any way to see what request the proxy server is sending out to the Clio API?
It's been a while since this question was posted, but let me give you a suggestion to include the /api/v4 part of the URL inside the Base URL property of the Flow. This way all your endpoints will use the specified version and you will not have to define them one by one in each request.
Except if you intentionally want to use different versions across the requests :) Anyways, I'm glad that you've been able to resolve the issue.

CanJS can.route.ready() version 2.1- '#!' is changed to '#!&' on clicking the link

I have an application which relies on can.route to capture the #change when the user clicks on a link.
href for the link is having pattern '#!'.
Once the change is capture by the can route utility, i am seeing the hash in the browser changing to #!&.
This is causing an additional entry in browser history stack.
Has anyone faced a similar issue?
Appreciate your help.
Could not provide a fix as there is no code to see how the route is configured.
Looks like you are adding only additional parameters to the route. To confirm, pls execute can.route.attr(); in your developer console of the browser.
If everything is configured properly, you should get something like this for the url http://localhost/example#!currentRoutePage
---> can.route.attr();
Object {route: "currentRoutePage"}
Looks in your case, url is http://localhost/example#!&view=currentRoutePage and so route is null in the object
---> can.route.attr();
Object {view: "currentRoutePage", route: ""}
If this doesn't help much, please share the url you are seeing in the browser and the route configuration for the same.

Custom error handling

I am developing a component in joomla 2.5, my component sends a request to some url and gets the response object. If i pass wrong url, joomla takes me to the default page of Error : 500 - No response code found . I want that if user install my component and mistakenly they put wrong url , it should show some custom error message/page which should more meaningful to non-programming person rather than taking user to default error page. Is there some way to add this type of functionality in Joomla without editing template/error.php file in core.
You should have an error.php file in your template, if you don't add one and make it look the way you want. also remember that when you turn debugging off you won't get the stack trace etc.
However error 500 indicates something different than that the url does not exist ("wrong URL"), which would be a 404. 500 is an internal server error and you need to check your logs to figure out what is causing it.

How is the session created in a JSF application?

I got few doubts on sessions in JSF and/or in general.
First up, does session gets created on load of an web app in AS/servlet container? Meaning, after I do right click- run as - run on server and the app is started and synchornised?
Or does it get created after the web app is loaded and the defined welcome page is displayed and then the client makes a request?
Second: I was looking into the issue of "Cannot create a session after the response has been committed" in jsf.
I was trying to reproduce the issue by doing this given in the following site,
http://java.net/jira/browse/JAVASERVERFACES-2215
But, I didnt get any error as mentioned above. I tried with all bean scope.
Was the session created?
This is the code.
<h:body>
<h:form id="test">
<p:growl id="msg"></p:growl>
<h:outputText value="#{myTestBean.exceedBuffer}" />
</h:form>
</h:body>
bean code is.
public String getExceedBuffer() {
int size = FacesContext.getCurrentInstance().getExternalContext().getResponseBufferSize();
char[] chars = new char[size];
Arrays.fill(chars, 'x');
return new String(chars);
}
My understanding is the following,
First when the app is loaded the servlet container or an AS creates a session and a sessionID(JSESSIONID) and puts it in server memory. So the initial page gets loaded up anyhow, meaning even if the response buffer is overflowed or not but the session wont be created. Now, when the client makes a request on this page, since the session was not created, the error occurs. But, I tried even doing this by
<p:commandButton actionListener="#{myTestBean.onSelect}" update=":test"></p:commandButton>
and in onSelect method just entered a dummy code. Even now the page displayed as usual.
Well, that was when I was completely lost. Can someone pls help me on this? Thanks in advance.
First up, does session gets created on load of an web app in AS/servlet container? Meaning, after I do right click- run as - run on server and the app is started and synchornised?
Or does it get created after the web app is loaded and the defined welcome page is displayed and then the client makes a request?
It's created on start of the HTTP session, not on webapp's startup (that's the application scope). Basically, when request.getSession() is called for the first time and the HttpSession hasn't been created yet. This all is handled by the Servlet API which JSF is using under the covers. So the following answer should help in understanding how it works: How do servlets work? Instantiation, sessions, shared variables and multithreading
Second: I was looking into the issue of "Cannot create a session after the response has been committed" in jsf.
I was trying to reproduce the issue by doing this given in the following site, http://java.net/jira/browse/JAVASERVERFACES-2215
But, I didnt get any error as mentioned above. I tried with all bean scope. Was the session created?
You will get this error when the HttpSession isn't created yet at the moment the response is committed. That you didn't get this error can only mean that the session has already been created beforehand. You need to test it on a freshly started webapp and the session shouldn't be created yet. Note that some servers by default stores sessions on shutown/restart. You'd need to disable this or to remove the JSESSIONID cookie in your browser before sending the first request on this test page. Restarting the webbrowser or using a different one should also force a fresh new session.

500 error when integrating multiple apps in one code base

I'm trying to set up an MVC application that will service several facebook applications for various clients. With help from Prabir's blog post I was able to set this up with v5.2.1 and it is working well, with one exception.
At first, I had only set up two "clients", one called DemoStore and the first client, ClientA. The application determines what client content and facebook settings to use based on the url. example canvasUrl: http://my_domain.com/client_name/
This works for ClientA, but for some reason when I try any DemoStore routes I get a 500 error. The error page points to an issue with the web.config.
Config Error:
Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'facebookredirect.axd'
I am able to add additional clients with no problem, and changing DemoStore to something like "demo" while using the same facebook application settings works fine also.
Working calls:
http:// localhost:2888/ClientA/
http:// localhost:2888/ClientB/
http:// localhost:2888/Demo/
Failing call:
http:// localhost:2888/DemoStore/
I was thinking this might be an MVC issue, but the Config Error points to the facebookredirect handler. Why would the SDK try to add this value to the config during runtime, and only for this specific client?
Any insight would be greatly appreciated.
I managed to figure out what went wrong here. Silly mistake..
After I had set up the application routes to require the client_name I changed the Project Url in the project properties to point to demostore by default. When I hit ctrl+S a dialog popped up that I promptly entered through without reading.
When I changed the Project Url, IIS Express created a new virtual directory for the project. This was the source of my problem. Why? I'm not sure, but once I removed the second site from my applicationhost.config I was able to access the DemoStore routes.
Moral of the story: read the VS dialog messages!

Resources