security源码大全(Security中文)
本文目录一览:
- 1、求个spring security2 表单登入可运行的代码 。谢谢 378656569@qq.com
- 2、spring security3如何实现动态数据库?求源码
- 3、求java加密源代码(MD5,base64)
求个spring security2 表单登入可运行的代码 。谢谢 378656569@qq.com
spring security2的登录验证是由组件本身的代码实现的,你只需要做登陆页面即可,给你一个我在项目中使用过的登陆页面的源代码:
%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%
%@ taglib prefix='c' uri='' %
%@ taglib prefix='fmt' uri='' %
%@ page import="org.springframework.security.ui.AbstractProcessingFilter" %
%@ page import="org.springframework.security.ui.webapp.AuthenticationProcessingFilter" %
%@ page import="org.springframework.security.AuthenticationException" %
!-- Not used unless you declare a form-login login-page="/login.jsp"/ element --
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /
meta http-equiv="pragma" content="no-cache" /
meta http-equiv="cache-control" content="no-cache" /
meta http-equiv="expires" content="0" /
style type="text/css"
#pic {
width: 480px;
height: 300px;
position: relative;
}
#pic fieldset{
margin: 0;
padding: 0;
border:0px
}
#pic div{
position: absolute;
top: 100px;
left:50px;
}
#pic div label{
float: left;
font-size:13px;
font-weight:bold;
width: 86px; /*width of label (left column)*/
text-transform: uppercase;
/*border-bottom: 1px solid red;*/
margin-right: 18px; /*spacing with right column*/
text-align:right;
line-height : 22px;
}
input.text{
width: 118px;
}
/style
/head
body onload="document.f.j_username.focus();"
center
div id="pic"
%-- this form-login-page form is also used as the
form-error-page to ask for a login again.
--%
img src="/CMSWeb/common/media/login_back.jpg" width="480px" height="300px" alt="配置管理系统" /
form name="f" action="c:url value='j_spring_security_check'/" method="POST"
fieldset class="2644-98ba-16a2-cf34 singlerow"
c:if test="${not empty param.login_error}"
font color="red"
登录失败或者你没有权限访问目标!br/
错误原因:c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/.br/
您的此次访问将会被永久记录下来。
/font
/c:if
div
p
label用户:/labelinput maxlength="18" size="30" type='text' class="98ba-16a2-cf34-2bca text" name='j_username' value='c:if test="${not empty param.login_error}"c:out value="${SPRING_SECURITY_LAST_USERNAME}"//c:if' /
/p
p
label密码:/labelinput maxlength="18" size="30" type='password' class="16a2-cf34-2bca-d6fa text" name='j_password' /
/p
!-- input type="checkbox" name="_spring_security_remember_me"Don't ask for my password for two weeks --
br/
p
input name="submit" type="submit" value="提交" input name="reset" type="reset" value="取消"
/p
/div
/fieldset
/form
/div
/center
/body
/html
spring security3如何实现动态数据库?求源码
您指的是对用户权限等信息通过配置文件或注解方式去给类或方法进行动态的配置管理还是指使用数据动态控制角色,如果是前者官方给出了很多实现方法的源码啊! 如果是后者我做过类似的,需要可以发你!
求java加密源代码(MD5,base64)
import java.security.*;
import javax.crypto.*;
/**
* 本例解释如何利用DES私钥加密算法加解密
*
* @author Devon
* @version 1.0 04/03/10
*/
public class SingleKeyExample {
public static void main(String[] args) {
try {
String algorithm = "DES"; //定义加密算法,可用 DES,DESede,Blowfish
String message = "Hello World. 这是待加密的信息";
// 生成个DES密钥
KeyGenerator keyGenerator = KeyGenerator.getInstance(algorithm);
keyGenerator.init(56); //选择DES算法,密钥长度必须为56位
Key key = keyGenerator.generateKey(); //生成密钥
// 生成Cipher对象
Cipher cipher = Cipher.getInstance("DES");
//用密钥加密明文(message),生成密文(cipherText)
cipher.init(Cipher.ENCRYPT_MODE, key); //操作模式为加密(Cipher.ENCRYPT_MODE),key为密钥
byte[] cipherText = cipher.doFinal(message.getBytes()); //得到加密后的字节数组
System.out.println("加密后的信息: " + new String(cipherText));
//用密钥加密明文(plainText),生成密文(cipherByte)
cipher.init(Cipher.DECRYPT_MODE, key); //操作模式为解密,key为密钥
byte[] sourceText = cipher.doFinal(cipherText); //获得解密后字节数组
System.out.println("解密后的信息: " + new String(sourceText));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
/**
* @author Devon
*/
import java.security.*;
import java.security.spec.*;
import javax.crypto.*;
public class PairKeyExample {
public static void main(String argv[]) {
try {
String algorithm = "RSA"; //定义加密算法,可用 DES,DESede,Blowfish
String message = "张三,你好,我是李四";
//产生张三的密钥对(keyPairZhang)
KeyPairGenerator keyGeneratorZhang =
KeyPairGenerator.getInstance(algorithm); //指定采用的算法
keyGeneratorZhang.initialize(1024); //指定密钥长度为1024位
KeyPair keyPairZhang = keyGeneratorZhang.generateKeyPair(); //产生密钥对
System.out.println("生成张三的公钥对");
// 张三生成公钥(publicKeyZhang)并发送给李四,这里发送的是公钥的数组字节
byte[] publicKeyZhangEncode = keyPairZhang.getPublic().getEncoded();
//通过网络或磁盘等方式,把公钥编码传送给李四
//李四接收到张三编码后的公钥,将其解码
KeyFactory keyFacoryLi = KeyFactory.getInstance(algorithm); //得到KeyFactory对象
X509EncodedKeySpec x509KeySpec =
new X509EncodedKeySpec(publicKeyZhangEncode); //公钥采用X.509编码
PublicKey publicKeyZhang = keyFacoryLi.generatePublic(x509KeySpec); //将公钥的KeySpec对象转换为公钥
System.out.println("李四成功解码,得到张三的公钥");
//李四用张三的公钥加密信息,并发送给李四
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); //得到Cipher对象
cipher.init(Cipher.ENCRYPT_MODE, publicKeyZhang); //用张三的公钥初始化Cipher对象
byte[] cipherMessage = cipher.doFinal(message.getBytes()); //得到加密信息
System.out.println("加密后信息:" + new String(cipherMessage));
System.out.println("加密完成,发送给李四...");
//张三用自己的私钥解密从李四处收到的信息
cipher.init(Cipher.DECRYPT_MODE, keyPairZhang.getPrivate()); //张三用其私钥初始化Cipher对象
byte[] originalMessage = cipher.doFinal(cipherMessage); //得到解密后信息
System.out.println("张三收到信息,解密后为:" + new String(originalMessage));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}