Spring Security
来源:互联网 发布:nginx 400 bad request 编辑:程序博客网 时间:2024/06/07 01:02
http://wenku.baidu.com/link?url=EQ-tXmNc7Wny1uVIACfdaANr58O7uR_i2IUE1vY9dnw7s9N4wdfUFDzMNPUyvMZRim4JD1co5dFBWPX9urz-hOK8waWQ7uAVpnIox28iPG3
http://www.cnblogs.com/xiongyu/archive/2012/07/21/2602220.html
package com.mkyong.common.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HelloController {
@RequestMapping(value="/welcome",method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
System.out.println("come in1");
model.addAttribute("message", "Spring Security Hello World");
return "hello1";
}
@RequestMapping(value="/",method = RequestMethod.GET)
public String index(ModelMap model) {
System.out.println("come in");
model.addAttribute("message", "Spring Security Hello World");
return "hello";
}
}
package com.mkyong.common.controller;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
public class MyUserDetailsService implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException {
Collection<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
try {
auths = AuthorityUtils.createAuthorityList("ROLE_USER");
} catch (Exception e) {
e.printStackTrace();
}
return new org.springframework.security.core.userdetails.User(
"admin1", "admin1", true, true, true, true,
auths);
//那这样登陆已可,to thi tha
}
}
securt.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<http auto-config="true" access-denied-page="/403.jsp">
<intercept-url pattern="/**" access="ROLE_USER"/>
</http>
<authentication-manager>
<authentication-provider user-service-ref="myUserDetailsService">
</authentication-provider>
</authentication-manager>
<beans:bean name="myUserDetailsService" class="com.mkyong.common.controller.MyUserDetailsService">
</beans:bean>
</beans:beans>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
----------------------------
http://blog.csdn.net/cdnsa/article/details/22268451
- Spring Security
- Spring Security
- spring security
- spring security
- spring security
- spring security
- spring security
- spring security
- spring security
- spring security
- spring security
- Spring Security
- spring security
- spring-security
- Spring Security
- Spring Security
- spring security
- spring Security
- Linux下的android-adb调试工具搭建 ubuntu下
- 笔记
- Linux Vim多窗口操作命令
- Go语言interface详解
- Git的基本使用
- Spring Security
- Unable to compile class for JSP
- photoshop学习(一)-切图篇
- Go中的make和new的区别
- 如何理解Saas,Paas和Iaas
- 1025 反转链表
- Linux makefile 教程 非常详细,且易懂
- 关于 RxJava
- redis