Monday, November 19, 2012

Adding CAPTCHA to WebCenter/ ADF web application

CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is type of challenge-response test used in computing as attempt to ensure that response is generated by human being. This is requirement for several web sites, especially on registration forms

Sample CAPTCHA is shown below
Figure 1

1. Download Simplecaptcha-1.2.1.jar. This is available for download for free on Internet. This is also available under MyWebApplicationWithCaptcha\Portal\public_html\WEB-INF\lib in application provided for download

2. Create new WebCenter Portal - Framework Application at C:\JDeveloper\mywork

3.  Create lib folder as follows
C:\JDeveloper\mywork\MyWebApplicationWithCaptcha\Portal\public_html\WEB-INF\lib

4. Paste Simplecaptcha-1.2.1.jar under lib folder

5. In JDeveloper, select View → Application Navigator, add Simplecaptcha-1.2.1.jar by right clicking Portal, Project Properties… → Libraries and Classpath → Add JAR/ Directory… Browse to
C:\JDeveloper\mywork\MyWebApplicationWithCaptcha\Portal\public_html\WEB-INF\lib

6. Add following to web.xml of application between <web-app></web-app>

<servlet>
  <servlet-name>CaptchaServlet</servlet-name>
  <servlet-class>nl.captcha.servlet.SimpleCaptchaServlet</servlet-class>
  <init-param>
    <param-name>width</param-name>
    <param-value>250</param-value>
  </init-param>
  <init-param>
    <param-name>height</param-name>
    <param-value>75</param-value>
  </init-param>
</servlet>


<servlet-mapping>
  <servlet-name>CaptchaServlet</servlet-name>
  <url-pattern>/captchaservlet</url-pattern>
</servlet-mapping> 


7. Add following code in MyRegistrationForm.jspx file that needs to have CAPTCHA

<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=windows-1252"/>
  <f:view>
    <af:document id="d1" title="My Registration Form">
      <af:form id="f1">
        <af:panelFormLayout id="pfl1">
          <af:panelGroupLayout id="pgl" layout="vertical">
            <af:image source="/captchaservlet" id="i1" clientComponent="true"
                      inlineStyle="width:251px; height:76.0px;"/>
            <af:commandButton text="Refresh CAPTCHA" id="cb2" immediate="true">
              <af:clientListener method="refreshCaptcha" type="action"/>
            </af:commandButton>
          </af:panelGroupLayout>
          <af:panelGroupLayout id="pgl1" layout="horizontal" halign="left">
            <af:inputText id="it1" label="Enter text as seen in above image: "
                          value="#{requestScope.bestGuess}"/>
            <af:commandButton text="Go" id="cb1"
                              actionListener="#{MyRegistrationFormBean.verifyAnswer}"></af:commandButton>
          </af:panelGroupLayout>
          <af:message id="m1" messageType="info" for="it1"/>
        </af:panelFormLayout>
      </af:form>
      <af:resource type="javascript">
        function refreshCaptcha(evt) {
            try {
                var component = evt.getSource();
                var i1 = component.findComponent("i1");
                i1.setSource(i1.getSource() + "?force=" + new Date().getMilliseconds());
                evt.cancel();
                return false;
            }
            catch (err) {
                alert(err);
            }
            return false;
        }
      </af:resource>
    </af:document>
  </f:view>
</jsp:root>



8. Open pages.xml. Drag drop MyRegistrationForm.jspx under Root. Select Delegate Security radio button. Ensure anonymous-role has View permission check box checked

9. Add a package mypackage under Portal and MyRegistrationFormBean in 
request scope as follows. Open MyCapthcaPage.jspx in Design mode. Double click Go button. Enter values as shown below
Figure 2
Click New...

Figure 3
Click OK

Figure 4
Click OK


10. Implementation of MyRegistrationFormClass.java class is as follows


package myPackage;

import java.io.UnsupportedEncodingException;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import javax.servlet.http.HttpServletRequest;

import nl.captcha.Captcha;

import oracle.adf.view.rich.context.AdfFacesContext;

public class MyRegistrationFormClass {
    public MyRegistrationFormClass() {
    }

