Commit 602ea7c5 by Jan Hrabal

roles

parent a70bfc2e
......@@ -8,9 +8,7 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Bean;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.AuthenticationException;
......@@ -96,4 +94,9 @@ public class JhSecurityConfig extends WebSecurityConfigurerAdapter {
return new AppUserRepository();
}
// @Bean
// public GrantedAuthorityDefaults grantedAuthorityDefaults() {
// return new GrantedAuthorityDefaults(""); // Remove the ROLE_ prefix
// }
}
......@@ -8,8 +8,6 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.springframework.security.core.GrantedAuthority;
import com.jh.boot.jpa.AbstractIdEntity;
/**
......@@ -19,7 +17,7 @@ import com.jh.boot.jpa.AbstractIdEntity;
*/
@Entity
@Table(name = "APP_ROLE")
public class AppRole extends AbstractIdEntity implements GrantedAuthority {
public class AppRole extends AbstractIdEntity {
private static final long serialVersionUID = 1L;
......@@ -47,9 +45,4 @@ public class AppRole extends AbstractIdEntity implements GrantedAuthority {
this.name = name;
}
@Override
public String getAuthority() {
return getName();
}
}
......@@ -3,7 +3,9 @@ package com.jh.boot.security.service;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
......@@ -58,7 +61,9 @@ public class AppUserAuthService implements AuthService {
//initialize roles
user.initRolesMap();
AppUserAuthentication auth = new AppUserAuthentication(user, user.getRoles());
Set<SimpleGrantedAuthority> authorities = user.getRoles().stream().map(r -> new SimpleGrantedAuthority("ROLE_" + r.getName())).collect(Collectors.toSet());
AppUserAuthentication auth = new AppUserAuthentication(user, authorities);
return auth;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment