[Architect] Java Apache Shiro authority validation framework to explain (Spring + SpringMVC + MyBatis + Shiro integration)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/ylcto/article/details/101549560

[Architect] Java permissions verification framework to explain the Apache Shiro

This course Deep stepped learning. Course contents basic practical cases to explain, Apache Shiro security framework compared with the Spring framework, more lightweight, easy to learn and simple, feature-rich.

Scan code start learning:
Here Insert Picture Description
Shiro learning comprises the following aspects:

| - Authentication:

身份验证是身份验证的过程-您正在尝试验证用户的身份。为此,用户需要提供系统可以理解和信任的某种身份证明。
Shiro框架旨在使身份验证尽可能简洁和直观,同时提供丰富的功能。以下是Shiro身份验证功能的重点。

| - role authorization:

	授权,也称为访问控制,是确定对应用程序中资源的访问权限的过程。换句话说,确定“谁有权访问什么”。授权用于回答安全性问题,例如“是否允许用户编辑帐户”,“是否允许该用户查看此网页”,“该用户是否有权访问”这些都是决定用户有权访问哪些内容的决定,因此都代表授权检查。
	授权是任何应用程序的关键要素,但它很快就会变得非常复杂。Shiro的目标是消除授权方面的许多复杂性,以便您可以更轻松地构建安全软件。以下是Shiro授权功能的重点。

| - Data encryption:

	密码学是一种通过隐藏信息或将其转换为无用信息来保护信息免受不希望的访问的做法,因此其他人都无法阅读。Shiro专注于密码学的两个核心要素:使用公钥或私钥对诸如电子邮件之类的数据进行加密的密码,以及不可逆地对诸如密码之类的数据进行加密的哈希(即消息摘要)。
	Shiro密码术的主要目标是解决传统上极为复杂的领域,并为我们其他人提供便利,同时提供一组强大的加密功能。

| - Session Management:

	会话是用户在使用应用程序时一段时间内随身携带的数据桶。传统上,会话是Web或EJB环境专有的。不再!Shiro 为任何应用程序环境启用会话。此外,Shiro还提供了许多其他出色的功能来帮助您管理会话。

| - WEB Support:

	尽管Apache Shiro旨在用于保护任何基于JVM的应用程序,但是最常用于保护Web应用程序。它极大地简化了基于简单URL模式匹配和过滤器链定义来保护Web应用程序的方式。除了Shiro的API,Shiro的Web支持还包括丰富的JSP标记库,用于控制页面输出

| - plug-in integration:

Shiro已被下载超过一百万次,并在成千上万家公司中投入生产。原因之一:它与其他技术和框架很好地集成在一起。
这些集成得到Apache Shiro开发团队的支持。想帮助他们变得更好吗?贡献回到项目!
Spring Application Framework将Shiro集成到独立的或基于Web的Spring应用程序中。
Guice依赖注入框架用于使用标准Guice约定和机制的基于Guice的应用程序。
CAS SSO服务器用Jasig CAS SSO服务器保护您的WebApp。

shiro whole learning process configuration files are very cured, after writing a copy of other projects can be used directly. But also it provides 10 minutes of official study guide: http: //shiro.apache.org/10-minute-tutorial.html.

Download

  1. Ensure you have JDK 1.6+ and Maven 3.0.3+ installed.

  2. Download the lastest “Source Code Distribution” from the Download page. In this example, we’re using the 1.4.1 release distribution.

  3. Unzip the source package:

    $ unzip shiro-root-1.4.1-source-release.zip
    
  4. Enter the quickstart directory:

    $ cd shiro-root-1.4.1/samples/quickstart
    
  5. Run the QuickStart:

    $ mvn compile exec:java
    

    Java document tells us that more than the minimum required version 1.6, Maven 3.0.3 version requires at least. Once you have downloaded the official source code that we can try to learn these classes and inheritance.

    Shiro's core is the Subject, all the code to start a car:

    Subject currentUser = SecurityUtils.getSubject();
    

    Next we implement basic user authentication:

    ### shiro.ini配置
    [users]
    admin=hello
    xmkeshe=java
    

    Write code to verify operation of certification:

    package cn.xmkeshe.demo;
    import org.apache.shiro.SecurityUtils;
    import org.apache.shiro.authc.UsernamePasswordToken;
    import org.apache.shiro.mgt.DefaultSecurityManager;
    import org.apache.shiro.realm.text.IniRealm;
    import org.apache.shiro.subject.Subject;
    import java.util.HashSet;
    import java.util.Set;
    public class ShiroDemo {
     public static void main(String[] args) {
     // 使用 IniRealm 获取 shiro-config.ini 文件
     IniRealm iniRealm = new IniRealm("classpath:shiro-config.ini");
     // 创建一个 DefaultSecurityManager 实例
     DefaultSecurityManager securityManager = new DefaultSecurityManager();
     // Set<Realm> allRealm = new HashSet<Realm>();
     // allRealm.add(iniRealm);
     securityManager.setRealm(iniRealm);
     // shiro 有提供一个专门用户处理认证的操作类
     SecurityUtils.setSecurityManager(securityManager);
     // 获取进行用户名和密码认证的接口对象
     Subject subject = SecurityUtils.getSubject();
     // 定义 token 保存用户名和密码信息
     UsernamePasswordToken token = new UsernamePasswordToken("admin","hello");
     // 实现用户登录
     subject.login(token);
     System.out.println(subject.getPrincipal()); // 获取用户名
     subject.logout(); // 退出系统
     }
    }
    

    If there are mistakes, it represents the wrong password authentication failure:

    Exception in thread "main" org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token
    

    We discuss together the curriculum more about Apache Shiro welcome everyone Jiaru Xin Mao Java community college.

    Course Q micro letter: kylctolook forward to meet you.
    Scan code to add friends

Guess you like

Origin blog.csdn.net/ylcto/article/details/101549560
Recommended