0% found this document useful (0 votes)
58 views5 pages

16 Homework Java, Academic Year 2013./2014. Fer: Id Firstname Lastname Nick Email Passwordhash

This document provides instructions for a homework assignment to develop a Java web application that implements a blog system using JPA. Students are tasked with integrating previous code with new requirements to build out functionality for user registration, login, viewing blog posts and adding/editing posts. This includes adding a BlogUser domain class to model users, handling authentication on login by checking stored password hashes, and implementing the page flow specified in a diagram. Testing and project configuration are also required.

Uploaded by

Sven Vidak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views5 pages

16 Homework Java, Academic Year 2013./2014. Fer: Id Firstname Lastname Nick Email Passwordhash

This document provides instructions for a homework assignment to develop a Java web application that implements a blog system using JPA. Students are tasked with integrating previous code with new requirements to build out functionality for user registration, login, viewing blog posts and adding/editing posts. This includes adding a BlogUser domain class to model users, handling authentication on login by checking stored password hashes, and implementing the page flow specified in a diagram. Testing and project configuration are also required.

Uploaded by

Sven Vidak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

16

th
homework; JAVA, Academic year 2013./2014.; FER
Introduction
For this homework you will integrate the structured web-application which is described in document
java_tecaj_11_prezentacija_uputa.txt which is available in Ferko's repository with a JPA-based
implementation of blog system !et this new web application's name be aplikacija5 so that it will be
available using an "#! such as http$%%localhost$&'&'%aplikaci(a) *nce you finish the application+ you will
prepare a ,-P archive of your eclipse pro(ect and upload it to Ferko .please note that in the document
java_tecaj_11_prezentacija_uputa.txt this aplication is named aplikacija4 so do not simply copy
everything from this document but instead replace names where needed/
Problem 1.
-f you still did not complete the simple web application described in te0t file we used during last lecture+
complete it .1ekci(a 2 describes the structure of web-application3 however+ you must have all previous
configuration details implemented+ such as 4
nd
-level caching3 you don't need command-line e0amples in this
web-application/
Problem 2.
As part of this problem you will implement a simple user-management functionality for your blog website
Add new domain class BlogUser modeling a single user .place it into the same package as all other domain
classes/ For each blog user you should track following properties$ id+ firstName+ lastName+ nick+ email and
passwordHash
For e0ample+ some user can have firstName=Pero+ lastName=Peri+ nick=perica+
email=pp5somecom and passwordHash=22ffc727b16!eac"7#$!%d26$%dec%%1%1!ec! Property
passwordHash is used for storing storing a he0-encoded hash value .calculated as 16A-7 hash/ obtained
from users password .you have already created a code for hashing binary data in one of your previous
homeworks 8 search for &essage'igest() 9ou are not allowed to store users' passwords in plain te0t into
database since this would allow a database admin .and anyone who obtain the access to database/ to easily
see and steal users' passwords -nstead+ during a user registration process you will$
7 ask a user to provide a nick and password+
2) ep = calc+late he,-ncode.calcHash.password((
: store ep in database as passwordHash
Also treat nick property as uni;ue$ no two users are allowed to have same nicks .set appropriate domain
constraint3 also check during the registration if user with given nickname already e0ists+ and if it does+ show
user appropriate message and ask him to choose different nickname/
<uring a user's login process .handled by /ser0leti/main servlet+ see diagram on the ne0t page/+ you will$
7 ask user to provide nick and password+
4 calculate ep = calc+late he,-ncode.calcHash.password((+
: lookup user in database with provided nick+
2 compare stored passwordHash and calculated ep for match
-f comparison does not match+ display appropriate error message+ and render login form again but without
provided password .username which the user provided should be filled in the form automatically/
=odify domain class Blog-ntr1$ add property creator which will reference the BlogUser that created the
entry =ake that relation bidirectional
Problem 3.
9ou will ad(ust e0isting code and implement whats missing to obtain a web application with page-flow as
given on following diagram
Main page:
/servleti/main
Login form for
existing users:
* nick
* password
List of registered
authors.
Link to
registration page
for new users.
Registration page:
/servleti/register
Registration form
for new users:
* firstName
* lastName
* email
* nick
* password
Blog entries list page:
/servleti/author/N!"
List of titles of
#logentries for
author with
provided N!" in
$RL rendered as
links
%hown onl& if
logged in user
has provided nick:
link for adding
new #log entr&
Blog entr& page:
/servleti/author/N!"/'(
%how selected
#log entr& )with
id*'(+, title -
text
%hown onl& if
logged in user
has provided nick:
link for #log entr&
editing
%how comments
%how form for
adding new
comment
New/'dit #log entr& page:
/servleti/author/N!"/new
/servleti/author/N!"/edit
%hown onl& if
logged in user
has provided nick:
form allowing
editing selected
#log entr& or
creation of new
entr&.
'lse show error
index./sp
9ou should create a servlet that will be mapped on /inde,)2sp and that will send to a client a redirection
to page /ser0leti/main .in your web application conte0t+ of course/ For e0ample+ if your application is
deployed as aplikacija4+ writing http3//localhost3!"!"/aplikaci2a should produce redirection to
http3//localhost3!"!"/aplikaci2a/ser0leti/main
For our demo user perica+ re;uesting$
http$%%localhost$&'&'%aplikaci(a2%servleti%author% perica
should bring a page with titles .and links/ of all of his blog entries+ while re;uesting$
http$%%localhost$&'&'%aplikaci(a2%servleti%author% perica%)
should bring a page with blog entry with id=$ .assuming that the creator of that entry is indeed perica/ 8 if
not+ produce an error
>he general idea of our application is that all users$ anonymous and logged-in should see e0actly the same
page structure 6owever+ logged in users also see additional functionality$ adding a new blog entry on his
blog page and editing his blog entries
Anonymous users can obtain an account by filling in registration form 8 no restrictions should apply beside
the fact that two users can not have the same nick
-n previous picture only a rough structure is presented .with some e0amples of "#!s/3 all that is missing is
left to you to implement as you deem appropriate .including parameters+ back links+ etc/
-n a case where you wish to map a servlet to a partial "#! .for e0ample+ to any "#! that starts by
/ser0leti/a+thor regardless of which path was provided after that/+ you can get information on actual "#!
that triggered the servlet .for e0ample+ /ser0leti/a+thor/perica+ /ser0leti/a+thor/perica/$+
/ser0leti/a+thor/perica/new etc/ using Http4er0let5e6+est methods get4er0letPath.( and
getPath7nfo.( >ake a look at these methods and what they return
http$%%docsoraclecom%(avaee%?%api%(ava0%servlet%http%6ttp1ervlet#e;uesthtml@get1ervletPathA4&A4B
http$%%docsoraclecom%(avaee%?%api%(ava0%servlet%http%6ttp1ervlet#e;uesthtml@getPath-nfoA4&A4B
Handling of the login process
Please observe that information on users is now stored in our web applications database >hat means that we
alone will handle authentication and authoriCation >his is what you should do
Dhen user provides nick and password+ you will check them and if user is valid you will store BlogUser)id
into current session .use+ for e0ample+ key c+rrent)+ser)id/3 additionally+ store current user nick+ first
name and last name under keys c+rrent)+ser)fn+ c+rrent)+ser)ln and c+rrent)+ser)nick
Each action that needs to check if there is logged-in user will simply check if there is currentuserid in
session map -f no+ we are working with anonymous user that can only browse all blogs and blog entries and
add comments -f there is such key stored+ we have logged-in user whose other commonly-used information
can also obtained from session map
Handling of the logout process
9ou should add to main page also a logout link 1tarting associated action should simply invalidate current
session .see Http4er0let5e6+est)get4ession.()in0alidate.(/ and send back redirection to
/ser0leti/main .(ust as servlet mapped to /inde,)2sp did/
http$%%docsoraclecom%(avaee%?%api%(ava0%servlet%http%6ttp1ervlet#e;uesthtml
http$%%docsoraclecom%(avaee%?%api%(ava0%servlet%http%6ttp1essionhtml
Additional note:
-n header of each rendered page .not in FheadGF%headG of 6>=! itself but in visual header 8 top of
rendered page/ please write first name and last name of loged-in user or not loged in+ and provide link for
logout .if user is loged-in/
Any graphical design .eg H11 styles/ is optional Also+ you don't have to implement editing of users profile
.eg allowing user to change fist name+ last name+ email or password/
Finally+ anything that is not strictly prescribed in this document you are free to solve as you deem
appropriate 6owever+ please note that you are e0pected to create a high-;uality code and an application that
is layered and conceptually clear+ (ust as we e0plained on lectures and in previous homework
Also+ it is e0pected that by default+ persistence.xml is configured to use$
Url: (dbc$derby$%%localhost$7)4I%blogJaCa
Username: blog<JAdmin
Password: blog<JPassword
Please note. 9ou can consult with your peers and e0change ideas about this homework before you start
actual coding *nce you open you -<E and start coding+ consultations with others .e0cept with me/ will be
regarded as cheating 9ou can not use any of pree0isting code or libraries for this homework .whether it is
yours old code or someones else/+ unless it is one of the libraries or your old homework - e0plicitly
mentioned in previous problems <ocument your codeK
-n order to solve this homework+ create a blank Eclipse Java Pro(ect and write your code inside *nce you
are done+ e0port pro(ect as a ,-P archive and upload this archive on Ferko before the deadline <o not forget
to lock your upload or upload will not be accepted
E;uip the pro(ect with appropriate b+ild),ml) 9ou must add war target that will automatically create
complete DA# file
9ou are re;uired to create at least one unit test .for whatever you wish/
Jefore uploading+ please make double sure that a working DA# can be build from console by ant Please
take special care not to embed any absolute paths in your code or in scripts 8 different users will have
tomcat installed at different places 9our pro(ect name must be HW16-yourJMBAG
>he deadline for uploading and locking this homework is July+ &
th
4'72 at 77$)B P=

You might also like