(3) abstractFactory 클래스는 주로 싱글톤인지 여부를 설정합니다.
(4) iniFactorySupport는 ini 설정을 지원하여 생성된 객체입니다.
(5) iniSecurityman agerFactory는 securityManager
(2)//2의 구현 클래스를 생성하는 ini 메소드입니다. SecurityManager 인스턴스를 가져와 SecurityUtils1 IniSecurityManagerFactory类:2 creatSecuritymanager(ini){3 SecurityManager securityManager = createSecurityManager(ini);4 return securityManager;5 }
1 private SecurityManager createSecurityManager(Ini ini) { 2 //null 3 Ini.Section mainSection = ini.getSection(MAIN_SECTION_NAME); 4 if (CollectionUtils.isEmpty(mainSection)) { 5 6 //try the default: null 7 mainSection = ini.getSection(Ini.DEFAULT_SECTION_NAME); 8 } 9 return createSecurityManager(ini, mainSection);10 }
( 3) ini 객체와 메인 모듈 mainSession을 통해 Securitymanager를 생성합니다. 1 private SecurityManager createSecurityManager(Ini ini, Ini.Section mainSection) { 2 //{securityManager=DefaultSecurityManager,iniRealm=IniRealm} 3 Map defaults = createDefaults(ini, mainSection); 4 Map objects = buildInstances(mainSection, defaults); 5 6 SecurityManager securityManager = getSecurityManagerBean(); 7 boolean autoApplyRealms = isAutoApplyRealms(securityManager); 8 if (autoApplyRealms) { 9 //realms and realm factory might have been created - pull them out first so we can initialize the securityManager:10 Collection realms = getRealms(objects);11 //set them on the SecurityManager12 if (!CollectionUtils.isEmpty(realms)) {13 applyRealmsToSecurityManager(realms, securityManager);14 }15 }16 return securityManager;17 }
1 private Map buildInstances(Ini.Section section, Map defaults) { 2 this.builder = new ReflectionBuilder(defaults); 3 return this.builder.buildObjects(section); 4 } 5 //类ReflectionBuilder 6 //通过mainSection创建对象并关联 7 public Map buildObjects(Map kvPairs) { 8 ..... 9 LifecycleUtils.init(objects.values());10 }
1 //类IniRealm 2 private void processDefinitions(Ini ini) { 3 Ini.Section usersSection = ini.getSection(USERS_SECTION_NAME); 4 processUserDefinitions(usersSection); 5 } 6 //通过userSection解析user模块 7 protected void processUserDefinitions(Map userDefs) { 8 for (String username : userDefs.keySet()) { 9 ........10 account = new SimpleAccount(username, password, getName());11 add(account);12 ........13 }14 }15 protected void add(SimpleAccount account) {16 String username = getUsername(account);17 USERS_LOCK.writeLock().lock();18 try {19 this.users.put(username, account);20 }finally {21 USERS_LOCK.writeLock().unlock();22 }
///3. 제목을 가져오고 사용자 이름/비밀번호 인증 토큰(예: user ID/자격 증명)
1 applyRealmsToSecurityManager(realms, securityManager){2 ((RealmSecurityManager) securityManager).setRealms(realms);3 }4 //在类RealmSecurityManager中5 public void setRealms(Collection realms) {6 this.realms = realms;7 afterRealmsSet();8 }
1 //获取主题对象 2 public static Subject getSubject() {3 Subject subject = ThreadContext.getSubject();//第一次null4 if (subject == null) {5 subject = (new Subject.Builder()).buildSubject();6 ThreadContext.bind(subject);7 }8 return subject;9 }(3) 테마를 통해 주제 객체 생성
1 public static class Builder{ 2 SubjectContext subjectContext; 3 SecurityManager securityManager; 4 public Builder(SecurityManager securityManager) { 5 if (securityManager == null) { 6 throw new NullPointerException("SecurityManager method argument cannot be null."); 7 } 8 this.securityManager = securityManager; 9 this.subjectContext = newSubjectContextInstance();//DefaultSubjectContext(初始化一个backMap集合)10 if (this.subjectContext == null) {11 throw new IllegalStateException("Subject instance returned from 'newSubjectContextInstance' " +12 "cannot be null.");13 }14 this.subjectContext.setSecurityManager(securityManager);15 }16 public Subject buildSubject() {17 return this.securityManager.createSubject(this.subjectContext);18 }19 }
1 public Subject createSubject(SubjectContext context) { 2 SecurityManager securityManager = context.resolveSecurityManager(); 3 Session session = context.resolveSession(); 4 boolean sessionCreationEnabled = context.isSessionCreationEnabled(); 5 PrincipalCollection principals = context.resolvePrincipals(); 6 boolean authenticated = context.resolveAuthenticated(); 7 String host = context.resolveHost(); 8 9 return new DelegatingSubject(principals, authenticated, host, session, sessionCreationEnabled, securityManager);10 }
위 내용은 Shiro 소스 코드의 자세한 소개의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!