ADF Code Corner How-to use Captcha with ADF Faces and Oracle ADF. Abstract: twitter.com/adfcodecorner

Similar documents
ADF Code Corner How-to show a glasspane and splash screen for long running queries. Abstract: twitter.com/adfcodecorner

ADF Code Corner. Oracle JDeveloper OTN Harvest 01 / Abstract: twitter.com/adfcodecorner

ADF Code Corner. 97. How-to defer train-stop navigation for custom form validation or other developer interaction. Abstract: twitter.

ADF Code Corner How-to launch a popup upon rendering of a page fragment in a region using JSF 2. Abstract: twitter.

ADF Code Corner. 90. Filtering ADF bound lists. Abstract: twitter.com/adfcodecorner

ADF Mobile Code Corner

ADF Code Corner How-to enforce LOV Query Filtering. Abstract: twitter.com/adfcodecorner

ADF Code Corner Implementing auto suggest functionality in ADF Faces. Abstract:

ADF Code Corner. 71. How-to integrate Java Applets with Oracle ADF Faces. Abstract: twitter.com/adfcodecorner

ADF Code Corner How to cancel an edit form, undoing changes with ADFm savepoints

ADF Code Corner How-to declaratively build a master-detail behavior with DVT components. Abstract: twitter.com/adfcodecorner

ADF Mobile Code Corner

ADF Code Corner. 64. How-to implement a Select Many Shuttle with pre- selected values. Abstract: twitter.com/adfcodecorner

ADF Code Corner. 016-How-to customize the ADF Faces Table Filter. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to further filter detail queries based on a condition in the parent view using ADF BC. Abstract: twitter.

ADF Code Corner. 70. How-to build dependent list boxes with Web Services Business Services. Abstract: twitter.com/adfcodecorner

An Oracle White Paper June Guidelines for Creating Task Flows to Be Used in Oracle Composer-Enabled Pages

How To Create Employee With Designation Report In ADF Attractively

ADF Mobile Code Corner

ADF Code Corner How-to use the af:autosuggestbehavior component tag with ADF bound data sources. Abstract: twitter.

ADF Code Corner. Oracle JDeveloper OTN Harvest 10 / Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to bind custom declarative components to ADF. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to restrict the list of values retrieved by a model driven LOV. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to build a reusable toolbar with Oracle ADF Declarative Components. Abstract: twitter.com/adfcodecorner

ADF Code Corner. 65. Active Data Service Sample Twitter Client. Abstract: twitter.com/adfcodecorner

Different color bars chart with Popup Box in ADF

ADF Mobile Code Corner

Hello Worldwide Web: Your First JSF in JDeveloper

ADF Region Interaction: External Train Navigation

ADF Code Corner. 048-How-to build XML Menu Model based site menus and how to protect them with ADF Security and JAAS. Abstract:

Functional. Pattern Embeding Regions inside PopUp Windows

ADF Code Corner. Oracle JDeveloper OTN Harvest 02 / Abstract: twitter.com/adfcodecorner

ADF Code Corner. Oracle JDeveloper OTN Harvest 12 / Abstract: twitter.com/adfcodecorner

Oracle Business Intelligence Publisher

Using JavaScript in ADF Faces Rich Client Applications

ADF Code Corner. Oracle JDeveloper OTN Harvest 09 / Abstract: twitter.com/adfcodecorner

An Oracle White Paper September Exposing WebCenter Services Task Flows as WSRP Portlets and Ensemble Pagelets

ADF Code Corner. Oracle JDeveloper OTN Harvest 04 / Abstract: twitter.com/adfcodecorner

Oracle Hyperion Financial Management Developer and Customization Guide

Oracle Developer Day

Copyright Descriptor Systems, Course materials may not be reproduced in whole or in part without prior written consent of Joel Barnum

We didn t need dialogue. We had faces.

ADF Code Corner. The Oracle JDeveloper Forum Harvest 10 / Abstract: twitter.com/adfcodecorner

Achieving the Perfect Layout with ADF Faces RC

Döcu Content Notes Document View BackingBean

Döcu Content Phantom Pages and Links JavaBean

