SEC-2915: Updated Java Code Formatting
This commit is contained in:
@@ -12,36 +12,35 @@ import org.springframework.security.core.userdetails.User;
|
||||
* @since 3.1
|
||||
*/
|
||||
public class CustomUserDetails extends User {
|
||||
private String email;
|
||||
private String name;
|
||||
private boolean newUser;
|
||||
private String email;
|
||||
private String name;
|
||||
private boolean newUser;
|
||||
|
||||
public CustomUserDetails(String username, Collection<GrantedAuthority> authorities) {
|
||||
super(username, "unused", authorities);
|
||||
}
|
||||
public CustomUserDetails(String username, Collection<GrantedAuthority> authorities) {
|
||||
super(username, "unused", authorities);
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public boolean isNewUser() {
|
||||
return newUser;
|
||||
}
|
||||
public boolean isNewUser() {
|
||||
return newUser;
|
||||
}
|
||||
|
||||
public void setNewUser(boolean newUser) {
|
||||
this.newUser = newUser;
|
||||
}
|
||||
public void setNewUser(boolean newUser) {
|
||||
this.newUser = newUser;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,94 +14,97 @@ import org.springframework.security.openid.OpenIDAttribute;
|
||||
import org.springframework.security.openid.OpenIDAuthenticationToken;
|
||||
|
||||
/**
|
||||
* Custom UserDetailsService which accepts any OpenID user, "registering" new users in a map so they can be welcomed
|
||||
* back to the site on subsequent logins.
|
||||
* Custom UserDetailsService which accepts any OpenID user, "registering" new users in a
|
||||
* map so they can be welcomed back to the site on subsequent logins.
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @since 3.1
|
||||
*/
|
||||
public class CustomUserDetailsService implements UserDetailsService, AuthenticationUserDetailsService<OpenIDAuthenticationToken> {
|
||||
public class CustomUserDetailsService implements UserDetailsService,
|
||||
AuthenticationUserDetailsService<OpenIDAuthenticationToken> {
|
||||
|
||||
private final Map<String, CustomUserDetails> registeredUsers = new HashMap<String, CustomUserDetails>();
|
||||
private final Map<String, CustomUserDetails> registeredUsers = new HashMap<String, CustomUserDetails>();
|
||||
|
||||
private static final List<GrantedAuthority> DEFAULT_AUTHORITIES = AuthorityUtils.createAuthorityList("ROLE_USER");
|
||||
private static final List<GrantedAuthority> DEFAULT_AUTHORITIES = AuthorityUtils
|
||||
.createAuthorityList("ROLE_USER");
|
||||
|
||||
/**
|
||||
* Implementation of {@code UserDetailsService}. We only need this to satisfy the {@code RememberMeServices}
|
||||
* requirements.
|
||||
*/
|
||||
public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException {
|
||||
UserDetails user = registeredUsers.get(id);
|
||||
/**
|
||||
* Implementation of {@code UserDetailsService}. We only need this to satisfy the
|
||||
* {@code RememberMeServices} requirements.
|
||||
*/
|
||||
public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException {
|
||||
UserDetails user = registeredUsers.get(id);
|
||||
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException(id);
|
||||
}
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException(id);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@code AuthenticationUserDetailsService} which allows full access to the submitted
|
||||
* {@code Authentication} object. Used by the OpenIDAuthenticationProvider.
|
||||
*/
|
||||
public UserDetails loadUserDetails(OpenIDAuthenticationToken token) {
|
||||
String id = token.getIdentityUrl();
|
||||
/**
|
||||
* Implementation of {@code AuthenticationUserDetailsService} which allows full access
|
||||
* to the submitted {@code Authentication} object. Used by the
|
||||
* OpenIDAuthenticationProvider.
|
||||
*/
|
||||
public UserDetails loadUserDetails(OpenIDAuthenticationToken token) {
|
||||
String id = token.getIdentityUrl();
|
||||
|
||||
CustomUserDetails user = registeredUsers.get(id);
|
||||
CustomUserDetails user = registeredUsers.get(id);
|
||||
|
||||
if (user != null) {
|
||||
return user;
|
||||
}
|
||||
if (user != null) {
|
||||
return user;
|
||||
}
|
||||
|
||||
String email = null;
|
||||
String firstName = null;
|
||||
String lastName = null;
|
||||
String fullName = null;
|
||||
String email = null;
|
||||
String firstName = null;
|
||||
String lastName = null;
|
||||
String fullName = null;
|
||||
|
||||
List<OpenIDAttribute> attributes = token.getAttributes();
|
||||
List<OpenIDAttribute> attributes = token.getAttributes();
|
||||
|
||||
for (OpenIDAttribute attribute : attributes) {
|
||||
if (attribute.getName().equals("email")) {
|
||||
email = attribute.getValues().get(0);
|
||||
}
|
||||
for (OpenIDAttribute attribute : attributes) {
|
||||
if (attribute.getName().equals("email")) {
|
||||
email = attribute.getValues().get(0);
|
||||
}
|
||||
|
||||
if (attribute.getName().equals("firstname")) {
|
||||
firstName = attribute.getValues().get(0);
|
||||
}
|
||||
if (attribute.getName().equals("firstname")) {
|
||||
firstName = attribute.getValues().get(0);
|
||||
}
|
||||
|
||||
if (attribute.getName().equals("lastname")) {
|
||||
lastName = attribute.getValues().get(0);
|
||||
}
|
||||
if (attribute.getName().equals("lastname")) {
|
||||
lastName = attribute.getValues().get(0);
|
||||
}
|
||||
|
||||
if (attribute.getName().equals("fullname")) {
|
||||
fullName = attribute.getValues().get(0);
|
||||
}
|
||||
}
|
||||
if (attribute.getName().equals("fullname")) {
|
||||
fullName = attribute.getValues().get(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (fullName == null) {
|
||||
StringBuilder fullNameBldr = new StringBuilder();
|
||||
if (fullName == null) {
|
||||
StringBuilder fullNameBldr = new StringBuilder();
|
||||
|
||||
if (firstName != null) {
|
||||
fullNameBldr.append(firstName);
|
||||
}
|
||||
if (firstName != null) {
|
||||
fullNameBldr.append(firstName);
|
||||
}
|
||||
|
||||
if (lastName != null) {
|
||||
fullNameBldr.append(" ").append(lastName);
|
||||
}
|
||||
fullName = fullNameBldr.toString();
|
||||
}
|
||||
if (lastName != null) {
|
||||
fullNameBldr.append(" ").append(lastName);
|
||||
}
|
||||
fullName = fullNameBldr.toString();
|
||||
}
|
||||
|
||||
user = new CustomUserDetails(id, DEFAULT_AUTHORITIES);
|
||||
user.setEmail(email);
|
||||
user.setName(fullName);
|
||||
user = new CustomUserDetails(id, DEFAULT_AUTHORITIES);
|
||||
user.setEmail(email);
|
||||
user.setName(fullName);
|
||||
|
||||
registeredUsers.put(id, user);
|
||||
registeredUsers.put(id, user);
|
||||
|
||||
user = new CustomUserDetails(id, DEFAULT_AUTHORITIES);
|
||||
user.setEmail(email);
|
||||
user.setName(fullName);
|
||||
user.setNewUser(true);
|
||||
user = new CustomUserDetails(id, DEFAULT_AUTHORITIES);
|
||||
user.setEmail(email);
|
||||
user.setName(fullName);
|
||||
user.setNewUser(true);
|
||||
|
||||
return user;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user