[英]how to authenticate user using spring security?
I wants to implement spring security log in and log out so I have tried following things , Spring-context.xml: 我想实现Spring Security登录和注销,所以我尝试了以下操作Spring-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>
spring-servlet.xml: spring-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/>
I am doing database connection and access manually that is why I am not able to implement the log in and log out using spring security. 我正在手动进行数据库连接和访问,这就是为什么我无法使用Spring Security实现登录和注销的原因。
I am using the following class to connect with database manually : 我正在使用以下类手动连接数据库:
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;
}
}
can anyone explain me to solve this.. 谁能解释我解决这个问题。
Try using spring roo, this rad tool help you to generate code and configure spring security automatically. 尝试使用spring roo,此rad工具可帮助您生成代码并自动配置spring安全性。 http://docs.spring.io/spring-roo/reference/html/beginning.html
http://docs.spring.io/spring-roo/reference/html/beginning.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.