2012-12-17 2 views
0

솔루션을 찾고 있지만 아무 것도 시도하지 않았습니다. JSF로 작성된 스프링 보안 구성과 프론트 엔드를 가지고 있습니다. 나는 intenter의 일부 CONFIGS를 찾았지만 그들은 함께 싶어 작업을SpringSecurity + JSF 커스텀 인증

<http> 
    <intercept-url pattern="/index*" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/javax.faces.resource/**" 
     access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/**" access="ROLE_USER" /> 
    <intercept-url pattern="/admin/*" access="ROLE_SUPERVISOR" /> 
    <form-login login-page="/index.html" default-target-url="/home.html" 
     always-use-default-target="true" authentication-failure-url="/index.xhtml?login_error=1" /> 
    <logout logout-url="/logout.html" /> 
</http> 

해달라고 :

<authentication-manager> 
    <authentication-provider>    
     <user-service> 
      <user name="admin" password="admin" authorities="ROLE_USER, ROLE_SUPERVISOR" /> 
      <user name="anonim" password="anonim" authorities="" /> 
      <user name="user" password="user" authorities="ROLE_USER" /> 
     </user-service> 
    </authentication-provider> 
</authentication-manager> 

가 나는 유사합니다 해결책을 발견 사용자 정의 로거처럼 몇 가지 사용자 정의 클래스를하고 싶습니다를 이 :

<h:form>  
    <h:panelGrid columns="2" cellpadding="5"> 
     <h:outputLabel for="username" name='j_username' value="Username:" /> 
     <p:inputText id="username" value="#{loginBeenController.login}" required="true" label="username" /> 

     <h:outputLabel for="password" value="Password:" /> 
     <h:inputSecret id="password" value='#{loginBeenController.password}' required="true" label="password" /> 

     <f:facet name="footer"> 
      <p:commandButton ajax='false' id="loginButton" value="Login" action="#{loginBeenController.login()}" /> 
     </f:facet> 
    </h:panelGrid>    
</h:form> 
: 여기

public class LoginBeenController { 
    private static final Logger LOGGER = Logger.getLogger(LoginBeenController.class); 

    private String login; 
    private String password; 
    @Autowired 
    private AuthenticationManager authenticationManager; 

    public LoginBeenController() { 

    } 

    public String getLogin() { 
     return login; 
    } 

    public String getPassword() { 
     return password; 
    } 

    public void setLogin(String login) { 
     this.login = login; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 

    public String login(){ 
     Authentication authentication = authenticationManager 
       .authenticate(new UsernamePasswordAuthenticationToken(
         this.login, this.password)); 
     if (authentication.isAuthenticated()) { 
      SecurityContextHolder.getContext().setAuthentication(
        authentication); 
     } 
     return new String(); 
    } 

} 

프라임 형태이다

+1

무슨 질문과 뭐죠 정확히 문제? – micha

+0

이 조각을 연결하는 방법을 모르겠다. – vermer

답변

0

AuthenticationManager를 사용하는 대신 Spring Security 인증 URL로 전달해야합니다. 이 시도 : 나는 단지 추가했다 해결책을 발견

public String doLogin() throws ServletException, IOException { 

    FacesContext context = FacesContext.getCurrentInstance(); 

     String springCheckUrl = this.buildSpringSecurityCheckUrl(); 

     HttpServletRequest request = (HttpServletRequest) context 
       .getExternalContext().getRequest(); 

     RequestDispatcher dispatcher = request 
       .getRequestDispatcher(springCheckUrl); 

     dispatcher.forward((ServletRequest) request, 
       (ServletResponse) context.getExternalContext.getResponse()); 

     context.responseComplete(); 

     return null; 
    } 

    private String buildSpringSecurityCheckUrl() { 
     StringBuilder springCheckUrl = new StringBuilder(
       "/j_spring_security_check").append("?").append("j_username") 
       .append("=").append(this.userName.trim()).append("&") 
       .append("j_password").append("=") 
       .append(this.userPassword.trim()); 
     return springCheckUrl.toString(); 
    } 
} 
+0

하지만 이것들은 서블릿 기반 maby 리디렉션을 기반으로하는 솔루션으로 JSF – vermer

2

확인 :

@Autowired 
@Qualifier("authenticationManager") 
AuthenticationManager authenticationManager; 
관련 문제