2014-04-21 3 views
0

나는 내가 시도 다음과 같은 일을 봄의 보안 로그를 구현하고 로그 아웃 싶어, 스프링의 context.xml :스프링 보안을 사용하여 사용자를 인증하는 방법은 무엇입니까?

<http auto-config="true"> 
     <intercept-url pattern="/**" access="isAuthenticated"/> <!-- this means all URL in this app will be checked if user is authenticated --> 
     <form-login/> <!-- --> 
     <logout logout-url="/logout" logout-success-url=""/> 
</http> 
<authentication-manager> 
     <authentication-provider> 
      <user-service> 
       <user name="sachin" password="sachin123" authorities="Admin"/> 
      </user-service> 
</authentication-provider> 

봄-servlet.xml에 :

<context:component-scan base-package="com.hrportal.controller" /> 
    </context:annotation-config> 
    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 
    <bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="classpath:messages" /> 
     <property name="defaultEncoding" value="UTF-8" /> 
    </bean> 

    <bean id="localeChangeInterceptor" 
     class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
     <property name="paramName" value="lang" /> 
    </bean> 

    <bean id="localeResolver" 
     class="org.springframework.web.servlet.i18n.CookieLocaleResolver"> 
     <property name="defaultLocale" value="en" /> 
    </bean> 

    <bean id="handlerMapping" 
     class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> 
     <property name="interceptors"> 
      <ref bean="localeChangeInterceptor" /> 
     </property> 
      </bean> 
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> 
    <mvc:resources mapping="/images/**" location="/images/"/> 
    <mvc:resources location="/css/**" mapping="/css/"/> 
    <mvc:resources location="/css/**" mapping="/css/"/> 
    <mvc:default-servlet-handler/> 

내가 뭐하는 거지 데이터베이스 연결 및 액세스가 수동으로 이루어 지므로 스프링 보안을 사용하여 로그인 및 로그 아웃을 구현할 수 없습니다. 내가 수동으로 데이터베이스에 연결하려면 다음 클래스를 사용하고

:

private static Connection con = null; 

public static Connection getConnection() { 
    try { 
     if (con == null) { 
      Class.forName("com.mysql.jdbc.Driver"); 
      con = DriverManager.getConnection("jdbc:mysql://localhost:3306/portal", 
        "root", "root"); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    return con; 
} 

} 

사람이이 문제를 해결하기 위해 나를 설명 할 수 ..

+0

문제점을 설명해주세요. – geoand

+0

@geoand, 사실 저는 스프링 테크놀러지를 처음 접했고 ..... sevlet을 잘 사용하고 있으며 로그와 로그 아웃 서비스를 사용하여 온라인 자습서를 따라 갔지만 완전히 이해할 수 없었습니다. – user3448105

+0

그리고 나는 수동으로 사용자 인증을하고 있으므로이를 수행 할 수있는 방법이 있습니까? – user3448105

답변

관련 문제