Creating Login Page in Oracle ADF

Follow these steps to create Login Page in Oracle ADF with ADF Security


  • Create Login.jspx page with two input text fields and bind those fields to a bean. Bind the button to one of the functions available in the below code (doLogin or doLoginNew)




  •  Now add the following functions in the bean. You can either use doLoginNew or
    doLogin function.


package view;

import java.io.IOException;

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

import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.LoginException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.adf.view.rich.component.rich.input.RichInputText;

import weblogic.security.URLCallbackHandler;
import weblogic.security.services.Authentication;

import weblogic.servlet.security.ServletAuthentication;

public class LoginBean {
    private RichInputText _username;
    private RichInputText _password;

    public LoginBean() {
    }

    public void set_username(RichInputText _username) {
        this._username = _username;
    }

    public RichInputText get_username() {
        return _username;
    }

    public void set_password(RichInputText _password) {
        this._password = _password;
    }

    public RichInputText get_password() {
        return _password;
    }

    private static final String REDIRECT_LOGIN_URL = "/adfAuthentication?success_url=/faces/EmployeesPage";
    
    
    
    private void reportUnexpectedLoginError(String errType, Exception e){
      FacesMessage msg =
        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Unexpected error during login",
                         "Unexpected error during login (" + errType + "), please consult logs for detail");
      
      FacesContext.getCurrentInstance().addMessage(null, msg);
      FacesContext.getCurrentInstance().renderResponse();
    }
    
    private void sendForward(String forwardUrl) {
        FacesContext ctx = FacesContext.getCurrentInstance();
        try {
          ctx.getExternalContext().redirect(forwardUrl);
        } catch (IOException ie) {
          reportUnexpectedLoginError("IOException", ie);
        }
         ctx.responseComplete();
      }
    
    public void doLoginNew(ActionEvent actionEvent) {
        
        String un = (String)get_username().getValue();
        byte[] pw = ((String)get_password().getValue()).getBytes();;
          FacesContext ctx = FacesContext.getCurrentInstance();
          HttpServletRequest request =
                         (HttpServletRequest)ctx.getExternalContext().getRequest();
          try {
              CallbackHandler handler = new URLCallbackHandler(un, pw);
              Subject mySubj = 
                         weblogic.security.services.Authentication.login(handler);
              weblogic.servlet.security.ServletAuthentication.runAs(mySubj, request);
              ServletAuthentication.generateNewSessionID(request);
              String loginUrl = "/faces/EmployeesPage";
              sendForward(loginUrl);
           } catch (FailedLoginException fle) {
              FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                "Incorrect Username or Password",
                                                "An incorrect Username or Password" +
                                                " was specified");
              ctx.addMessage(null, msg);
              set_password(null);
           } catch (LoginException le) {
              reportUnexpectedLoginError("LoginException", le);
           }
            
    }
    
    public void doLogin(ActionEvent actionEvent) {
        String username = (String)get_username().getValue();
        byte[] password = ((String)get_password().getValue()).getBytes();
        CallbackHandler handler = new URLCallbackHandler(username, password);
        try {
            Subject subject = Authentication.login(handler);
            ExternalContext eCtx = FacesContext.getCurrentInstance().getExternalContext();

            HttpServletRequest request = (HttpServletRequest)eCtx.getRequest();

            ServletAuthentication.runAs(subject, request);
            ServletAuthentication.generateNewSessionID(request);

            FacesContext ctx = FacesContext.getCurrentInstance();
            RequestDispatcher dispatcher = request.getRequestDispatcher(REDIRECT_LOGIN_URL);
            dispatcher.forward(request, (HttpServletResponse)eCtx.getResponse());
            ctx.responseComplete();
        } catch (LoginException le) {
            le.printStackTrace();
        } catch (ServletException se) {
            se.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
}

  • Go to Application Menu -> Secure -> Configure ADF Security

  •  
  • So now all users in Jazn-data.xml will be authenticated 
  •  

Comments

All Categories

Call Fusion BIP Report2 Change Password1 Code Combinations2 Compute Instance2 CTE1 Customer1 Data Aggregation2 Database5 Date Conversion1 DB Adapter2 Decryption1 Development1 EBS4 Encryption1 ESS Jobs3 Examine1 FBDI3 Fusion APIs1 Fusion BIP7 GIT2 GL3 GL Journals1 GL_DAILY_CONVERSION_TYPES1 GL_DAILY_RATES1 ICS1 Identity Domain1 Integrations1 Java1 Journal Import1 Keys1 Legal Entity1 LookupTypeLOV1 LOV1 LOVs1 MultiPartAPIs1 Networking1 NVL2 NVL in OIC2 OCI11 OCI Billing1 OCI Compute5 OCI Cost Management1 OCI Events Service1 OCI Free Tier3 OCI Notifification Service1 OCI Security3 OIC4 OIC Mapper2 Oracle26 Oracle ADF17 Oracle APEX1 Oracle Apps59 Oracle Apps R126 Oracle ATP1 Oracle BIP8 Oracle Cloud12 Oracle Cloud Free Tier1 Oracle cloud Infrastructure9 Oracle Cloud Security2 Oracle Cloud VM1 Oracle DB4 oracle ebs5 Oracle ERP4 Oracle ERP Adapter2 Oracle ERP Cloud7 Oracle financials2 Oracle Forms1 Oracle Fusion57 Oracle Fusion BIP4 Oracle Fusion ERP17 Oracle Fusion Financials18 Oracle Integration Cloud3 Oracle OAF17 Oracle OCI14 Oracle OIC22 Oracle SOA 12c10 Oracle SQL17 Oracle VBCS1 Oracle VBS2 Oracle Visual Builder Cloud Service1 Oracle Visual Builder Studio2 Oracle Workflow Notifications1 Others10 Payables2 Payables Import1 Properties1 R121 Register BIP as ESS Job1 Reset Password1 Responsibility1 REST4 Security List1 Site Map1 SOAP2 SOAP API2 SOAP UI3 SQL16 SQL Functions3 SQL Queries14 SQL Query8 SQL Tips3 SSH1 TCA1 Value Sets1 VBCS1 Virtual Machine2 Virtual Machines1 XML1 XSLT1
Show more