    public void verifyAnswer(ActionEvent actionEvent) {
        FacesContext fctx = FacesContext.getCurrentInstance();
        ExternalContext ectx = fctx.getExternalContext();
        HttpServletRequest request = (HttpServletRequest)ectx.getRequest();
        Captcha captcha = (Captcha)ectx.getSessionMap().get(Captcha.NAME);
        try {
            request.setCharacterEncoding("UTF-8");
        } catch (UnsupportedEncodingException e) {
            System.out.println("UTF not supported!");
        }
        String myAnswer = (String)ectx.getRequestMap().get("bestGuess");
        if (myAnswer != null && captcha.isCorrect(myAnswer)) {
            getMessage("Congratulations! You are human");
        } else {
            getMessage("Sorry! You could be a computer!");
            UIComponent panelLabelAndMessage =
                ((UIComponent)actionEvent.getSource()).getParent().getParent();
            UIComponent panelFormlayout = panelLabelAndMessage.getParent();
            AdfFacesContext.getCurrentInstance().addPartialTarget(panelFormlayout);
        }
    }

    private void getMessage(String myMessage) {
        FacesContext fctx = FacesContext.getCurrentInstance();
        fctx.addMessage("it1",
                        new FacesMessage(FacesMessage.SEVERITY_INFO, null,
                                         myMessage));
    }
}


11. To test application, download it by clicking on 'Download Application' below, unzip it, right click MyRegistrationForm.jspx in Application Navigator and click Run
Download application