文字エンコーディングフィルタ 1. 更新履歴 2003/07/07 新規作成(第 0.1 版) 版 数 第 0.1 版 ページ番号 1

... AND UIX BEGAT ADF FACES: HOW RICH IS ADF FACES RICH CLIENT? Peter Koletzke, Quovera

5.1 Registration and Configuration

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

1Z0-430

Oracle Retail Accelerators for WebLogic Server 11g

11 MOST COMMON MARKETING BLUNDERS AND HOW TO OVERCOME THEM

Contents. 1. JSF overview. 2. JSF example

Liferay Faces. Reference Documentation ga4

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

If you wish to make an improved product, you must already be engaged in making an inferior one.

Introduction to Java Server Faces(JSF)

FAQ: Crawling, indexing & ranking(google Webmaster Help)

Platform as a Service lecture 2

ServletConfig Interface

Take Your Oracle Forms on the Road Using ADF Mobile. Mia Urman, OraPlayer & Denis Tyrell, Oracle Corporation

PROFILE USER MANUAL. Satori Team

Introduction Haim Michael. All Rights Reserved.

Peter Norrhall. Callista Enterprise AB.

CS506 Web Design & Development Final Term Solved MCQs with Reference

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

shortcut Tap into learning NOW! Visit for a complete list of Short Cuts. Your Short Cut to Knowledge

INSTRUCTIONS FOR INSTALLING THE FACEBOOK BBB DYNAMIC SEAL. February 2017

This document explains how to obtain a direct link from within an existing Facebook page to the hotel s booking

AJAX in Apache MyFaces A New Approach To Web Applications

HTTP. HTTP HTML Parsing. Java

JavaServer Faces User's Guide J2X ENZ2(00)

<Insert Picture Here> Productive JavaEE 5.0 Development

Lab 10. Google App Engine. Tomas Lampo. November 11, 2010

ADF On-Ramp: What You Need to Know to Use ADF. What is ADF and Fusion? ADF core technologies. Required languages. Survey. Agenda. On the Positive Side

ArcGIS Server Java. ICEfaces - Esri Integration Guide

Oracle Fusion Middleware 11g: Build Applications with ADF I

Java TM. JavaServer Faces. Jaroslav Porubän 2008

OIG 11G R2 Field Enablement Training

Getting Started Guide. Version 1.7

EASYDNNROTATOR 7.X [USER S GUIDE]

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

Software Design Document

WORDPRESS 101 A PRIMER JOHN WIEGAND

A.1 JSP A.2 JSP JSP JSP. MyDate.jsp page contenttype="text/html; charset=windows-31j" import="java.util.calendar" %>

FINALTERM EXAMINATION Spring 2009 CS506- Web Design and Development Solved by Tahseen Anwar

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1

Advanced Internet Technology Lab # 4 Servlets

INTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature

Java Server Faces - The View Part

OES Permission Checks in ADF Task Flows

The Arrangement of the Screens: Introduction to Layout in ADF Faces

How Does a Search Engine Work? Part 1

Oracle Utilities Customer Self Service

CS433 Technology Overview

CHAPTER 2 LIFECYCLE AND PAGE NAVIGATION

Securing REST using Oracle WebService Manager July 2013

JBoss WS User Guide. Version: CR1

Accounts and Passwords

Transcription:

ADF Code Corner 008. How-to use Captcha with ADF Faces and Oracle ADF Abstract: A pictures say more than a thousand words. And it says it in a way that is hard to parse for machines that otherwise would try and spam your system. For sure, you have seen this on the the Internet already and even Google uses it to - at least sometimes - check the seriousness of your query string. Captcha also is very popular when it comes to security. The way it works is that an image is generated and displayed on the screen. The random character string is also made available to the developer, who then can compare the provided user input with what he or she knows twitter.com/adfcodecorner Author: Frank Nimphius, Oracle Corporation twitter.com/fnimphiu 17-JULY-2009

