You are on page 1of 1

Chapter 8

Adding OpenID users


As we do not yet have OpenID-enabled new user registration, we'll need to
preemptively add the user account to our existing users. To do this you will need to
update the calendar-data.sql file to include your OpenID. For example, if your
OpenID is http://springsecurity31.myopenid.com/, then you will want to
update one of the insert statements to use your OpenID as shown next:
src/main/resources/database/h2/calendar-data.sql

insert into calendar_users(


id,openid,
email,password,first_name,last_name)
values (
0,'http://springsecurity31.myopenid.com/',
'user1@example.com','user1','User','1'
);

You'll note that this is similar to our traditional username and password-based
admin account, with the exception that we have added an additional column for the
OpenID to act as another alias for the user.

CalendarUserDetailsService lookup by
OpenID
We have included code from the custom authentication we did in Chapter 3,
Custom Authentication. Previously, we linked Spring Security's UserDetails to our
CalendarUser using its e-mail property. However, the username will now be an
OpenID rather than an e-mail,
so we need to update our CalendarUserDetailsService to lookup the
CalendarUser user by OpenID. Go ahead and make the following changes:

src/main/java/com/packtpub/springsecurity/core/userdetails/
CalendarUserDetailsService.java

public UserDetails loadUserByUsername(String username) {


CalendarUser user = calendarUserDao.findUserByOpenid(username);
...
}

Your code should look like chapter08.01-calendar.

[ 195 ]

You might also like