CAS - Redirect to custom login page when credentials are wrong - redirect

Good morning.
I've successfully configured a CAS SSO server and client. However, I want to change CAS' configurations to use a custom login page. I followed this tutorial to make such configuration and it works like a charm. But, the problem is that when I enter invalid credentials (wrong username or password) it tries to redirect to the CAS' default login page; however, it should redirect to the custom external login page. I would really appreciate if you help me to find out how to make CAS to redirect to a different page when wrong credentials are entered.
This is my casLoginView.jsp
<%# page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<script type="text/javascript">
function doAutoLogin() {
document.forms[0].submit();
}
</script>
</head>
<body onload="doAutoLogin();">
<form id="credentials" method="POST" action="https://externalsite.com/cas-server-webapp-4.0.0/login?service=<%= request.getParameter("service") %>">
<input type="hidden" name="lt" value="${loginTicket}" />
<input type="hidden" name="execution" value="${flowExecutionKey}" />
<input type="hidden" name="_eventId" value="submit" />
<input type="hidden" name="username" value="<%= request.getParameter("username") %>" />
<input type="hidden" name="password" value="<%= request.getParameter("password") %>" />
<% if ("true".equals(request.getParameter("rememberMe"))) {%>
<input type="hidden" name="rememberMe" value="true" />
<% } %>
<input type="submit" value="Submit" style="visibility: hidden;" />
</form>
</body>
And this is my external custom login page:
<form method="GET" action="https://externalsite.com/cas-server-webapp-4.0.0/">
<p>Username : <input type="text" name="username" /></p>
<p>Password : <input type="password" name="password" /></p>
<p>Remember me : <input type="checkbox" name="rememberMe" value="true" /></p>
<p><input type="submit" value="Login !" /></p>
<input type="hidden" name="auto" value="true" />
<input type="hidden" name="service" value="<%= request.getParameter("service") %>" />
</form>
Basically my external login page sends the credentials to the CAS login page and the latter is submited automatically. However, when credentials are wrong, CAS redirects to the default login page and not to my external login page.
Regards.

You need change the code at login-webflow.xml in cas-server-webapp.
The code should be changed as below:
<action-state id="handleAuthenticationFailure">
<!-- Comment FailedLoginException and AccountNotFoundException -->
<!--<transition on="FailedLoginException" to="generateLoginTicket"/>-->
<!--<transition on="AccountNotFoundException" to="generateLoginTicket"/>-->
</action-state>
Add:
<action-state id="customFailedLoginException">
<evaluate expression="generateLoginTicketAction.generate(flowRequestContext)" />
<transition on="generated" to="customFailedLoginExceptionView" />
</action-state>
<view-state id="customFailedLoginExceptionView" view="externalRedirect:#{requestParameters.service}&errorMsg=failedLogin"/>
<action-state id="customAccountNotFoundException">
<evaluate expression="generateLoginTicketAction.generate(flowRequestContext)" />
<transition on="generated" to="customAccoundNotFoundExceptionView" />
</action-state>
<view-state id="customAccoundNotFoundExceptionView" view="externalRedirect:#{requestParameters.service}&errorMsg=notFound" />
Now if you submit a user name that do not exists or a password that is wrong, your would get a response url with a parameter called 'errorMsg'.
I also make a sample about how to login cas with client custom login screen rather than server login srceen. You could download it on
https://github.com/yangminxing/cas-custom-login-page

I solved my problem by changing the transitions on the login-webflow.xml file. What I did was to create a new action state:
<action-state id="customFailedLogin">
<evaluate expression="generateLoginTicketAction.generate(flowRequestContext)" />
<transition on="generated" to="externalRedirection" />
</action-state>
and this one calls a view-state which redirects the user to my external login page
<view-state id="externalRedirection" view="externalRedirect:#{requestParameters.callingUrl}&error=true"/>
(callingUrl is a variable that I created and sent with the service url). At the end I just changed the transition in the handleAuthenticationFailure
<transition on="AccountNotFoundException" to="customFailedLogin"/>
<transition on="FailedLoginException" to="customFailedLogin"/>
Hope it helps to someone else.

Related

formspree.io "Make sure you open this page through a web server ..."

I'm trying to use formspree.io but for some reason is returning the following error:
Make sure you open this page through a web server, Formspree will not work in >pages browsed as HTML files. Also make sure that you're posting to >https://formspree.io/test#yopmail.com.
For geeks: could not find the "Referrer" header.
My code is the following:
<form action="https://formspree.io/test1#yopmail.com" method="POST" target="_blank">
<input type="text" id="name" name="name" placeholder="*First Name">
<input type="text" id="lastname" name="lastname" placeholder="*Last Name">
<textarea id="subject" name="subject" placeholder="*Your Message" style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
Please notice that I have the s in the "https://fo..." and I also have in my head tag the following:
<meta name="referrer" content="origin">
Thanks for any help.

