Showing posts with label ADF. Show all posts
Showing posts with label ADF. Show all posts

Tuesday, August 20, 2013

Run configuration For ADF UI projects

Go to manage run configuration from jdeveloper Run menu.
Click on New and create a run configuration.
Select the task flow for default run target.
Click on the Task flow and select taskflow from the drop down
Go to the run menu and run the 'Copy of Default' configuration created
Save the run configuration and next time just run the required run configuration.

Sunday, August 11, 2013

ADF Security Basics part 9 : Evaluate policies using Custom JAAS permission

Custom JAAS permission can be created from JASS Permission option from jDeveloper .From the New Gallery> All items
Create a JAAS permission with below attributes :
Add the following lines to jazn-data.xml against the app-role1 grant from the source editor

  <grant>
            <grantee>
              <principals>
                <principal>
                  <class>oracle.security.jps.service.policystore.ApplicationRole</class>
                  <name>app-role1</name>
                </principal>
              </principals>
            </grantee>
            <permissions>
                <permission>
                <class>view.TestPermission</class>
                <name>TestPermission</name>
                <actions>view</actions>
              </permission>
            </permissions>
          </grant>
          <grant>

Create a new Resource Type from (+) from the Resource grant section of jazn-data.xml

Create the page customPermission.jspx and assign app-role1 grant to the page def file of it 
Source code for the jspx :

<?xml version='1.0' encoding='UTF-8'?>
<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=UTF-8"/>
    <f:view>
        <af:document title="customPermission.jspx" id="d1">
            <af:form id="f1">
                <af:panelGroupLayout id="pgl1">
                    <af:button text="button 1" id="b1"
                               rendered="#{securityContext.userGrantedPermission['permissionClass=view.TestPermission;target=TestPermission;action=view']}"/>
                    <af:outputText value="#{securityContext.userGrantedPermission['permissionClass=view.TestPermission;target=TestPermission;action=view']}" id="ot1"/>
                </af:panelGroupLayout>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

Note the button text code in bold.Run the page and the button will be visible.





Thursday, August 1, 2013

ADF Security Basics part 6:Login screen


This blog explain how we can make use of the default login html pages created if we are selected the Form based authentication created. Also explain how we can create a login screen in ADF.

Create a fusion application
Enable ADF security with ADF Authentication and Authorization option

Select Authentication type as Form based authentication.

Select the default choice No Automatic grants 


Specify the default choice of authenticated welcome page select on Generate Default.



The summary page 


Create a page mypage.jspx and add a af:ink in it.

Add following expression to the text of af:link 

Change the destination property with the following expression
Create the user in the jazn-data.xml file .The user is added to the role app-role1 below

Granting the resource permission to the role app-role1


Login as the user
Click on submit 
Now we can try to create an ADF screen for login screen.Create a managed bean as below :

package view;

import java.io.IOException;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

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 weblogic.security.SimpleCallbackHandler;
import weblogic.security.services.Authentication;

import weblogic.servlet.security.ServletAuthentication;


public class LoginPageName {
    private String username;
    private String password;

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUsername() {
        return username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }
    
    public String doLogin() {
                String un = username;
        byte[] pw = password.getBytes();
        FacesContext ctx = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) ctx.getExternalContext().getRequest();
        CallbackHandler handler = new SimpleCallbackHandler(un, pw);
        try {
            Subject mySubject = Authentication.login(handler);
            ServletAuthentication.runAs(mySubject, request);
            ServletAuthentication.generateNewSessionID(request);
            System.out.println(" Here :"+ctx.getViewRoot().getViewId());
            String loginUrl = "/adfAuthentication?success_url=/faces" +ctx.getViewRoot().getViewId();
            HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();

            sendForward(request, response, loginUrl);
        } catch (FailedLoginException e) {
            FacesMessage msg =
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "Incorrect user name or password",
                                 "Incorrect user name or password was specified");
            ctx.addMessage(null, msg);
        } catch (LoginException e) {
            e.printStackTrace();
        }
        return null;

    }

    public void sendForward(HttpServletRequest request, HttpServletResponse response, String forwardUrl) {
        System.out.println("Forwarding ..."+forwardUrl);
       FacesContext ctx = FacesContext.getCurrentInstance();
      
        RequestDispatcher dis = request.getRequestDispatcher(forwardUrl);
        try {
            dis.forward(request, response);
        } catch (IOException e) {
            reportUnexpectedLoginError("IOException Exception",e);
            e.printStackTrace();
        } catch (ServletException e) {
            reportUnexpectedLoginError("ServletException ",e);
            e.printStackTrace();
        }
ctx.responseComplete();
    }

    public void reportUnexpectedLoginError(String errorType, Exception e) {
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Unexpected Error during login","Error type ="+errorType);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

}

In the UI project add the Weblogic Remote client Library


Add the managed bean to the request scope 

Create loginPage.jspx withe username and password field 

<?xml version='1.0' encoding='UTF-8'?>
<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=UTF-8"/>
    <f:view>
        <af:document title="mypage.jspx" id="d1">
            <af:form id="f1">
                <af:link text="#{securityContext.authenticated?'Log out':'Login in'}" id="l1"
                         destination="#{securityContext.authenticated?'/adfAuthentication?logout=true&amp;amp;end_url=/faces/welcome.jspx':'/adfAuthentication?success_url=/faces/welcome.jspx'}"/>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

Create loginError.jspx for displaying errors. Make changes in the web.xml as below


Run the mypage.jspx and this will redirect to loginPage.jspx and you can see the web page as below

Login using the user defined in the jazn-data.xml and you can view the mypage.jspx with Logout link.

Tuesday, July 23, 2013

ADF Security Basics part 5:Entitlement Grants

Grouping of roles and resources:

Created the role app-role3.


Created a the page entitlementRole.jspx and created the pageDef of this file.



For multiple resource sake ,created a bounded task flow 


Created the testE1.jspx file to test the task flow


Adding the resources to the entitlement grant


Multiple resource granted entitlement grant 


The resources grant to role 


jazn-data.xml changes will looks like below 
Access entitlementRole.jspx page 
Access the testE1.jspx 


Monday, July 22, 2013

ADF Security Basics part 4:Applying Security Policy on Entity Ojbects

I have created following roles into jazn-data.xml

app-role1 :


app-role2:



Go to the security section of the Enity Object from the General tab.



Setting the security in the attribute level  for the Phone Number attribute



Setting the security in the attribute level for Email


From the jazn-data.xml editor assign the update permission to the app-role1 and app-role2





For the attribute phone number :



For the attribute Email :


Create a ADF form with the updatable VO in secureData.jspx page.


Secure the page secureData.jspx Assign view permission to both app-role1 and app-role2


Login as app-role2 and see the Email is read-only






Login as app-role1 and see the Phone Number disabled :