Erro ao utilizar EJB Com Spring Security

Pessoal, estou tentando utilizar EJB para realizar acessar o BD para pegar as roles do Spring Security

Segue o erro que estou tendo

Deployment Error for module: bpp: Erro durante a implantação: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginDetailsService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [br.com.gd.bpp.facade.LoginFacade] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.ejb.EJB(beanName=, mappedName=, beanInterface=class java.lang.Object, description=, name=, lookup=)}

Segue as classes:

[code]
@Service
public class LoginDetailsService implements UserDetailsService {

private static Logger logger;
static {
	try {
		logger = Logger.getLogger( LoginDetailsService.class );
	} catch (Exception e) {
		e.printStackTrace( System.err );
	}
}

@EJB
private LoginFacade loginFacade;

@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException, DataAccessException {
	logger.info("-----------------------------------------------------------------------------------");

	LoginVO loginVO = new LoginVO();
	loginVO.setEmail(email);
	loginVO.setSenha(request().getParameter("j_password").toCharArray());
	loginVO.setIp(request().getRemoteAddr());
	loginVO.setDataCriacao(new Date());
	loginVO.setSessaoAtual(request().getRequestedSessionId());
	logger.info(" Requisicao para logar: " + loginVO.getEmail() + " IP: "+ loginVO.getIp());
	
	Usuario u = null;
	try{
		 u = loginFacade.logarUser(loginVO);
	}catch (EJBException e) {
		logger.error(" Causa: "+e.getCause().getMessage());
		logger.info("-----------------------------------------------------------------------------------");
		throw new EmptyResultDataAccessException( e.getCause().getMessage(),1);	
	}
	
	sessao().setAttribute("usuarioLogado", u);
	logger.info("-----------------------------------------------------------------------------------");
    return u.getUser();
}

private static HttpSession sessao(){		
	return request().getSession(true); 
}


private static HttpServletRequest request(){
	ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
	return attr.getRequest();
}

}[/code]

[code]
@Stateless
public class LoginFacade extends AbstractFacade {
@PersistenceContext(unitName = “com.br.bpp”)
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
    return em;
}

public LoginFacade() {
    super(LoginFacade.class);
}

public Usuario logarUser(LoginVO loginVO) {
	System.out.println("lretornou lll");
	return null;
}

}[/code]

E o ApplicationContext-security.xml

[code]

<?xml version="1.0" encoding="UTF-8"?>

<b:beans xmlns=“http://www.springframework.org/schema/security
xmlns:b=“http://www.springframework.org/schema/beans
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xmlns:context=“http://www.springframework.org/schema/context
xmlns:util=“http://www.springframework.org/schema/util
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.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd”>

<!-- habilita a configuração por annotations -->
<context:annotation-config />

<!-- define os pacotes/subpacotes que onde serão procurados beans do spring -->
<context:component-scan base-package="br.com.gd.*" />

<global-method-security secured-annotations="enabled" />

<http>			
	<form-login 
		login-page="/login.jsf" 

		always-use-default-target="true" 			
		authentication-success-handler-ref="myAuthenticationSuccessHandler"
		authentication-failure-handler-ref="myExceptionMappingAuthenticationFailureHandler" />
	<logout  invalidate-session="true" success-handler-ref="myLogoutSuccessHandler"   />
	<session-management session-fixation-protection="none">
			 <concurrency-control error-if-maximum-exceeded ="false" max-sessions="1"/>
	</session-management>
    <intercept-url pattern="/**" requires-channel="https"/>
	<port-mappings>
  		<port-mapping http="80" https="443"/>
	</port-mappings> 
	<remember-me />
	<access-denied-handler ref="myAccessDeniedHandlerImpl" />
	<custom-filter before="FILTER_SECURITY_INTERCEPTOR"  ref="filterSecurityInterceptor" /> 
</http>

