Commit 602ea7c5 by Jan Hrabal

roles

parent a70bfc2e
...@@ -8,9 +8,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -8,9 +8,7 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 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.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.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
...@@ -96,4 +94,9 @@ public class JhSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -96,4 +94,9 @@ public class JhSecurityConfig extends WebSecurityConfigurerAdapter {
return new AppUserRepository(); return new AppUserRepository();
} }
// @Bean
// public GrantedAuthorityDefaults grantedAuthorityDefaults() {
// return new GrantedAuthorityDefaults(""); // Remove the ROLE_ prefix
// }
} }
...@@ -8,8 +8,6 @@ import javax.persistence.Column; ...@@ -8,8 +8,6 @@ import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import org.springframework.security.core.GrantedAuthority;
import com.jh.boot.jpa.AbstractIdEntity; import com.jh.boot.jpa.AbstractIdEntity;
/** /**
...@@ -19,7 +17,7 @@ import com.jh.boot.jpa.AbstractIdEntity; ...@@ -19,7 +17,7 @@ import com.jh.boot.jpa.AbstractIdEntity;
*/ */
@Entity @Entity
@Table(name = "APP_ROLE") @Table(name = "APP_ROLE")
public class AppRole extends AbstractIdEntity implements GrantedAuthority { public class AppRole extends AbstractIdEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -47,9 +45,4 @@ public class AppRole extends AbstractIdEntity implements GrantedAuthority { ...@@ -47,9 +45,4 @@ public class AppRole extends AbstractIdEntity implements GrantedAuthority {
this.name = name; this.name = name;
} }
@Override
public String getAuthority() {
return getName();
}
} }
...@@ -3,7 +3,9 @@ package com.jh.boot.security.service; ...@@ -3,7 +3,9 @@ package com.jh.boot.security.service;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -58,7 +61,9 @@ public class AppUserAuthService implements AuthService { ...@@ -58,7 +61,9 @@ public class AppUserAuthService implements AuthService {
//initialize roles //initialize roles
user.initRolesMap(); 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; 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