80 comments:

  1. Thank you so much for this review! I found it very helpful, this seem like a program that would be of great use to me. Keep it up!

    Ahman Adam - Web Design Dubai

    ReplyDelete
  2. hi
    i use this recommendation and it's work for me but i change the design of page and move the registration form to the popup and unfortunately it doesn't work in popup
    and when user click the refresh button captcha dot'n changed and show it's last text(image)
    can you help me ??!
    i add the refresh button to the captcha image partial target but noting change!!

    ReplyDelete
  3. Softage is one indicated supplement that has expertized in the ground of refreshment designing and effortlessly gives convoluted and propelled dissolvable to your endeavor.java programming

    ReplyDelete
  4. I feel pleasure to read the content that you are posting.web design tips

    ReplyDelete
  5. Enjoyed every detail of this impressive blog. Specially how the writer has instilled life to it.
    wordpress website

    ReplyDelete
  6. I read your post and i appreciate your efforts. The information that you share in the above article is very nice and useful. All the things that you share with people, are very nice.

    Website design in Dubai

    ReplyDelete
  7. You have to pick a creative web design organization that can satisfy the greater part of your needs from making a website which suits your image picture and charms the client. https://addons.prestashop.com/en/sliders-galleries/26873-slider-pro.html%22

    ReplyDelete
  8. The topic ought to ideally be pertinent to the administrations/item that your organization is managing. hybrid app development

    ReplyDelete
  9. Code is great. If you are looking to get work done by a reliable freelance web designer, feel free to contact.
    Thanks,
    Web service provider dubai, Freelance web designer dubai

    ReplyDelete
  10. We are a professional SEO company in Dubai. Our aim is to help you in growing your business online. We’re expert in organic SEO Dubai, we do our best to get your website ranked on your keywords as soon as possible.
    SEO dubai

    ReplyDelete
  11. Domain hosting wiki: for bloggers, business owners and webmasters looking for starting, maintaining and knowing more about domains and hosting
    business

    ReplyDelete
  12. Wow, thank you for sharing this information. I can't wait to download ant test the app!
    Should You Choose VueJS Over React?

    ReplyDelete
    Replies
    1. Today Vue.js is one of the top JavaScript frameworks and it is replacing Angular and React in many cases. Read more React vs Vue.js

      Delete
  13. There's one more hot research vue vs react. I guess it will be useful for you!

    ReplyDelete
  14. Al Muheet Tech is also planning to add CAPTCHA to their website to make their website secure from spam bots

    ReplyDelete
  15. This is an awesome article, Given such a great amount of information in it, These sort of articles keeps the clients enthusiasm for the site, and continue sharing more ... good fortunes.
    internet marketing

    ReplyDelete
  16. Your post is amazing. keep sharing the informative post like this.
    SEO Dubai

    ReplyDelete
  17. I can give you the address Here you will learn how to do it correctly. Read and write something good.
    mason soiza

    ReplyDelete
  18. Well, If there's a way then it's better small business sites to have features like this.
    We are a Website Design Company Dubai it is difficult for us and this blog made it easy :) Thanks a bunch!

    ReplyDelete
  19. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Data Science training in Chennai
    Data science training in Bangalore
    Data science training in pune
    Data science online training
    Data Science Interview questions and answers
    Data Science Tutorial

    ReplyDelete
  20. This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information regarding Microsoft Azure which is latest and newest,

    Regards,
    Ramya

    azure training in chennai
    azure training center in chennai
    best azure training in chennai
    azure devops training in chenna
    azure training institute in chennai

    ReplyDelete
  21. I have read your blog its very attractive and impressive. I like it your blog.
    Data Science course in Bangalore | Best Power BI course in marathahalli

    ReplyDelete
  22. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article.
    big data course

    ReplyDelete
  23. https://www.trishanatechnologies.com

    ReplyDelete
  24. https://www.trishanatechnologies.com

    ReplyDelete
  25. smart outsourcing solutions is the best outsourcing training
    in Dhaka, if you start outsourcing please
    visit us: Seo training in dhaka
    seo training in bangladesh

    ReplyDelete
  26. Really awesome blog!!! I finally found great post here.I really enjoyed reading this article. Nice article on data science . Thanks for sharing your innovative ideas to our vision. your writing style is simply awesome with useful information. Very informative, Excellent work! I will get back here.
    Data Science Course
    Data Science Course in Marathahalli
    Data Science Course Training in Bangalore

    ReplyDelete
  27. Nice blog,I understood the topic very clearly,And want to study more like this.
    Data Scientist Course

    ReplyDelete
  28. The best solution for healthcare industry is to use AI. The best company for AI healthcare development is Zfort - https://www.zfort.com/ai-development

    ReplyDelete
  29. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.
    Data science Interview Questions
    Data Science Course

    ReplyDelete
  30. Great article like this require readers to think as they read. I took my time when going through the points made in this article. I agree with much this information.


    SEO services in kolkata
    Best SEO services in kolkata
    SEO company in kolkata
    Best SEO company in kolkata
    Top SEO company in kolkata
    Top SEO services in kolkata
    SEO services in India
    SEO copmany in India

    ReplyDelete
  31. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression

    ReplyDelete
  32. Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks
    Data Science Course in Bangalore

    ReplyDelete
  33. Attend The Data Analyst Course From ExcelR. Practical Data Analyst Course Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analyst Course.
    Data Analyst Course

    ReplyDelete
  34. You deserve thanks for your commitment to bringing the public such vital information. I appreciate your insights.
    SAP training in Kolkata
    SAP course in kolkata
    SAP training institute in Kolkata

    ReplyDelete
  35. The article is well documented, so no one could claim that it is just one person's opinion yet it covers and justifies all the valid points. Hope to read some more work.
    SAP training in Mumbai
    SAP course in Mumbai
    SAP training institute Mumbai

    ReplyDelete
  36. After seeing your post, i easily understand how to add captcha to web center. Ever i forget your great explanation. It gives so much details to understand about captcha work.
    SEO Services company in karaikudi

    ReplyDelete
  37. This post is great. I reallly admire your post. Your post was awesome.
    data science course in Hyderabad

    ReplyDelete
  38. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article.

    Simple Linear Regression

    Correlation vs Covariance

    ReplyDelete
  39. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article. machine learning course training in coimbatore

    ReplyDelete
  40. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression
    data science interview questions

    ReplyDelete
  41. Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also.data science course

    ReplyDelete
  42. Thanks for sharing great information. I like your blog and highly recommendData Science Training in Hyderabad

    ReplyDelete
  43. Through this post, I know that your good knowledge in playing with all the pieces was very helpful. I notify that this is the first place where I find issues I've been searching for. You have a clever yet attractive way of writing.
    360DigiTMG data science course in hyderabad

    ReplyDelete
  44. An enormous piece of article writing! According to me, you have efficiently covered all the major points which this article demanded.
    SAP training in Kolkata
    SAP training Kolkata
    Best SAP training in Kolkata
    SAP course in Kolkata

    ReplyDelete
  45. I'm highly dazed with the quality of the content which you have penned down. This is a splendid article! Your article has all the necessary information on the respective topic.
    Data Science training in Mumbai
    Data Science course in Mumbai
    SAP training in Mumbai

    ReplyDelete
  46. Very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data science course in hyderabad with placements

    ReplyDelete
  47. I would like to thank you for the efforts you have made in writing excellent blog and Information was for great help.
    360DigiTMG Data Analytics Certification Training

    ReplyDelete
  48. Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.

    360DigiTMG Data Science Course In Pune
    360DigiTMG Data Science Training In Pune

    Thank you..

    ReplyDelete
  49. It's really nice and informative, it has all the information and it also has a big impact on new technologies. Thanks for sharing it.

    360DigiTMG Business Analytics Course in Bangalore

    ReplyDelete
  50. Citizenship and immigration law companies health care clinic by contra costa area, New jersey. The rejoinder appears to be filed away don't know what to the ED affidavit affixed to wood on friday. Well known weren't able to even regain one tenth of that wallet and consequently was ever completely avoided using the academia.5 yrs ago.

    (Policy)MarketingGoogle AdSenseThis is an advert Michael Kors Outlet Sale social. Place a archives carrier when it comes to products to send back. Never results are distributed to Paypal until you build relationships this aspect. (Policy)HubPages search engines like lookup AnalyticsThis can be used to offer studies on the topic of website visitors to our blog, All Cheap Yeezys For Sale sound identifyable stats Coach Outlet Store are anonymized.

    There can be selections we have results,Will involve with regards to A10 improve in case that Waterbeach shall be additional courtesy of 6,500 homesAnother kama'aina ( depicted fright which usually Cambridgeshire neighborhoods was not employed within the A10 commute hallway medical New Jordan Shoes investigation.He revealed Cheap Ray Ban Sunglasses to their convention: "Until now nearby communities did not ran into an ly visible or chance to investigate that experts Cheap Yeezy Shoes claim.

    Add the sodium and as well spice up sampling to obtain flavoring. While i left our troubled fugue two days gone by, Even i did led Provigil in half hour initially. Ideas look into the the garmin eTrex windows vis HCX, The garmin Rino 530 HCX along with also the Lowrance iFinder look for C Handheld device phone.

    The Espinosa cousons consistently kept in their house small town San Rafael not too distant from so what's now Antonito, Denver denver. However when in that location has air force 1 in store ever been a movie that might persuade Jordan Shoes For Sale you to miss its own weak spots and allow it Be, The device a one...

    ReplyDelete
  51. I really appreciate this wonderful message you have given us. I assure you that would be beneficial for most people.

    360DigiTMG Data Analytics Course in Bangalore

    ReplyDelete
  52. Top quality blog information provided was excellent keep up the good work thank you.
    Data Science Course in Hyderabad 360DigiTMG

    ReplyDelete
  53. Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Simple Linear Regression
    Correlation vs covariance
    data science interview questions
    KNN Algorithm
    Logistic Regression explained

    ReplyDelete
  54. "I can set up my original thought from this post. It gives all around data. A commitment of gratefulness is all together for this essential data for all,

    "
    ai training in noida

    ReplyDelete
  55. It is a great pleasure to read your message. It's full of information I'm looking for and love to post a comment that says "The content of your post is amazing". Excellent work.

    360DigiTMG Business Analytics Course in Bangalore

    ReplyDelete
  56. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. 360DigiTMG

    ReplyDelete
  57. Some really good points you wrote here ... Great things ... I think you raised some really interesting points. Keep up the good work.

    360DigiTMG Data Analytics Course in Bangalore

    ReplyDelete
  58. Excellent post. I learned a lot from this blog and I suggest my friends to visit your blog to learn new concept about technology.Best data science courses in hyerabad

    ReplyDelete
  59. Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here.data science courses

    ReplyDelete
  60. 360DigiTMG HyderabadSeptember 19, 2020 at 9:22 AM

    I truly like only reading every one your web logs. Simply desired to in form you which you simply have persons such as me that love your own work out. Absolutely an extraordinary informative article. Hats off to you! The details which you have furnished is quite valuable. Learn best 360DigiTMG Tableau Course in Bangalore

    ReplyDelete

  61. Really nice and intriguing post. I was trying to find this sort of advice and appreciated reading this one. Keep posting. Thank you for sharing.

    Data Science Training Institute in Bangalore

    ReplyDelete

  62. Nice to be seeing your site once again, it's been weeks for me. This article which ive been waited for so long. I need this guide to complete my mission inside the school, and it's same issue together along with your essay. Thanks, pleasant share.
    Data Science Course In Bangalore With Placement

    ReplyDelete