Extension showing html on frontend

I am new to Typo3 development. I am using Typo3 version 6.2.0. I have created a custom extension using extension buider. Its working is basic and just register two values name and id.
Extension is showing a link to new registration but after that its is showing fluid+html tags on the page instead of showing rendered output(textbox and form).
Please help me solving this problem.
<form name="newTest" action="index.php?id=24&tx_tl1_t...<form name="newTest" action="index.php?id=24&tx_tl1_tl2%5Baction%5D=create&tx_tl1_tl2%5Bcontroller%5D=Test&cHash=b3050554aab196ddb3773dbb3eefda3c" method="post">
<input type="hidden" name="tx_tl1_tl2[__referrer][#extension]" value="Tl1" />
<input type="hidden" name="tx_tl1_tl2[__referrer][#vendor]" value="Cts" />
<input type="hidden" name="tx_tl1_tl2[__referrer][#controller]" value="Test" />
<input type="hidden" name="tx_tl1_tl2[__referrer][#action]" value="new" />
<input type="hidden" name="tx_tl1_tl2[__referrer][arguments]" value="YToyOntzOjY6ImFjdGlvbiI7czozOiJuZXciO3M6MTA6ImNvbnRyb2xsZXIiO3M6NDoiVGVzdCI7fQ==a98b3f0778be75a7fc4b7f2fbe9f541196f8c763" />
<input type="hidden" name="tx_tl1_tl2[__trustedProperties]" value="a:1:{s:7:"newTest";a:1:{s:8:"username";i:1;}}18e3421cc9d103c83147f40c4a539581aef5788e" />
Username
<input type="text" name="tx_tl1_tl2[newTest][username]" />
<input type="submit" name="" value="Create new" />
</form>

SEO Url not changing upon form submission

Am using SEO URls to load my pages ie http://www.mywebsite.com/p/page1/100 but am having a problem with my search form. When I click submit, instead of the entire url changing to the stated one in the form, it just appends the variables to the url eg http://www.mywebsite.com/p/page1/100?p=search&q=Any+Query+String+here.
My question is, how do I replace the entire URL with the form variable instead?
Here is my form code:
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">
<input type="text" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" name="q" value="Search" />
<input type="hidden" value="search" name="p" />
<input type="submit" value="Search" class="submit" />
</form>
OK I solved it using a hack I think???
Apparently if I append a variable to the action url, this will force the browser to load the new url instead of append the form variable to the existing url.
Eg.
<form action="<?php $_SERVER['PHP_SELF'] ?>?p=search" method="get">
<input type="text" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" name="q" value="Search" />
<input type="hidden" value="search" name="p" />
<input type="submit" value="Search" class="submit" />
</form>
This worked for me but I dunno if it's the right way to achieve this or it's a hack.

JSF form with URL action?

Is there any way to call a URL action within a <h:commandButton>, or for that matter a <h:form>? I'm trying to bypass my email's login page from my own website, so I'm using JSF beans to hold my login info in <h:inputSecret> tags so that I can simply click "Go to Email" and because I'm logged in to my own website, I could go straight to my inbox w/o logging in again
Just use plain HTML <form> instead of JSF <h:form>.
<form action="http://example.com/mail" method="post">
<input type="text" name="username" value="#{bean.username}" />
<input type="password" name="password" value="#{bean.password}" />
<input type="submit" value="Go to Email" />
</form>

IE Form redirecting to action

I have the following simple form:
<form id="MyForm" action="../webformmailer.php" method="post" >
<input type="hidden" name="subject" value="Submission" />
<input type="hidden" name="redirect" value="../sandbox/123/thanks.html" />
<input type="text" size="20" name="FirstName" />
<input type="text" size="20" name="LastName" />
<input type="text" size="20" name="email" />
<select name="comment">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<input type="submit" name="submit" value="submit"/>
</form>
I am redirecting users to a simple 'thanks.html' page after they submit their information. This works well in all browsers except IE 8, which redirects users to the webformmailer.php or the action of the form.
Can anyone point me in the right direction?
Thanks
Inside your action script, process the request and then redirect to thanks.html:
header('Location: ../sandbox/123/thanks.html');
Update: since you don't have control over the action script, and all other browsers work exception IE8, then the problem must be in the way IE8 sends data to the server. Try set enctype="application/x-www-form-urlencoded" and see if it works.