Oracle ADF Code Corner is a loose blog-style series of how-to documents that provide solutions to real world coding problems. Disclaimer: All samples are provided as is with no guarantee for future upgrades or error correction. No support can be given through Oracle customer support. Please post questions or report problems related to the samples in this series on the OTN forum for Oracle JDeveloper: http://forums.oracle.com/forums/forum.jspa?forumid=83 Introduction Inspired by a question on OTN, I found a simple captcha solution posted on sourceforge.net that appears to be sufficient for this little ADF Code Corner goodie. 2

The project is "Simple Captcha" (http://simplecaptcha.sourceforge.net/) and it provides a HTTP servet that you can configure in your ADF Faces application and then reference from an af:image component. SimpleCaptcha is open source software under the BSD License. You can extend the functionality provided by the three simple servlet implementations in your own HttpServlet, following the instructions on the following page: http://simplecaptcha.sourceforge.net/extending.html In the Oracle JDeveloper 11g R1 example that you candownload at the end of this article, I let you prove that you are not a robot. A wrong entry that does not match the image text in the captcha will welcome you as Mr. Roboto. Implementation The implementation of this sample requires editing of 3 files, web.xml, the ADF Faces page that displays the captcha and a managed bean to initiate the comparison. The web.xml file is edited to contain the servlet reference <servlet> <servlet-name>captchaservlet</servlet-name> <servlet-class>nl.captcha.servlet.simplecaptchaservlet</servletclass> <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> ADF Faces Page Source The ADF Page source has nothing remarkable to point out. It uses an af:inputtext component for the user answer and anaf:image component to reference the Captcha servlet. An af:message component is used to display the informational message created in the managed bean. <f:view> <af:document id="d1"> <af:form id="f1"> <af:panelformlayout id="pfl1"> <f:facet name="footer"/> <af:image source="/captchaservlet" id="i1" inlinestyle="width:251px; height:76.0px;"/> <af:commandbutton text="can't read image" id="cb2" partialsubmit="false"/> <af:panellabelandmessage label="are U a robot?" id="plam1"> 3

<af:panelgrouplayout id="pgl1" layout="horizontal" halign="left"> <af:inputtext id="it1" value="#{requestscope.bestguess"/> <af:commandbutton text="try" id="cb1" actionlistener="#{handlecaptchabean.verifyanswer" partialsubmit="true" immediate="false"/> </af:panelgrouplayout> <af:message id="m1" messagetype="info" for="it1"/> </af:panellabelandmessage> </af:panelformlayout> </af:form> </af:document> </f:view> Managed Bean Code 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 HandleCaptchBean { public HandleCaptchBean() { 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) { //bad luck - but ignore System.out.println("UTF not supported!"); String answer = (String) ectx.getrequestmap().get("bestguess"); if (answer!= null && captcha.iscorrect(answer)){ message("hello, Human"); else{ message("hello Mr. Roboto. Try again."); UIComponent panellabelandmessage = ((UIComponent) actionevent.getsource()).getparent().getparent(); UIComponent panelformlayout = panellabelandmessage.getparent(); AdfFacesContext.getCurrentInstance().addPartialTarget( 4

panelformlayout); private void message(string s){ FacesContext fctx = FacesContext.getCurrentInstance(); fctx.addmessage("it1",new FacesMessage(FacesMessage.SEVERITY_INFO,"Info: "+s,null)); Download One of a few samples that do not require a database. The workspace is created with Orace JDeveloper 11g R1. There is one area that might need some additional work, which is to refresh the captcha image using PPR. But wait - didn't the title say "with ADF Faces and Oracle ADF"? What is the ADF part in this? Well, there is none! Download sample here from the ADF Code Corner website: http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html Update April, 12th 2012 Michael Yehle from Oracle used this sample and found a work around for the refresh issue I faced with this solution. The solution is to expose the Captcha image in an iframe. Here's the work around explained by copying content of Michael's mail: <af:inlineframe source="/captchaservlet" id="if1" clientcomponent="true" binding="#{viewscope.captchbean.iframe"/>... af:commandtoolbarbutton text="refresh" id="ctb1" actionlistener="#{viewscope.captchbean.refreshactionlistener" immediate="true" partialsubmit="true"/> and public void refreshactionlistener(actionevent actionevent) { AdfFacesContext.getCurrentInstance().addPartialTarget(iframe); 5