1. 程式人生 > >Apache Shiro Architecture--官方文件

Apache Shiro Architecture--官方文件

原文地址:http://shiro.apache.org/architecture.html

Apache Shiro's design goals are to simplify application security by being intuitive and easy to use. Shiro's core design models how most people think about application security - in the context of someone (or something) interacting with an application.

Software applications are usually designed based on user stories. That is, you'll often design user interfaces or service APIs based on how a user would (or should) interact with the software. For example, you might say, "If the user interacting with my application is logged in, I will show them a button they can click to view their account information. If they are not logged in, I will show a sign-up button."

This example statement indicates that applications are largely written to satisfy user requirements and needs. Even if the 'user' is another software system and not a human being, you still write code to reflect behavior based on who (or what) is currently interacting with your software.

Shiro reflects these concepts in its own design. By matching what is already intuitive for software developers, Apache Shiro remains intuitive and easy to use in practically any application.

High-Level Overview

At the highest conceptual level, Shiro's architecture has 3 primary concepts: the SubjectSecurityManager and Realms. The following diagram is a high-level overview of how these components interact, and we'll cover each concept below:





  • Subject: As we've mentioned in our Tutorial
    , the Subject is essentially a security specific 'view' of the the currently executing user. Whereas the word 'User' often implies a human being, a Subject can be a person, but it could also represent a 3rd-party service, daemon account, cron job, or anything similar - basically anything that is currently interacting with the software. 

    Subject instances are all bound to (and require) a SecurityManager. When you interact with a Subject, those interactions translate to subject-specific interactions with the SecurityManager

  • SecurityManager: The SecurityManager is the heart of Shiro’s architecture and acts as a sort of 'umbrella’ object that coordinates its internal security components that together form an object graph. However, once the SecurityManager and its internal object graph is configured for an application, it is usually left alone and application developers spend almost all of their time with the Subject API. 

    We will talk about the SecurityManager in detail later on, but it is important to realize that when you interact with a Subject, it is really the SecurityManager behind the scenes that does all the heavy lifting for any Subject security operation. This is reflected in the basic flow diagram above. 

  • Realms: Realms act as the ‘bridge’ or ‘connector’ between Shiro and your application’s security data. When it comes time to actually interact with security-related data like user accounts to perform authentication (login) and authorization (access control), Shiro looks up many of these things from one or more Realms configured for an application. 

    In this sense a Realm is essentially a security-specific DAO: it encapsulates connection details for data sources and makes the associated data available to Shiro as needed. When configuring Shiro, you must specify at least one Realm to use for authentication and/or authorization. The SecurityManager may be configured with multiple Realms, but at least one is required. 

    Shiro provides out-of-the-box Realms to connect to a number of security data sources (aka directories) such as LDAP, relational databases (JDBC), text configuration sources like INI and properties files, and more. You can plug-in your own Realm implementations to represent custom data sources if the default Realms do not meet your needs. 

    Like other internal components, the Shiro SecurityManager manages how Realms are used to acquire security and identity data to be represented as Subject instances.

Detailed Architecture

The following diagram shows Shiro's core architectural concepts followed by short summaries of each:

  • Subject ()
    A security-specific 'view' of the entity (user, 3rd-party service, cron job, etc) currently interacting with the software. 

  • SecurityManager ()
    As mentioned above, the SecurityManager is the heart of Shiro's architecture. It is mostly an 'umbrella' object that coordinates its managed components to ensure they work smoothly together. It also manages Shiro's view of every application user, so it knows how to perform security operations per user. 

  • Authenticator ()
    The Authenticator is the component that is responsible for executing and reacting to authentication (log-in) attempts by users. When a user tries to log-in, that logic is executed by the Authenticator. The Authenticator knows how to coordinate with one or more Realmsthat store relevant user/account information. The data obtained from these Realms is used to verify the user's identity to guarantee the user really is who they say they are. 

    • Authentication Strategy ()
      If more than one Realm is configured, the AuthenticationStrategy will coordinate the Realms to determine the conditions under which an authentication attempt succeeds or fails (for example, if one realm succeeds but others fail, is the attempt successful? Must all realms succeed? Only the first?). 

  • Authorizer ()
    The Authorizer is the component responsible determining users' access control in the application. It is the mechanism that ultimately says if a user is allowed to do something or not. Like the Authenticator, the Authorizer also knows how to coordinate with multiple back-end data sources to access role and permission information. The Authorizer uses this information to determine exactly if a user is allowed to perform a given action. 

  • SessionManager ()
    The SessionManager knows how to create and manage user Session lifecycles to provide a robust Session experience for users in all environments. This is a unique feature in the world of security frameworks - Shiro has the ability to natively manage user Sessions in any environment, even if there is no Web/Servlet or EJB container available. By default, Shiro will use an existing session mechanism if available, (e.g. Servlet Container), but if there isn't one, such as in a standalone application or non-web environment, it will use its built-in enterprise session management to offer the same programming experience. The SessionDAO exists to allow any datasource to be used to persist sessions. 

    • SessionDAO ()
      The SessionDAO performs Session persistence (CRUD) operations on behalf of the SessionManager. This allows any data store to be plugged in to the Session Management infrastructure. 

  • CacheManager ()
    The CacheManager creates and manages Cache instance lifecycles used by other Shiro components. Because Shiro can access many back-end data sources for authentication, authorization and session management, caching has always been a first-class architectural feature in the framework to improve performance while using these data sources. Any of the modern open-source and/or enterprise caching products can be plugged in to Shiro to provide a fast and efficient user-experience. 

  • Cryptography ()
    Cryptography is a natural addition to an enterprise security framework. Shiro's crypto package contains easy-to-use and understand representations of crytographic Ciphers, Hashes (aka digests) and different codec implementations. All of the classes in this package are carefully designed to be very easy to use and easy to understand. Anyone who has used Java's native cryptography support knows it can be a challenging animal to tame. Shiro's crypto APIs simplify the complicated Java mechanisms and make cryptography easy to use for normal mortal human beings. 

  • Realms ()
    As mentioned above, Realms act as the ‘bridge’ or ‘connector’ between Shiro and your application’s security data. When it comes time to actually interact with security-related data like user accounts to perform authentication (login) and authorization (access control), Shiro looks up many of these things from one or more Realms configured for an application. You can configure as manyRealms as you need (usually one per data source) and Shiro will coordinate with them as necessary for both authentication and authorization.

The SecurityManager

Because Shiro's API encourages a Subject-centric programming approach, most application developers will rarely, if ever, interact with the SecurityManager directly (framework developers however might sometimes find it useful). Even so, it is still important to know how theSecurityManager functions, especially when configuring one for an application.

Design

As stated previously, the application's SecurityManager performs security operations and manages state for all application users. In Shiro's default SecurityManager implementations, this includes:

  • Authentication
  • Authorization
  • Session Management
  • Cache Management
  • Realm coordination
  • Event propagation
  • "Remember Me" Services
  • Subject creation
  • Logout
    and more.

But this is a lot of functionality to try to manage in a single component. And, making these things flexible and customizable would be very difficult if everything were lumped into a single implementation class.

To simplify configuration and enable flexible configuration/pluggability, Shiro's implementations are all highly modular in design - so modular in fact, that the SecurityManager implementation (and its class-hierarchy) does not do much at all. Instead, the SecurityManagerimplementations mostly act as a lightweight 'container' component, delegating almost all behavior to nested/wrapped components. This 'wrapper' design is reflected in the detailed architecture diagram above.

While the components actually execute the logic, the SecurityManager implementation knows how and when to coordinate the components for the correct behavior.

The SecurityManager implementations and are also JavaBeans compatible, which allows you (or a configuration mechanism) to easily customize the pluggable components via standard JavaBeans accessor/mutator methods (get*/set*). This means the Shiro's architectural modularity can translate into very easy configuration for custom behavior.

相關推薦

Apache Shiro Architecture--官方

原文地址:http://shiro.apache.org/architecture.html Apache Shiro's design goals are to simplify application security by being intuitive and easy to use. Shiro'

Apache Common CLI官方

原文連結     參考連結    譯者:小村長 本篇文章是併發程式設計網組織的一次Apache Common元件翻譯的一部分,因為無意中看到了Apache Common CLI感覺很好奇,因為這個工具很少在網上看到,當然或許我沒有關注過。因為我之前也寫過類似的CLI工具所以感覺情有獨鍾吧。所以讓我來為大家揭

Apache Commons Pool官方

原文連結  譯者:張坤 Apache Commons Pool 開源軟體庫提供了一個物件池API和一系列物件池實現。Apache Commons Pool 2.x與1.x相比實現了一個可重寫的物件池實現。另外,效能和可伸縮性也有了改進,2.x版本包含魯棒的例項追蹤和物件池監控。2.x版本需要J

Apache Storm 官方 —— Trident State

Trident 中含有對狀態化(stateful)的資料來源進行讀取和寫入操作的一級抽象封裝工具。這個所謂的狀態(state)既可以儲存在拓撲內部(儲存在記憶體中並通過 HDFS 來實現備份),也可以存入像 Memcached 或者 Cassandra 這樣的外部資料庫中。而對於 Trident A

Flume.apache.org 官方學習筆記 part one

Apache Flume 是一個分散式,可靠且可用的系統,用於有效地從許多不同的源收集,聚合和移動大量日誌資料到集中式資料儲存。 Apache Flume的使用不僅限於日誌資料聚合。由於資料來源是可定製的,因此Flume可用於傳輸大量事件資料,包括但不限於網路流量資料

Flume.apache.org 官方學習筆記 part two

   配置個體元件:       當你定義了這個流之後,你需要去設定每個資源、接收器、通道的屬性。這是在你設定元件型別和每個元件的特定屬性值的同一層名稱空間內完成的。 # properties for sources <Agent>.sources.<S

