Code Monkey home page Code Monkey logo

play-spike's Introduction

play-spike

This is a spike to demonstrate how we use Java Playframework 2.5 with LDAP authentication and JPA with mySQL. It is just a simple login screen and then the user personal details upon login success. You can either browse the code to see how it is done or see the app in action by following the steps below.

How this app works

  1. If you access any link without having logged in, a filter (AuthorizationFilter.java) is put in place to intercept every http request and check that the user name is present in the session cookie. If it is not, you will be directed to a login page.

  2. When you fill in the login form and submit, the credentials will be authenticated against the ldap database (ActiveDirectoryService.java). A session cookie is created of successful authentication (Play gives you integrity protection for session, more detail from https://www.playframework.com/documentation/2.5.x/ScalaSessionFlash)

  3. Once successfully logged in, you are taken to the welcome page, which will show you the logged in user's personal detail (name, age) retrieved from mySql (PersonService.java, here we show how to retrieve the information using both Hibernate ORM and JPA)

Pre-requisite

  1. Install OpenLdap
  1. Install mySql
  • detailed instructions can be found at https://dev.mysql.com/downloads/installer/
  • Once mySql has been installed, create a schema with the following table:
    CREATE TABLE person (id MEDIUMINT not null auto_increment, 
                          name VARCHAR(40), 
                          age INT(10), 
                          username VARCHAR(20), 
                          PRIMARY KEY (id));
                          
    INSERT INTO person (name, age, username) VALUES('Jane Smith', 30, <the ldap username created>);
    
  1. Install Play activator from https://www.playframework.com/download

  2. Ensure you have JDK and JRE 1.8 on your machine

  3. Clone this project

  4. Modify application.conf to reflect the mySQL connection settings that you created in step 2

  5. Modify ActiveDirectoryService.java to have the ldap settings that you created in step 3

Run the app (using activator)

  1. Start up activator:
  • For linux/unix: ./<activator installation>/bin/activator ui
  • For windows: <activator installation>/bin/activator.bat ui
  1. Register the app:
  • Load the activator ui (usually at http://localhost:8888)
  • Select the folder icon in 'Open existing app'
  • Navigate to the play-spike folder that you just cloned
  • Select 'Choose'
  • The app should be loaded
  1. Run the app:
  • Once the play-spike app has been loaded, select 'Run' on the menu and click on the 'Run' icon. You should see the server started up on localhost:9000 (by default)

Run the app (using sbt command)

  1. Ensure you download and install sbt http://www.scala-sbt.org/download.html. Ensure you can execute sbt command
  2. cd <directory where you cloned the code>/play-spike
  3. Type sbt. SBT will load up your project settings and compile everything, it may take a while to be ready on first start.
  4. In the sbt shell type run. Your server should start up on localhost:9000

Other Resources

  1. Play tutorials: https://www.playframework.com/documentation/2.5.x/Tutorials
  2. Ldaptive authentication: http://www.ldaptive.org/

play-spike's People

Contributors

thaodang avatar nhabuiduc avatar

Stargazers

 avatar Stephan Dowding avatar  avatar

Watchers

James Cloos avatar  avatar Stephan Dowding avatar

Forkers

thoughtworksinc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.