Será que não seria pedir muito se vc colocasse ai pra mim ver quais sao as classes e arquivos de xml vc tem?
Por exemplos eu tenho assim
-model
-----usuario
-----papel
-----atividade
–seguranca
------MyFilterSecurityMetadataSource
------UserDetailsAdapter
------UserDetailsServiceImpl
usuario
@NamedQueries({
@NamedQuery(name = "Usuario.BuscaUsersByUsernameEqualsPasswordEquals",
query = "SELECT o FROM Usuario o WHERE o.username = :p0 AND o.password = :p1"),
@NamedQuery(name = "Usuario.BuscaUsersByUsernameEquals",
query = "SELECT o FROM Usuario o WHERE o.username = :p0")
})
@Entity
@Table(name = "usuario")
public class Usuario extends gov.sefaz.utils.entidade.EntidadeBase {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
private String nome;
private String username;
private String password;
private String email;
private Boolean ativo;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "ultimo_acesso")
private Date ultimoAcesso;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "acesso_atual")
private Date acessoAtual;
@ManyToMany(cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER)
private Set<Papel> papel = new HashSet<Papel>();
@Version
@Column(name = "versao")
private Integer versao;
--.....
papel
@Entity
@Table(name = "papel")
public class Papel extends gov.sefaz.utils.entidade.EntidadeBase {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
@Column(name = "nome", nullable = false, length = 64)
private String nome;
@Version
@Column(name = "versao")
private Integer versao;
....
atividade
[code]
@NamedQueries({
@NamedQuery(name = “Atividade.BuscaAtividadeByPapelEquals”,
query = “SELECT o FROM Atividade o JOIN o.papel p WHERE p.id = :p0 ORDER BY o.ordem ASC”),
@NamedQuery(name = “Atividade.BuscaAtividadeByRaiz”,
query = “SELECT o FROM Atividade o JOIN o.papel p WHERE o.parente is null AND p.id = :p0 ORDER BY o.ordem ASC”)
})
@Entity
@Table(name = “atividade”)
public class Atividade extends gov.sefaz.utils.entidade.EntidadeBase {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "nome", nullable = false,length=64)
private String nome;
@Column(name = "url", length=255)
private String url;
@Column(name = "ordem", nullable = false,length=16)
private String ordem;
@ManyToOne
@JoinColumn(name = "id_atv_pai", referencedColumnName = "id")
private Atividade parente;
@OneToMany(mappedBy = "parente", fetch=FetchType.EAGER)
private List<Atividade> subAtividades;
@ManyToMany
private Set<Papel> papel = new HashSet<Papel>();
@Version
@Column(name="versao")
private Integer versao;[/code]
MyFilterSecurityMetadataSource ficou assim
[code]public class MyFilterSecurityMetadataSource implements FilterInvocationSecurityMetadataSource {
@Autowired
private INfeGerencialBO ejbFacade;
private FilterInvocation objFilter;
public List<ConfigAttribute> getAttributes(Object object) {
if ((object == null) || !this.supports(object.getClass())) {
throw new IllegalArgumentException(
"Object must be a FilterInvocation");
}
String url = ((FilterInvocation) object).getRequestUrl();
String method = ((FilterInvocation) object).getHttpRequest()
.getMethod();
objFilter = (FilterInvocation) object;
return lookupAttributes(url, method);
}
private List<ConfigAttribute> lookupAttributes(String url, String method) {
// TODO Auto-generated method stub
return null;
}
public Collection<ConfigAttribute> getAllConfigAttributes() {
return null;
}
public boolean supports(Class<?> clazz) {
return FilterInvocation.class.isAssignableFrom(clazz);
}
}[/code]
UserDetailsAdapter
[code]
@Service(“userDetailsAdapter”)
public class UserDetailsAdapter {
private Long id;
org.springframework.security.core.userdetails.User buildUserFromUserEntity(Usuario userEntity) {
String username = userEntity.getUsername();
String password = userEntity.getPassword();
boolean enabled = userEntity.getAtivo();
boolean accountNonExpired = true;
boolean credentialsNonExpired = true;
boolean accountNonLocked = true;
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
Iterator<Papel> papeis = userEntity.getPapel().iterator();
while (papeis.hasNext()) {
Papel papel = papeis.next();
authorities.add(new GrantedAuthorityImpl(papel.getNome()));
}
/*this.id = userEntity.getId();*/
org.springframework.security.core.userdetails.User user = new org.springframework.security.core.userdetails.User(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
return user;
}
public Long getId() {
return id;
}
}[/code]
UserDetailsServiceImpl
package gov.sefaz.ms.nfe.gerencial.seguranca;
import gov.sefaz.ms.nfe.gerencial.bo.iface.INfeGerencialBO;
import gov.sefaz.ms.nfe.gerencial.entidade.Usuario;
import gov.sefaz.utils.exception.SefazException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@Service("userDetailsService")
public class UserDetailsServiceImpl implements UserDetailsService {
@Autowired
private INfeGerencialBO ejbFacade;
@Autowired
private UserDetailsAdapter userDetailsAdapter;
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
UserDetails userDetails = null;
Usuario userEntity = null;
try {
userEntity = (Usuario) ejbFacade.buscarPorNamedQuery("Usuario.BuscaUsersByUsernameEquals", new Object[]{username});
} catch (SefazException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (userEntity == null) {
throw new UsernameNotFoundException("user not found");
}
userDetails = userDetailsAdapter.buildUserFromUserEntity(userEntity);
return userDetails;
}
}
applicationContext-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<beans:bean id="databaseFilter" class="gov.sefaz.ms.nfe.gerencial.seguranca.MyFilterSecurityMetadataSource"/>
<beans:bean id="filterSecurityInterceptor"
class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
<beans:property name="authenticationManager" ref="authenticationManager"></beans:property>
<beans:property name="accessDecisionManager" ref="accessDecisionManager"></beans:property>
<beans:property name="securityMetadataSource" ref="databaseFilter"></beans:property>
<beans:property name="validateConfigAttributes" value="true"></beans:property>
</beans:bean>
<beans:bean id="accessDecisionManager"
class="org.springframework.security.access.vote.AffirmativeBased">
<beans:property name="decisionVoters">
<beans:list>
<beans:bean class="org.springframework.security.access.vote.RoleVoter" />
<beans:bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy">
<filter-chain-map path-type="ant">
<filter-chain pattern="/**" filters="filterSecurityInterceptor" />
</filter-chain-map>
</beans:bean>
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="userDetailsServiceImpl" />
</authentication-manager>
<beans:bean id="userDetailsServiceImpl"
class="br.com.ideiadigital.ideiasecurityad.web.seguranca.UserDetailServiceImpl">
</beans:bean>
</beans:beans>