Flume.apache.org 官方學習筆記 part three

    JMS 源:         jms源閱讀從jms目的地發來的資訊,例如佇列,主題等。  作為一個jms應用程式,他應該和jms提供程式一起工作,但是僅使用ActiveMQ進行測試。JMS源提供可配置的批量大小,訊息選擇器,使用者/傳遞還有訊息到接收器事件轉換器。 要

Flume.apache.org 官方學習筆記 part five

     kafka 源:         Kafka 源是Apache Kafka 消耗者,讀取來自kafka主題的資訊。如果你有多個Kafka源在執行,你可以給他們配置一樣的使用者群組,以便每個源都讀取一組唯一的主題分割槽。                 要注

Shiro官方之第一個Shiro程式

Your First Apache Shiro Application If you’re new to Apache Shiro, this short tutorial will show you how to set up an initial and v

Apache Flink官方Apache Flink介紹

原文連結 譯者:ivansong 下面是關於Apache Flink(以下簡稱Filnk)框架和流式計算的概述。為了更專業、更技術化的介紹,在Flink文件中推薦了一些“概念性”的文章。 1、無窮資料集的持續計算 在我們詳細介紹Flink前,複習一下當我們計算資料選擇運算模型時,很可能會遇到

Apache Hive官方》首頁

原文連結  譯者:BJdaxiang Apache Hive是一款資料倉庫軟體,通過SQL使得分散式儲存系統中的大的資料集的讀、寫和管理變得容易。使用者可以使用自帶的命令列工具和JDBC驅動用來連線Hive。 開始Apache Hive之旅 在我們的wiki上了解更多關於Hive的功能。

Apache Storm 官方 —— 配置

原文連結    譯者:魏勇 Storm 有大量配置項用於調整 nimbus、supervisors 和拓撲的行為。有些配置項是系統級的配置項,在拓撲中不能修改,另外一些配置項則是可以在拓撲中修改的。 每一個配置項都在 Storm 程式碼庫的 defaults.yaml 中有一個預設值。可以通過

Apache Storm 官方 —— 本地模式

原文連結    譯者:魏勇 本地模式是一種在本地程序中模擬 Storm 叢集的工作模式,對於開發和測試拓撲很有幫助。在本地模式下執行拓撲與在叢集模式下執行拓撲的方式很相似。 建立一個程序內的“叢集”只需要使用 LocalCluster 類即可,例如: import backtype.sto

Apache RocketMQ使用者指南》官方

本章節主要詳細介紹如何在本地計算機上設定RocketMQ訊息系統以傳送和接收訊息. 前置條件 假定安裝了以下軟體: 推薦64bit OS, Linux/Unix/Mac系統; 64bit JDK 1.8+; Maven 3.2.x Git 從釋出版下載並構建 點選 這裡 下載4.2.0發行版原始碼. 你

Apache Flink 官方》前言

原文連結 譯者:ivansong 本文件針對的是Apache Flink的 1.2.0版本。 Apache Flink是一個分散式流式和批量資料處理程式的開源平臺。Flink的核心是流式資料引擎,Flink通過資料流的分散式計算的方式提供資料的分發、通訊和容錯。Flink也構建了流引擎之上的批

Apache Flink官方》程式設計模型

原文連結   譯者:魏勇 抽象層次 Flink 能夠為流式計算或批處理應用提供多種層次的抽象介面。 最低階的抽象介面是狀態化的資料流介面。這個介面是通過 ProcessFunction 整合到 資料流 API 中的。此類介面讓使用者可以使用連續的容錯狀態,並且可以不受限制地處理多個數據

Apache Thrift官方》簡介

Apache Thrift 最後修改時間: 2017-11-11 簡介 Thrift是一個輕量級、語言無關的軟體棧,它具有一套為RPC通訊生成程式碼的機制。Thrift為資料的傳輸、序列化,以及應用層處理提供了乾淨的抽象。採用這種抽象棧,它的程式碼生成器僅使用一種簡潔的定義語言作為輸入,便能

Apache Zookeeper 官方》管理分散式系統就像管理動物園一樣

原文連結 譯者:方騰飛,JIT Zookeeper 是一個高效能的分散式應用協調服務框架. 它以一種簡單介面的形式暴露了一系列的通用服務,比如命名,配置管理,同步和分組等。 因此你不必從一堆草稿中去實現他們。你可以使用現成的東西去實現一致性,分組管理,機器選擇和已經存在的一些協議。同時你能夠用

Apache Storm 官方 —— Trident Spouts

原文連結    譯者:魏勇 與一般的 Storm API 一樣,spout 也是 Trident 拓撲的資料來源。不過,為了實現更復雜的功能服務,Trident Spout 在普通的 Storm Spout 之上另外提供了一些 API 介面。 資料來源、資料流以及基於資料流更新 state(比

Apache Storm 官方 —— FAQ

原文連結    譯者:魏勇 Storm 最佳實踐 關於配置 Storm + Trident 的建議 worker 的數量最好是伺服器數量的倍數;topology 的總併發度(parallelism)最好是 worker 數量的倍數;Kafka 的分割槽數(partitions)最好是 Spo