セッションでユーザ名を取得する方法について疑問があります。私は私のクラスUsuarioを持って春のセキュリティ4.2セッションでユーザ名を取得するSpring Security
を使用しています
@Entity
@Data
public class Usuario {
@Id @GeneratedValue
private Integer id;
private String login;
private String senha;
private String papel;
}
私のクラスUsuarioController
@Named
@ViewScoped
public class UsuarioController {
@Autowired
private UsuarioRepository usuarioRepository;
@Getter @Setter
private List<Usuario> usuarios;
@Getter @Setter
private Usuario usuario = new Usuario();
}
とフィルターの役割を果たしている私のクラスSecurityConfig、すでに春のセキュリティに組み込まれています。
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UsuarioRepository usuarioRepository;
@Override
protected void configure(HttpSecurity http) {
try {
http.csrf().disable();
http
.userDetailsService(userDetailsService())
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/cliente.jsf").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login.jsf")
.permitAll()
.failureUrl("/login.jsf?error=true")
.defaultSuccessUrl("/cliente.jsf")
.and()
.logout()
.logoutSuccessUrl("/login.jsf");
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
}
@Override
protected UserDetailsService userDetailsService() {
List<Usuario> usuarios = usuarioRepository.findAll();
List<UserDetails> users = new ArrayList<>();
for(Usuario u: usuarios){
UserDetails user = new User(u.getLogin(), u.getSenha(), AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_"+u.getPapel()));
users.add(user);
} return new InMemoryUserDetailsManager(users);
}
}
フォーラムで他の投稿を既に調査しましたが、ヒントはありませんでした。別のクラスを作成する必要がありますか?
CDI/JSFのために間違った組み合わせを使用しています'@ Named'と' @ Viewsoped'の組み合わせです。 1つは「CDI」で、もう1つは「JSF」です。それがsprimgのためにそのように働くならば、問題は決してjsf関連ではありません。 – Kukeltje
こんにちはKukeltje、そして何が正しいフォームでしょうか? – Genn
通常、私はgoogleを試してみたいと思いますが、気分は良いです:https://stackoverflow.com/questions/14384369/how-to-replace-managedbean-viewscope-by-cdi-in-jsf-2 -0-2-1 – Kukeltje