Thursday July 31, 2008
Acegisecurity Memo-9, Login Password with PasswordEncoder(SHA,MD5...)
| Table of Content |
|---|
| class | 說明 |
|---|---|
| org.acegisecurity.providers.encoding.PlaintextPasswordEncoder | 如果 AuthenticationProvider 有傳入 SaltSource,則此加密就是原 password + "{" + aSaltSource.toString() + "}",若無 SaltSource,則即原 password。 |
| org.acegisecurity.providers.ldap.authenticator.LdapShaPasswordEncoder | 一般 LDAP 內建的加密方式,有{SHA}, {SSHA} 二種。 |
| org.acegisecurity.providers.encoding.Md5PasswordEncoder | MD5 加密演算法。 |
| org.acegisecurity.providers.encoding.ShaPasswordEncoder | SHA 加密演算法,建構子可傳入 key 長度,預設是 SHA-1 演算法。 |
| org.acegisecurity.providers.encoding.MessageDigestPasswordEncoder | Md5PasswordEncoder 和 ShaPasswordEncoder 的父類別,但可以直接使用,不過必須在建構子傳入演算法名稱。 |
<bean id="authenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> <property name="userDetailsService"> <ref bean="inMemoryDaoImpl" /> </property> <property name="passwordEncoder"> <bean class="org.acegisecurity.providers.encoding.ShaPasswordEncoder"/> </property> </bean>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="authenticationProvider"
class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
<property name="userDetailsService">
<ref bean="inMemoryDaoImpl" />
</property>
<property name="passwordEncoder">
<bean class="org.acegisecurity.providers.encoding.ShaPasswordEncoder"/>
</property>
</bean>
<bean id="inMemoryDaoImpl" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl">
<property name="userMap">
<!--
admin=1234,ROLE_admin,ROLE_USER,ROLE_other
piaoyi=1234,ROLE_admin,ROLE_USER,ROLE_other
readonly=readonly,ROLE_USER,ROLE_readonly
密碼加密 SHA-1 後如下
-->
<value>
admin=7110eda4d09e062aa5e4a390b0a572ac0d2c0220,ROLE_admin,ROLE_USER,ROLE_other
piaoyi=7110eda4d09e062aa5e4a390b0a572ac0d2c0220,ROLE_admin,ROLE_USER,ROLE_other
readonly=9a27718297218c3757c365d357d13f49d0fa3065,ROLE_USER,ROLE_readonly
</value>
</property>
</bean>
</beans>
Posted at 2008-07-31 01:29 by Piaoyi Kao in Acegisecurity | Permalink | Comments[4]
Thursday July 03, 2008
Acegisecurity Memo, Table of Contents
| Acegisecurity Contents |
|---|
|
Posted at 2008-07-03 16:53 by Piaoyi Kao in Acegisecurity | Permalink | Comments[1]
Tuesday May 27, 2008
Acegisecurity Memo-8, Login Page & Logout URL
| Table of Content |
|---|
| Name | 值 | 說明 |
|---|---|---|
| login url | /contextPath/j_acegi_security_check | 使用者輸入帳號密碼且按確定後,會處理認證的 URL 記得要加上 contextPath |
| login id name | j_username 或用 AuthenticationProcessingFilter.ACEGI_SECURITY_FORM_USERNAME_KEY | 帳號的 key,即 Server 要用來取出 parameter 用的 key |
| login password name | j_password 或用 AuthenticationProcessingFilter.ACEGI_SECURITY_FORM_PASSWORD_KEY | 密碼的 key,即 Server 要用來取出 parameter 用的 key |
| 登入錯誤的 Exception | AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY | 從 Session 的 Attribute 中,可以取得登入錯誤的 AuthenticationException。 |
<%@ page pageEncoding = "UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@page import="org.acegisecurity.AuthenticationException"%> <%@page import="org.acegisecurity.ui.AbstractProcessingFilter"%> <%@page import="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"%> <html> <head> <title>會員登入</title> </head> <body> <c:if test="${param.error==1}"> <font color="red"> Your login attempt was not successful, try again.<BR><BR> Reason: <%=((AuthenticationException)session.getAttribute(AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY)).getMessage()%> </font> </c:if> <form action = "<c:url value="/j_acegi_security_check"/>" method = "POST"> <table border="1"> <tr> <td>帳號</td> <td> <input type="text" name="<%=AuthenticationProcessingFilter.ACEGI_SECURITY_FORM_USERNAME_KEY%>" size = "20"> </td> </tr> <tr> <td>密碼</td> <td> <input type="password" name="<%=AuthenticationProcessingFilter.ACEGI_SECURITY_FORM_PASSWORD_KEY %>" size="20"/> </td> </tr> <!-- <tr> <td colspan="2" align="center"><input type="checkbox" name="_acegi_security_remember_me">Remember Me</td> </tr> --> <tr> <td colspan="2" align="center"><input type = "submit" value = "登入"/></td> </tr> </table> </form> </body> </html>
Acegi 登出的網址為
/contextPath/j_acegi_logout //use taglib <c:url value="/j_acegi_logout"/>
Posted at 2008-05-27 17:12 by Piaoyi Kao in Acegisecurity | Permalink | Comments[4]