簡體   English   中英

具有Spring Security 3.2.3的Java Web App無需部署

[英]Java Web App With Spring Security 3.2.3 No Deploy

我正在使用應用程序服務器Wildfly 8.1.0。 我正在嘗試實現Spring Security版本3.2.3,但是在執行Deploy時會在服務器控制台上收到以下錯誤消息:

Implantando C:\Program Files (x86)\wildfly-8.2.0\standalone\deployments\tei-ambiente-1.0-SNAPSHOT.war
{"JBAS014671: Failed services" => {"jboss.deployment.unit.\"tei-ambiente-1.0-SNAPSHOT.war\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"tei-ambiente-1.0-SNAPSHOT.war\".WeldStartService: Failed to start service
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type AuthenticationManagerBuilder with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Inject public br.com.tei_ambiente.security.SecurityConfig.configureGlobal(AuthenticationManagerBuilder)
  at br.com.tei_ambiente.security.SecurityConfig.configureGlobal(SecurityConfig.java:0)
"}}

在我的SecuriryConfig.Java檔案下面

package br.com.tei_ambiente.security;

import javax.inject.Inject;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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 br.com.tei_ambiente.security.authentication.AutenticacaoLogin;

@Configuration
@EnableWebSecurity
@ComponentScan(basePackages
        = {"br.com.tei_ambiente.security.authentication",
            "br.com.tei_ambiente.control.service",
            "br.com.tei_ambiente.persistence"})
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Inject
    private AutenticacaoLogin autenticacaoLogin;

    @Inject
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(autenticacaoLogin);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        http.exceptionHandling().accessDeniedPage("/login.xhtml")
                .and()
                .authorizeRequests()
                //.antMatchers("/administracao/**").hasRole("ADMIN")                        
                .anyRequest().authenticated()
                .and()
                .logout().logoutSuccessUrl("/login.xhtml?logout")
                .permitAll()
                .and()
                .formLogin().loginPage("/login.xhtml")
                .failureUrl("/login.xhtml")
                .permitAll();

    }

}

在我的AutenticationLogin.Java檔案下面

package br.com.tei_ambiente.security.authentication;

import br.com.tei_ambiente.control.facade.UsuarioFacade;
import br.com.tei_ambiente.entity.UsuarioEntity;
import br.com.tei_ambiente.util.BundleUtil;
import br.com.tei_ambiente.util.CriptografiaUtil;
import br.com.tei_ambiente.util.JsfUtil;
import javax.ejb.LocalBean;
import javax.ejb.Stateful;
import javax.inject.Inject;
import javax.inject.Named;
import lombok.Getter;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.stereotype.Service;

@Service
public class AutenticacaoLogin implements AuthenticationProvider {    

    @Inject
    @Getter
    private transient UsuarioFacade usuarioFacade;

    @Override    
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        String username = authentication.getName();
        String password = (String) authentication.getCredentials();

        UsuarioEntity usuario = null; //= this.usuarioFacade.recuperarUsuarioPorUsernameCaseInsensitive(username);

        String passwordMD5 = CriptografiaUtil.criptografar(password);
        if (usuario == null || !usuario.getPassword().equals(passwordMD5)) {
            JsfUtil.informarMensagemDeErro(BundleUtil.recuperarChave("mensagem.login.invalido"));
           //throw new BadCredentialsException("Dados não encontrados.");
        }

        return new UsernamePasswordAuthenticationToken(username, password, AuthorityUtils.NO_AUTHORITIES);        
    }

    //@Override
    public boolean supports(Class<?> arg0) {
        return true;
    }

}

在SecurityConfig文件中,我嘗試通過@Autowired更改@Inject,但仍然失敗。

謝謝您的幫助。

對於@Autowired批注,您需要聲明bean屬性以將其連接到xml配置文件中。

<bean id="foo" class="org.foo.bar">
    <property name="foo" ref="foo"/>
</bean>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM