Created
March 2, 2014 05:27
-
-
Save sivaprasadreddy/9302340 to your computer and use it in GitHub Desktop.
SecurityUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sivalabs.springapp.web.config; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.Set; | |
import org.springframework.security.core.GrantedAuthority; | |
import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
import org.springframework.security.core.userdetails.UserDetails; | |
import com.sivalabs.springapp.entities.Role; | |
import com.sivalabs.springapp.entities.User; | |
public class SecurityUser extends User implements UserDetails | |
{ | |
private static final long serialVersionUID = 1L; | |
public SecurityUser(User user) { | |
if(user != null) | |
{ | |
this.setId(user.getId()); | |
this.setName(user.getName()); | |
this.setEmail(user.getEmail()); | |
this.setPassword(user.getPassword()); | |
this.setDob(user.getDob()); | |
this.setRoles(user.getRoles()); | |
} | |
} | |
@Override | |
public Collection<? extends GrantedAuthority> getAuthorities() { | |
Collection<GrantedAuthority> authorities = new ArrayList<>(); | |
Set<Role> userRoles = this.getRoles(); | |
if(userRoles != null) | |
{ | |
for (Role role : userRoles) { | |
SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.getRoleName()); | |
authorities.add(authority); | |
} | |
} | |
return authorities; | |
} | |
@Override | |
public String getPassword() { | |
return super.getPassword(); | |
} | |
@Override | |
public String getUsername() { | |
return super.getEmail(); | |
} | |
@Override | |
public boolean isAccountNonExpired() { | |
return true; | |
} | |
@Override | |
public boolean isAccountNonLocked() { | |
return true; | |
} | |
@Override | |
public boolean isCredentialsNonExpired() { | |
return true; | |
} | |
@Override | |
public boolean isEnabled() { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment