Initialize OPSS values.

This commit is contained in:
Paulo Gustavo Veiga 2013-03-19 23:18:19 -03:00
parent 617abd9d90
commit e0a6d15ad0

View File

@ -61,7 +61,7 @@ public class UserDetailsService
final User result; final User result;
if (dbUser != null) { if (dbUser != null) {
if (!token.getIdentityUrl().equals(dbUser.getAuthenticatorUri())) { if (!token.getIdentityUrl().equals(dbUser.getAuthenticatorUri())) {
throw new UsernameNotFoundException("Identity url for this user can not change:" + token.getIdentityUrl()); throw new IllegalStateException("Identity url for this user can not change:" + token.getIdentityUrl());
} }
result = dbUser; result = dbUser;
} else { } else {
@ -82,25 +82,40 @@ public class UserDetailsService
private User buildUserFromToken(@NotNull OpenIDAuthenticationToken token) { private User buildUserFromToken(@NotNull OpenIDAuthenticationToken token) {
final User result = new User(); final User result = new User();
String lastName = null;
String firstName = null;
String email = null;
String fullName = null;
final List<OpenIDAttribute> attributes = token.getAttributes(); final List<OpenIDAttribute> attributes = token.getAttributes();
for (OpenIDAttribute attribute : attributes) { for (OpenIDAttribute attribute : attributes) {
if (attribute.getName().equals("email")) { if (attribute.getName().equals("email")) {
final String email = attribute.getValues().get(0); email = attribute.getValues().get(0);
result.setEmail(email);
} }
if (attribute.getName().equals("firstname")) { if (attribute.getName().equals("firstname")) {
final String firstName = attribute.getValues().get(0); firstName = attribute.getValues().get(0);
result.setFirstname(firstName);
} }
if (attribute.getName().equals("lastname")) { if (attribute.getName().equals("lastname")) {
final String lastName = attribute.getValues().get(0); lastName = attribute.getValues().get(0);
}
if (attribute.getName().equals("fullName")) {
fullName = attribute.getValues().get(0);
}
}
if (lastName == null || firstName == null) {
result.setFirstname(fullName);
result.setLastname("");
} else {
result.setLastname(lastName); result.setLastname(lastName);
result.setFirstname(firstName);
} }
result.setEmail(email);
result.setPassword(""); result.setPassword("");
}
final Calendar now = Calendar.getInstance(); final Calendar now = Calendar.getInstance();
result.setActivationDate(now); result.setActivationDate(now);