<b:bean id="filterSecurityInterceptor"  class="br.com.gd.bpp.security.MyFilterSecurityInterceptor">
  <b:property name="authenticationManager" ref="authenticationManager"/>
  <b:property name="accessDecisionManager" ref="accessDecisionManager"/>
  <b:property name="securityMetadataSource" ref="securityMetadataSource" />
  <b:property name="validateConfigAttributes" value="true" />
</b:bean>

<authentication-manager alias="authenticationManager" >
  <authentication-provider user-service-ref="loginDetailsService">
    <password-encoder hash="md5"/>
  </authentication-provider>
</authentication-manager>

<b:bean id="securityMetadataSource"    class="br.com.gd.bpp.security.MySecureResourceFilter" />

<b:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
	<b:property name="decisionVoters">
		<b:list>
		<b:bean class="org.springframework.security.access.vote.RoleVoter" />
		<b:bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
		</b:list>
	</b:property>
</b:bean>	

</b:beans>[/code]

Alguém poderia ajudar, por favor

Dá para se usar injeção com @EJB dentro de um bean gerenciado pelo Spring ?
Não tem que escrever nada em um arquivo de configuração ?
O erro aparentemente é que ele não conseguiu injetar o seu ejb.

Error creating bean with name ‘loginDetailsService’: Injection of resource dependencies failed;

Lele_vader, boa tarde.

Ai que está o problema. Gostaria de saber como fazer para injetar o ejb. Em qual arquivo de configuração tenho que escrever…

Pessoal,

declarei no meu ApplicationContext-security.xml

<b:bean id="loginDetailsService" class="org.springframework.jndi.JndiObjectFactoryBean"> <b:property name="jndiName" value="jdbc/freeERP" /> </b:bean>

e estou tendo o seguinte erro:

Deployment Error for module: bpp: Erro durante a implantação: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginDetailsService' defined in class path resource [applicationContext-security.xml]: Invocation of init method failed; nested exception is javax.naming.NamingException: Lookup failed for 'jdbc/freeERP' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: freeERP not found]

Alguem saberia o que pode estar ocorrendo?

Obrigado

Tenta colocar java/comp/env/jdbc/freeERP

O datasource é freeERP mesmo ?

Para registrar,

<b:property name=“jndiName” value=“jdbc/freeERP” /> no value coloquei o nome do mue jndi que criei no glassfish.

Ok, resolveu meu problema…porém agora estou com outro…

Segue:


Deployment Error for module: bpp: Erro durante a implantação: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.config.authentication.AuthenticationManagerFactoryBean] while setting bean property 'parent'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#4': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.gjc.spi.jdbc40.DataSource40' to required type 'org.springframework.security.core.userdetails.UserDetailsService' for property 'userDetailsService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.gjc.spi.jdbc40.DataSource40] to required type [org.springframework.security.core.userdetails.UserDetailsService] for property 'userDetailsService': no matching editors or conversion strategy found

Alguém poderia me dar uma luz?

Obrigado

[quote=camilooscar]Para registrar,

<b:property name=“jndiName” value=“jdbc/freeERP” /> no value coloquei o nome do mue jndi que criei no glassfish.

Ok, resolveu meu problema…porém agora estou com outro…

Segue:


Deployment Error for module: bpp: Erro durante a implantação: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.config.authentication.AuthenticationManagerFactoryBean] while setting bean property 'parent'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#4': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.gjc.spi.jdbc40.DataSource40' to required type 'org.springframework.security.core.userdetails.UserDetailsService' for property 'userDetailsService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.gjc.spi.jdbc40.DataSource40] to required type [org.springframework.security.core.userdetails.UserDetailsService] for property 'userDetailsService': no matching editors or conversion strategy found

Alguém poderia me dar uma luz?

Obrigado[/quote]

Conseguiu resolver?
tbm estou com o msm problema

Cara, não tive a oportunidade de trabalhar com EJB ainda, mas o próprio JEE já não possui um mecanismo de segurança e autenticação? Acho que se chama JAAS.

Tem um tutorial aqui no próprio GUJ, dê uma conferida se for do seu interesse.