锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Run-As Manager 鍜?After-Invocation Manager涓嶉噸瑕?/p>
The actual implementation of a security interceptor will depend on what resource is being secured. If you’re securing a URL in a web application, the security interceptor will be implemented as a servlet filter. But if you’re securing a method invocation, aspects will be used to enforce security.
榪欑瘒鍙Authentication Manager:
璁よ瘉鏄氳繃AuthenticationManager鏉ョ鐨勶紝
public interface AuthenticationManager { }
The authenticate() method will attempt to authenticate the user using the org.acegisecurity.Authentication object (which carries the principal and credentials). If successful, the authenticate() method returns a complete Authentication object, including information about the user’s granted authorities (which will be considered by the authorization manager).
鍏蜂綋鐨勫伐浣滄槸浜ょ粰鍚勪釜 authentication provider鏉ュ仛鐨勶細
榪欓噷provider manager鍖呭惈澶氫釜鍏蜂綋鐨刾roviders:
<bean id="authenticationManager" 浠aoAuthenticationProvider涓句緥錛?
<bean id="authenticationProvider" 瀹冧細瑕佹眰涓涓猆serDetailsService, 璺熷畠鐩稿叧鐨勬槸UserDetails鎺ュ彛
UserDetailsService鎺ュ彛鏄釜綆鍗曠殑鎺ュ彛
public interface UserDetailsService {
UserDetails鎺ュ彛濡備笅錛?
public interface UserDetails extends Serializable { String getPassword();
String getUsername();
boolean isAccountNonExpired();
boolean isAccountNonLocked();
boolean isCredentialsNonExpired();
boolean isEnabled(); 瑙i噴涓涓媑etAuthorities:璇ユ柟娉曡繑鍥炰竴涓狦rantedAuthority[]鏁扮粍瀵硅薄錛孏rantedAuthority鏄敤鎴鋒潈闄愪俊鎭璞★紝榪欎釜瀵硅薄涓畾涔変簡涓涓幏鍙栫敤鎴鋒潈闄愭弿榪頒俊鎭殑getAuthority()鏂規硶銆?
闇瑕佹敞鎰?em>Authentication瀵硅薄鎵嶆槸Spring Security浣跨敤鐨勮繘琛屽畨鍏ㄨ闂帶鍒剁敤鎴蜂俊鎭畨鍏ㄥ璞°傚疄闄呬笂錛孉uthentication瀵硅薄鏈夋湭璁よ瘉鍜屽凡璁よ瘉涓ょ鐘舵侊紝鍦ㄤ綔涓哄弬鏁頒紶鍏ヨ璇佺鐞嗗櫒錛圓uthenticationManager錛夌殑authenticate鏂規硶鏃訛紝鏄竴涓湭璁よ瘉鐨勫璞★紝瀹冧粠瀹㈡埛绔幏鍙栫敤鎴風殑韜喚淇℃伅錛堝鐢ㄦ埛鍚嶏紝瀵嗙爜錛夛紝鍙互鏄粠涓涓櫥褰曢〉闈紝涔熷彲浠ヤ粠Cookie涓幏鍙栵紝騫剁敱緋葷粺鑷姩鏋勯犳垚涓涓狝uthentication瀵硅薄銆傝岃繖閲屾彁鍒扮殑UserDetails浠h〃涓涓敤鎴峰畨鍏ㄤ俊鎭殑婧愶紙浠庢暟鎹簱錛孡DAP鏈嶅姟鍣紝CA涓績榪斿洖錛夛紝Spring Security瑕佸仛鐨勫氨鏄皢榪欎釜鏈璇佺殑Authentication瀵硅薄鍜孶serDetails榪涜鍖歸厤錛屾垚鍔熷悗灝哢serDetails涓殑鐢ㄦ埛鏉冮檺淇℃伅鎷瘋礉鍒癆uthentication涓粍鎴愪竴涓畬鏁寸殑Authentication瀵硅薄錛屽叡鍏跺畠緇勪歡鍏變韓銆?
鍙傝冿細
Spring in Action
Spring Security瀛︿範鎬葷粨錛?http://m.tkk7.com/redhatlinux/archive/2008/08/20/223148.html
Spring Security2 瀛︿範綺捐錛?http://www.javaeye.com/topic/319965
]]>
寮濮嬭姳浜嗕袱涓夊ぉ鐨勬椂闂村Spring Security錛岃繕鏄簯灞遍浘緗╃殑錛屽ぇ鍙楁墦鍑匯備簬鏄噸鏂版葷粨涓涓嬶紝椋炶秺榪烽浘錛屾⒊鐞嗘濊礬錛屽啓榪欐牱涓綃囨枃瀛椼傜綉涓婃湁涓浄閿嬪啓浜哠pring Security2 瀛︿範綺捐錛歨ttp://www.javaeye.com/topic/319965閲岄潰鍖呭惈鍙互榪愯鐨勪唬鐮侊紝濡傛灉浣犲spring scurity鎰熷叴瓚o紝鍙互蹇熸祻瑙堜竴涓嬩笅闈㈢殑絎旇錛岀劧鍚巇ebug code錛岀劧鍚庡啀鐪嬬湅絎旇銆係pring Security鐨勫唴瀹硅繙姣旂瑪璁板鏉傦紝鎴戝彧鏄牴鎹嚜宸辯殑鐞嗚В鎸戦噸瑕佺殑璁板綍騫舵暣鐞嗕竴涓嬨傛妸sample code涔熷綋浣滅瑪璁扮殑涓閮ㄥ垎錛岄偅涓猚ode榪樻槸姣旇緝綺劇畝鍦幫紝鏇撮噸瑕佺殑鏄疄鐢ㄣ?br />
瀹樻柟鎻愪緵鐨剆ample code鍖呭眳鐒舵病鏈夋簮浠g爜錛宖aint錛?google鍗婂ぉ鎵懼埌http://grepcode.com/snapshot/repo1.maven.org/maven2/org.springframework.security/spring-security-samples-contacts/2.0.0 褰撶劧錛屽鏋滀綘浼氱敤git鐨勮瘽涔熷彲浠ヨ嚜宸眂heck out code, 涓嶈繃鎴戞病鐢ㄨ繃git榪欑楂樼駭璐с?br />
姝f枃
璺熸潈闄愭湁鍏崇殑涓や釜姒傚康鏄?璁よ瘉 鍜?鎺堟潈錛?鍏堜笂涓浘錛?/p>
public Authentication authenticate(Authentication authentication)
throws AuthenticationException;
class="org.acegisecurity.providers.ProviderManager">
<property name="providers">
<list>
<ref bean="daoAuthenticationProvider"/>
<ref bean="ldapAuthenticationProvider"/>
</list>
</property>
</bean>
ProviderManager is given its list of authentication providers through its providers property.
class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
<property name="userDetailsService"
ref="userDetailsService"/>
</bean>
UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException;
}
GrantedAuthority[] getAuthorities();
}
涓嬩竴綃囷細 鎬葷粨Spring Security涔?鍏充簬鎺堟潈錛屼繚鎶eb鍜屼繚鎶ゆ柟娉?/u>
]]>
]]>
]]>
1: class ExampleBean {
2: private String string;
3: public ExampleBean(String string) {
4: this.string = string;
5: }
6:
7: public void write() {
8: System.out.println("The text is: " + text);
9: }
10:
11: }
12:
13: class ExampleBeanFactory {
14: public static ExampleBean createExampleBean(String string) {
15: return new ExampleBean(string);
16: }
17: }
18:
19: public class Main {
20: public static void main(String[] args) {
21: ApplicationContext context = new ClassPathXmlApplicationContext(
22: "context.xml");
23: ExampleBean exampleBean =
24: ExampleBean)context.getBean("exampleBean",
25: new Object[]{"bla bla"});
26: exampleBean.write();
27: }
28: }
1: <bean id="exampleBean" class="...ExampleBeanFactory" scope="prototype"
2: factory-method="createExampleBean">
3: <constructor-arg value="default value"/>
4: </bean>
娉ㄦ剰scope浣跨敤prototype