Shiro
Indroduction
Shiro is an easy-to-use Java security framework, that works both on web and standalone applications.
Features
Highlights
- Multi
realm
s support. - Pluggable data storage. (
realm
,session
) - Cryptography.
- SSO support.
- Web friendly. (URL-specific filter chains)
- OAuth, CAS, SAML, OpenID Connect, LDAP, JWT… support. pac4j
- Popular web framework support: Spring MVC, Play!, Lift, Wicket, Dropwizard
Components
Subject
The current executing user.
|
|
Almost the only object you would cope with in your application.
SecurityManager
The heart of shiro architecture, who does the haavy lifting for Subject
behind the scenes.
SessionManager
Manages creation, maintainance, clean-up of sessions.
Realm
Storages for users, roles, permissions.
A Realm is essentially a security-specific DAO.
Authenticator
Processing the login
logic.
Authorizer
Performs authorization operations on any given Subject
(a.k.a. user).
CacheManager
Maintains the lifecycle of cache instances, it is a wrapper of the popular cache provider, such as EhCache, JCS …
SubjectDAO
- create (org.apache.shiro.session.Session)
- readSession (java.io.Serializable)
- update (org.apache.shiro.session.Session)
- delete (org.apache.shiro.session.Session)
CredentialsMatcher
Determines if an AuthenticationToken
‘s provided credentials matches a corresponding account’s credentials stored n the realm
(s).
Filter
Filter Name | Class | Description |
---|---|---|
anon | AnonymousFilter | no security check |
authc | FormAuthenticationFilter | do login or redirect to loginUrl |
logout | LogoutFilter | do logout |
noSessionCreation | NoSessionCreationFilter | making subject.getSession(true) throws exception |
perms | PermissionsAuthorizationFilter | permission specific check |
port | PortFilter | accept request only on that port, default 80 |
rest | HttpMethodPermissionFilter | /user/** = rest[user] -> Subject.isPermitted("user:read") |
roles | RolesAuthorizationFilter | denies access if the user has none of the roles specified |
ssl | SslFilter | denies access if the schema is not https |
user | UserFilter | requires authenticated or remembered |
Configuration
ini
Sample shiro.ini
① Configuration for the authc authentication filer.
② Configuration for the passwordMatcher and passwordService, which are components for
password verification and matching.
③ The definition of the Datasource in this example is a JDBC DataSource.
④ Configuration for the Realm in this example is a JDBC Realm.
⑤ This assigns the configured Realm to the Siro SecurityManager.
⑥ This assigns URL patterns to the appropriate filters.