新闻中心

01-16
2018
传爱奇艺在美提交IPO申请 融资10亿美元0101
1月16日消息,外媒汤森路透旗下IFR报道,百度旗下流媒体视频服务爱奇艺已秘密在美国提交了IPO(首次公开招股)申请,融资约10亿美元。对此消息,爱奇艺方面拒绝置评。传爱奇艺在美提交IPO申请(图片来自baidu)      外媒援引消息人士说法,爱奇艺IPO可能会在今年第一季度末或第二季度初完成。其实早在2017年9月,彭博社就援引两位知情人士说法,爱奇艺计划最早于2018年在美国IPO,届时的估值可能超过80亿美元。        根据百度递交给SEC的文件显示,旗下视频业务爱奇艺2016年营收112.83亿元(16.25亿美元),较2015年同期的52.95亿元增长113.1%。爱奇艺2015年营收则较2014年的28.7亿元增长84.3%。2016年,爱奇艺运营亏损27.65亿元(3.98亿美元),较2015年同期的亏损23.83亿元有所增加。不过,相比爱奇艺的营收增长,其运营亏损的增幅并不大。       公开资料显示,爱奇艺,原名奇艺,于2010年4月22日正式上线。2011,百度耗资4500万美元认购奇艺B轮优先股,并于2012年11月3日,收购原爱奇艺第二大股东普罗维登斯所持股份,成为其单一最大股东。       2013年,百度斥资3.7亿美元收购PPS,实现PPS与爱奇艺的合并,之后在自制剧,产品建设,独播等很多领域动作频繁。       2016年,百度公司发布公告称,董事会收到了来自百度董事长兼CEO李彦宏和爱奇艺CEO龚宇的非约束性提议,计划收购百度所持有的爱奇艺股份,估值28亿美元。仅仅过了几个月,百度董事长兼首席执行官李彦宏和爱奇艺首席执行官龚宇代表买方财团致信百度董事会,宣布撤回今年2月提出的爱奇艺私有化要约。
07-11
2017
基于Maven+SSM整合shiro+Redis实现后台管理项目 0101
本项目由卖咸鱼叔叔开发完成,欢迎大神指点,慎重抄袭!参考了sojson提供的demo,和官方文档介绍。完整实现了用户、角色、权限CRUD及分页,还有shiro的登录认证+授权访问控制。项目架构:Maven + SpringMVC + Spring + Mybatis + Shiro + Redis数据库:MySql前端框架:H-ui 首先创建Maven项目1.pom.xml 加入依赖包<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>sys</groupId>  <artifactId>sys</artifactId>  <packaging>war</packaging>  <version>0.0.1-SNAPSHOT</version>  <name>sys Maven Webapp</name>  <url>http://maven.apache.org</url>        <dependencies>            <!-- spring依赖管理 -->            <!-- spring-context 是使用spring的最基本的环境支持依赖,会传递依赖core、beans、expression、aop等基本组件,以及commons-logging、aopalliance -->            <dependency>                <groupId>org.springframework</groupId>                <artifactId>spring-context</artifactId>                <version>4.3.2.RELEASE</version>            </dependency>                        <!-- spring-context-support 提供了对其他第三方库的内置支持,如quartz等 -->            <dependency>                <groupId>org.springframework</groupId>                <artifactId>spring-context-support</artifactId>                <version>4.3.2.RELEASE</version>            </dependency>                        <!-- spring-orm 是spring处理对象关系映射的组件,传递依赖了jdbc、tx等数据库操作有关的组件 -->            <dependency>                <groupId>org.springframework</groupId>                <artifactId>spring-orm</artifactId>                <version>4.3.2.RELEASE</version>            </dependency>                        <!-- spring-webmvc 是spring处理前端mvc表现层的组件,也即是springMVC,传递依赖了web等web操作有关的组件 -->            <dependency>                <groupId>org.springframework</groupId>                <artifactId>spring-webmvc</artifactId>                <version>4.3.2.RELEASE</version>            </dependency>                        <!-- spring-aspects 增加了spring对面向切面编程的支持,传递依赖了aspectjweaver -->            <dependency>                <groupId>org.springframework</groupId>                <artifactId>spring-aspects</artifactId>                <version>4.3.2.RELEASE</version>            </dependency>                                    <!-- json解析, springMVC 需要用到 -->            <dependency>                <groupId>com.fasterxml.jackson.core</groupId>                <artifactId>jackson-databind</artifactId>                <version>2.6.0</version>            </dependency>                        <!-- mybatis依赖管理 -->            <!-- mybatis依赖 -->            <dependency>                <groupId>org.mybatis</groupId>                <artifactId>mybatis</artifactId>                <version>3.3.0</version>            </dependency>                        <!-- mybatis和spring整合 -->            <dependency>                <groupId>org.mybatis</groupId>                <artifactId>mybatis-spring</artifactId>                <version>1.2.3</version>            </dependency>                        <!-- mybatis 分页插件 -->            <dependency>                <groupId>com.github.pagehelper</groupId>                <artifactId>pagehelper</artifactId>                <version>4.1.6</version>            </dependency>                        <!-- mysql驱动包依赖 -->            <dependency>                <groupId>mysql</groupId>                <artifactId>mysql-connector-java</artifactId>                <version>5.1.37</version>            </dependency>                        <!-- c3p0依赖 -->            <dependency>                <groupId>com.mchange</groupId>                <artifactId>c3p0</artifactId>                <version>0.9.5</version>            </dependency>                        <!-- redis java客户端jar包 -->            <dependency>                <groupId>redis.clients</groupId>                <artifactId>jedis</artifactId>                <version>2.9.0</version>            </dependency>                        <!-- 文件上传 -->            <dependency>                <groupId>commons-fileupload</groupId>                <artifactId>commons-fileupload</artifactId>                <version>1.3.1</version>            </dependency>                        <dependency>                <groupId>commons-io</groupId>                <artifactId>commons-io</artifactId>                <version>2.5</version>            </dependency>                        <dependency>                <groupId>org.apache.commons</groupId>                <artifactId>commons-email</artifactId>                <version>1.4</version>            </dependency>                        <dependency>                <groupId>org.apache.logging.log4j</groupId>                <artifactId>log4j-core</artifactId>                <version>2.7</version>            </dependency>                        <dependency>                <groupId>org.apache.httpcomponents</groupId>                <artifactId>httpclient</artifactId>                <version>4.5.2</version>            </dependency>                        <dependency>                <groupId>org.apache.httpcomponents</groupId>                <artifactId>httpcore</artifactId>                <version>4.4.4</version>            </dependency>                                    <!-- junit -->            <dependency>                <groupId>junit</groupId>                <artifactId>junit</artifactId>                <version>4.11</version>            </dependency>                        <!-- servlet依赖 -->            <dependency>                <groupId>javax.servlet</groupId>                <artifactId>javax.servlet-api</artifactId>                <version>3.1.0</version>                <scope>provided</scope>            </dependency>            <!-- jsp依赖 -->            <dependency>                <groupId>javax.servlet.jsp</groupId>                <artifactId>jsp-api</artifactId>                <version>2.2</version>                <scope>provided</scope>            </dependency>            <!-- jstl依赖 -->            <dependency>                <groupId>org.glassfish.web</groupId>                <artifactId>jstl-impl</artifactId>                <version>1.2</version>                <exclusions>                    <exclusion>                        <groupId>javax.servlet</groupId>                        <artifactId>servlet-api</artifactId>                    </exclusion>                    <exclusion>                        <groupId>javax.servlet.jsp</groupId>                        <artifactId>jsp-api</artifactId>                    </exclusion>                </exclusions>            </dependency>                                <dependency>            <groupId>net.sf.json-lib</groupId>            <artifactId>json-lib</artifactId>            <version>2.4</version>            <classifier>jdk15</classifier>        </dependency>        <dependency>            <groupId>commons-httpclient</groupId>            <artifactId>commons-httpclient</artifactId>            <version>3.1</version>        </dependency>                      <!-- shiro依赖包 -->        <dependency>              <groupId>org.apache.shiro</groupId>              <artifactId>shiro-core</artifactId>              <version>1.2.3</version>          </dependency>          <dependency>              <groupId>org.apache.shiro</groupId>              <artifactId>shiro-spring</artifactId>              <version>1.2.3</version>          </dependency>          <dependency>              <groupId>org.apache.shiro</groupId>              <artifactId>shiro-cas</artifactId>              <version>1.2.3</version>              <exclusions>                  <exclusion>                      <groupId>commons-logging</groupId>                      <artifactId>commons-logging</artifactId>                  </exclusion>              </exclusions>          </dependency>          <dependency>              <groupId>org.apache.shiro</groupId>              <artifactId>shiro-web</artifactId>              <version>1.2.3</version>          </dependency>          <dependency>              <groupId>org.apache.shiro</groupId>              <artifactId>shiro-ehcache</artifactId>              <version>1.2.3</version>          </dependency>          <dependency>              <groupId>org.apache.shiro</groupId>              <artifactId>shiro-quartz</artifactId>              <version>1.2.3</version>          </dependency>        <!-- shiro end -->                                    </dependencies>         <build>        <finalName>sys</finalName>        <plugins>            <!-- 指定JDK编译版本 -->            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-compiler-plugin</artifactId>                <version>3.1</version>                  <configuration>                    <source>1.8</source>                  <target>1.8</target>                </configuration>            </plugin>        </plugins>    </build></project>2.SSM框架配置beans.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:mvc="http://www.springframework.org/schema/mvc"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:aop="http://www.springframework.org/schema/aop"    xmlns:tx="http://www.springframework.org/schema/tx"    xsi:schemaLocation="http://www.springframework.org/schema/beans                        http://www.springframework.org/schema/beans/spring-beans.xsd                          http://www.springframework.org/schema/mvc                        http://www.springframework.org/schema/mvc/spring-mvc.xsd                        http://www.springframework.org/schema/context                        http://www.springframework.org/schema/context/spring-context.xsd                        http://www.springframework.org/schema/aop                        http://www.springframework.org/schema/aop/spring-aop.xsd                        http://www.springframework.org/schema/tx                        http://www.springframework.org/schema/tx/spring-tx.xsd">        <!-- 数据库连接池 -->    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">        <property name="driverClass" value="com.mysql.jdbc.Driver"/>          <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/sys_test?characterEncoding=UTF8&amp;allowMultiQueries=true"/>        <property name="user" value="root"/>          <property name="password" value="root"/>          <property name="maxPoolSize" value="100"/>          <property name="minPoolSize" value="10"/>          <property name="maxIdleTime" value="60"/>      </bean>        <!-- mybatis 的 sqlSessionFactory -->    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="dataSource"/>        <property name="configLocation" value="classpath:mybatis-config.xml"></property>    </bean>        <!-- mybatis mapper接口自动扫描、自动代理 -->    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">       <property name="basePackage" value="com.sys.mapper" />    </bean>        <!-- 事务管理器 -->    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">        <property name="dataSource" ref="dataSource" />    </bean>    <!-- 事务传播行为 -->    <tx:advice id="txAdvice" transaction-manager="txManager">        <tx:attributes>            <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>            <tx:method name="page*" propagation="SUPPORTS" read-only="true"/>            <tx:method name="is*" propagation="SUPPORTS" read-only="true"/>            <tx:method name="*" propagation="REQUIRED" read-only="false"/>        </tx:attributes>    </tx:advice>    <!-- 织入事务增强功能 -->    <aop:config>        <aop:pointcut id="txPointcut" expression="execution(* com.sys.service..*.*(..))" />        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />    </aop:config>     <!-- 配置扫描spring注解(@Component、@Controller、@Service、@Repository)时扫描的包,同时也开启了spring注解支持 -->     <!-- 这个地方只需要扫描service包即可,因为controller包由springMVC配置扫描,mapper包由上面的mybatis配置扫描 -->    <context:component-scan base-package="com.sys.service"></context:component-scan>    <!-- 开启spring aop 注解支持,要想aop真正生效,还需要把切面类配置成bean -->    <aop:aspectj-autoproxy/>         </beans>dispatcher-servlet.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:mvc="http://www.springframework.org/schema/mvc"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:aop="http://www.springframework.org/schema/aop"    xmlns:tx="http://www.springframework.org/schema/tx"    xsi:schemaLocation="http://www.springframework.org/schema/beans                        http://www.springframework.org/schema/beans/spring-beans.xsd                          http://www.springframework.org/schema/mvc                        http://www.springframework.org/schema/mvc/spring-mvc.xsd                        http://www.springframework.org/schema/context                        http://www.springframework.org/schema/context/spring-context.xsd                        http://www.springframework.org/schema/aop                        http://www.springframework.org/schema/aop/spring-aop.xsd                        http://www.springframework.org/schema/tx                        http://www.springframework.org/schema/tx/spring-tx.xsd">                            <!-- 配置扫描spring注解时扫描的包,同时也开启了spring注解支持 -->    <context:component-scan base-package="com.sys" />    <!-- 开启springMVC相关注解支持 -->    <mvc:annotation-driven />        <!-- 开启spring aop 注解支持 -->    <aop:aspectj-autoproxy/>        <!-- 约定大于配置:约定视图页面的全路径 = prefix + viewName + suffix -->    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="prefix" value="/WEB-INF/jsp/"></property>        <property name="suffix" value=".jsp"></property>    </bean>    <!-- 文件上传解析器 -->    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">        <property name="maxUploadSize" value="104857600" />        <property name="defaultEncoding" value="UTF-8" />        <property name="maxInMemorySize" value="40960" />    </bean>        <!-- 资源映射 -->    <mvc:resources location="/css/" mapping="/css/**" />    <mvc:resources location="/js/" mapping="/js/**" />    <mvc:resources location="/images/" mapping="/images/**" />    <mvc:resources location="/skin/" mapping="/skin/**" />    <mvc:resources location="/lib/" mapping="/lib/**" /> </beans>mybatis-config.xml<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration>    <settings>        <!-- 使用log4j2作为日志实现 -->        <setting name="logImpl" value="LOG4J2"/>    </settings>    <typeAliases>        <!-- 为指定包下的pojo类自动起别名 -->        <package name="com.sys.pojo"/>    </typeAliases>        <mappers>        <!-- 自动加载指定包下的映射配置文件 -->        <package name="com.sys.mapper"/>    </mappers></configuration>Log4j2.xml <?xml version="1.0" encoding="UTF-8"?>  <!DOCTYPE xml><Configuration status="OFF">    <Appenders>        <Console name="CONSOLE" target="SYSTEM_OUT">            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{0} - %msg%n" />        </Console>        <RollingFile name="ROLLING" fileName="/logs/ups-manager/log.log"             filePattern="/logs/log_%d{yyyy-MM-dd}_%i.log">            <PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/>            <Policies>                <TimeBasedTriggeringPolicy modulate="true" interval="1"/>                <SizeBasedTriggeringPolicy size="1024 KB"/>            </Policies>            <DefaultRolloverStrategy max="100"/>        </RollingFile>    </Appenders>        <Loggers>        <Root level="debug">            <AppenderRef ref="CONSOLE" />            <AppenderRef ref="ROLLING"/>        </Root>                <!-- 控制某些包下的类的日志级别 -->        <Logger name="org.mybatis.spring" level="error">            <AppenderRef ref="CONSOLE"/>        </Logger>    </Loggers></Configuration>web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">    <!-- 初始化spring容器 -->    <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>        <!-- 设置post请求编码和响应编码 -->    <filter>        <filter-name>characterEncodingFilter</filter-name>        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>            <init-param>                <param-name>encoding</param-name>                <param-value>UTF-8</param-value>            </init-param>        <init-param>            <!-- 为true时也对响应进行编码 -->            <param-name>forceEncoding</param-name>            <param-value>true</param-value>        </init-param>    </filter>    <filter-mapping>        <filter-name>characterEncodingFilter</filter-name>        <!-- 设置为/*时才会拦截所有请求,和servlet有点区别,servlet设置为/*只拦截所有的一级请求,如/xx.do,而不拦截/xx/xx.do;servlet设置为/时才会拦截所有请求 -->        <url-pattern>/*</url-pattern>    </filter-mapping>    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>            classpath:spring-shiro.xml,            classpath:beans.xml,            classpath:dispatcher-servlet.xml        </param-value>    </context-param>          <!-- The filter-name matches name of a 'shiroFilter' bean inside applicationContext.xml -->    <filter>        <filter-name>shiroFilter</filter-name>        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>        <init-param>            <param-name>targetFilterLifecycle</param-name>            <param-value>true</param-value>        </init-param>    </filter>          <filter-mapping>        <filter-name>shiroFilter</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>        <!-- 初始化springMVC容器 -->    <servlet>        <servlet-name>dispatcher</servlet-name>        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        <init-param>            <param-name>contextConfigLocation</param-name>            <param-value>classpath:dispatcher-servlet.xml</param-value>        </init-param>        <load-on-startup>1</load-on-startup>    </servlet>      <servlet-mapping>        <servlet-name>dispatcher</servlet-name>        <url-pattern>/</url-pattern>    </servlet-mapping>        </web-app>3.实现用户、角色、权限页面操作功能,这里就不贴代码了4.接下来就是shiro,登录认证和授权只需要继承AuthorizingRealm,其继承了 AuthenticatingRealm(即身份验证),而且也间接继承了 CachingRealm(带有缓存实现)。身份认证重写doGetAuthenticationInfo方法,授权重写doGetAuthorizationInfo方法。Shiro 默认提供的 Realm 身份认证流程 流程如下:首先调用 Subject.login(token) 进行登录,其会自动委托给 Security Manager,调用之前必须通过 SecurityUtils.setSecurityManager() 设置;SecurityManager 负责真正的身份验证逻辑;它会委托给 Authenticator 进行身份验证;Authenticator 才是真正的身份验证者,Shiro API 中核心的身份认证入口点,此处可以自定义插入自己的实现;Authenticator 可能会委托给相应的 AuthenticationStrategy 进行多 Realm 身份验证,默认 ModularRealmAuthenticator 会调用 AuthenticationStrategy 进行多 Realm 身份验证;Authenticator 会把相应的 token 传入 Realm,从 Realm 获取身份验证信息,如果没有返回 / 抛出异常表示身份验证失败了。此处可以配置多个 Realm,将按照相应的顺序及策略进行访问。 代码实现:/** * */package com.sys.shiro;import javax.annotation.Resource;import org.apache.shiro.SecurityUtils;import org.apache.shiro.authc.AccountException;import org.apache.shiro.authc.AuthenticationInfo;import org.apache.shiro.authc.AuthenticationToken;import org.apache.shiro.authc.DisabledAccountException;import org.apache.shiro.authc.SimpleAuthenticationInfo;import org.apache.shiro.authz.AuthorizationInfo;import org.apache.shiro.authz.SimpleAuthorizationInfo;import org.apache.shiro.realm.AuthorizingRealm;import org.apache.shiro.subject.PrincipalCollection;import org.apache.shiro.subject.SimplePrincipalCollection;import org.apache.shiro.util.ByteSource;import com.sys.pojo.AdminUser;import com.sys.service.AdminUserService;/**  * @ClassName: MyRealm  * @Description: shiro 认证 + 授权   重写 */public class MyRealm extends AuthorizingRealm {    @Resource    AdminUserService adminUserService;            /* (non-Javadoc)     * @see org.apache.shiro.realm.AuthorizingRealm#doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)     */    /**     * 授权Realm     */    @Override    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {        String account = (String)principals.getPrimaryPrincipal();        AdminUser pojo = new AdminUser();        pojo.setAccount(account);        Long userId = adminUserService.selectOne(pojo).getId();        SimpleAuthorizationInfo info =  new SimpleAuthorizationInfo();        /**根据用户ID查询角色(role),放入到Authorization里.*/        info.setRoles(adminUserService.findRoleByUserId(userId));        /**根据用户ID查询权限(permission),放入到Authorization里.*/        info.setStringPermissions(adminUserService.findPermissionByUserId(userId));        return info;    }    /* (non-Javadoc)     * @see org.apache.shiro.realm.AuthenticatingRealm#doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken)     */    /**     * 登录认证Realm     */    @Override    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {        String username = (String)token.getPrincipal();        String password = new String((char[])token.getCredentials());        AdminUser user = adminUserService.login(username, password);        if(null==user){            throw new AccountException("帐号或密码不正确!");        }        if(user.getIsDisabled()){            throw new DisabledAccountException("帐号已经禁止登录!");        }        //**密码加盐**交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配        return new SimpleAuthenticationInfo(user.getAccount(),user.getPassword(),ByteSource.Util.bytes("3.14159"), getName());    }        /**     * 清空当前用户权限信息     */    public  void clearCachedAuthorizationInfo() {        PrincipalCollection principalCollection = SecurityUtils.getSubject().getPrincipals();        SimplePrincipalCollection principals = new SimplePrincipalCollection(                principalCollection, getName());        super.clearCachedAuthorizationInfo(principals);    }    /**     * 指定principalCollection 清除     */    public void clearCachedAuthorizationInfo(PrincipalCollection principalCollection) {        SimplePrincipalCollection principals = new SimplePrincipalCollection(                principalCollection, getName());        super.clearCachedAuthorizationInfo(principals);    }        }shiro的配置:spring-shiro.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"    xmlns:context="http://www.springframework.org/schema/context"    xsi:schemaLocation="       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">        <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">        <!--shiro 核心安全接口  -->        <property name="securityManager" ref="securityManager"></property>        <!--登录时的连接  -->        <property name="loginUrl" value="/login"></property>              <!--未授权时跳转的连接  -->        <property name="unauthorizedUrl" value="/unauthorized.jsp"></property>           <!-- 其他过滤器 -->           <property name="filters">               <map>                   <!-- <entry key="rememberMe" value-ref="RememberMeFilter"></entry> -->                   <entry key="kickout" value-ref="KickoutSessionControlFilter"/>               </map>           </property>                      <!-- 读取初始自定义权限内容-->        <!-- 如果使用authc验证,需重写实现rememberMe的过滤器,或配置formAuthenticationFilter的Bean -->        <property name="filterChainDefinitions">            <value>                /js/**=anon                /css/**=anon                /images/**=anon                /skin/**=anon                   /lib/**=anon                   /nodel/**=anon                   /WEB-INF/jsp/**=anon                   /adminUserLogin/**=anon                                                             /**/submitLogin.do=anon                /**=user,kickout            </value>        </property>    </bean>                    <!-- Shiro生命周期处理器-->    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />        <!-- 安全管理器 -->    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">        <property name="realm" ref="MyRealm"/>        <property name="rememberMeManager" ref="rememberMeManager"/>    </bean>        <bean id="MyRealm" class="com.sys.shiro.MyRealm" >        <property name="cachingEnabled" value="false"/>    </bean>        <!-- 相当于调用SecurityUtils.setSecurityManager(securityManager) -->    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">        <property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/>        <property name="arguments" ref="securityManager"/>    </bean>        <!-- sessionIdCookie:maxAge=-1表示浏览器关闭时失效此Cookie -->    <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie">          <constructor-arg value="rememberMe"/>          <property name="httpOnly" value="true"/>          <property name="maxAge" value="-1"/>      </bean>            <!-- 用户信息记住我功能的相关配置 -->    <bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie">        <constructor-arg value="rememberMe"/>        <property name="httpOnly" value="true"/>        <!-- 配置存储rememberMe Cookie的domain为 一级域名        这里如果配置需要和Session回话一致更好。-->        <property name="maxAge" value="604800"/><!-- 记住我==保留Cookie有效7天 -->    </bean>        <!-- rememberMe管理器 -->    <bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">        <!-- rememberMe cookie加密的密钥 建议每个项目都不一样 默认AES算法 密钥长度(128 256 512 位)-->        <property name="cipherKey"                  value="#{T(org.apache.shiro.codec.Base64).decode('3AvVhmFLUs0KTA3Kprsdag==')}"/>        <property name="cookie" ref="rememberMeCookie"/>    </bean>        <!-- 记住我功能设置session的Filter -->    <bean id="RememberMeFilter" class="com.sys.shiro.RememberMeFilter" />        <!-- rememberMeParam请求参数是 boolean 类型,true 表示 rememberMe -->    <!-- shiro规定记住我功能最多得user级别的,不能到authc级别.所以如果使用authc,需打开此配置或重写实现rememberMe的过滤器 -->    <!-- <bean id="formAuthenticationFilter" class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">        <property name="rememberMeParam" value="rememberMe"/>    </bean> -->            <bean id="KickoutSessionControlFilter" class="com.sys.shiro.KickoutSessionControlFilter">    </bean>                  </beans>5.登录即密码失败多次后锁定/** * */package com.sys.controller;import java.util.LinkedHashMap;import java.util.Map;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.apache.shiro.SecurityUtils;import org.apache.shiro.authc.AccountException;import org.apache.shiro.authc.AuthenticationException;import org.apache.shiro.authc.DisabledAccountException;import org.apache.shiro.authc.ExcessiveAttemptsException;import org.apache.shiro.authc.UsernamePasswordToken;import org.apache.shiro.subject.Subject;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import com.sys.pojo.AdminUser;import com.sys.service.AdminUserService;import com.sys.common.JedisUtils;import com.sys.shiro.ShiroUtils;/**  * @ClassName: LoginController  * @Description: 登录*/@Controllerpublic class LoginController{    protected final static Logger logger = LogManager.getLogger(LoginController.class);    protected Map<String, Object> resultMap = new LinkedHashMap<String, Object>();        @Resource    AdminUserService adminUserService;        /**    * @Description: 登录认证    * @param um 登录账号    * @param pw 登录密码    * @param rememberMe 记住我    * @param request    * @return    * @throws      * @author lao    * @Date 2018年1月15日下午12:24:19    * @version 1.00     */    @RequestMapping(value="/submitLogin.do",method=RequestMethod.POST)    @ResponseBody    public Map<String,Object> submitLogin(String um,String pw,boolean rememberMe,HttpServletRequest request){                Subject subject = SecurityUtils.getSubject();        UsernamePasswordToken token = new UsernamePasswordToken(um,ShiroUtils.getStrByMD5(pw));                            try{                      token.setRememberMe(rememberMe);            subject.login(token);            JedisUtils.del(um);            logger.info("------------------身份认证成功-------------------");            resultMap.put("status", 200);            resultMap.put("message", "登录成功!");        } catch (DisabledAccountException dax) {              logger.info("用户名为:" + um + " 用户已经被禁用!");            resultMap.put("status", 500);            resultMap.put("message", "帐号已被禁用!");        } catch (ExcessiveAttemptsException eae) {              logger.info("用户名为:" + um + " 用户登录次数过多,有暴力破解的嫌疑!");            resultMap.put("status", 500);            resultMap.put("message", "登录次数过多!");        } catch (AccountException ae) {              logger.info("用户名为:" + token.getPrincipal() + " 帐号或密码错误!");            String excessiveInfo = ExcessiveAttemptsInfo(um);            if(null!=excessiveInfo){                resultMap.put("status", 500);                resultMap.p
06-17
2017
有关Servlet和JSP的梳理0101
大二第一学期的时候有学JSP的课,但是因为在开学之前做过JSP的小项目,所以一个学期的课也没听,直到期末考试成绩出来了,才回想JSP的内容还有多少记得,没想到模模糊糊也记不起多少,赶紧回头学回来。接下来是关于Servlet和JSP的梳理。-------------------------------------------------------------------------------------------------------------------------------------------------  Servlet是一个Java程序,一个Servlet应用有一个或多个Servlet程序,而且JSP页面也会被转换和编译成Servlet程序。  Servlet应用无法独立运行,必须运行在Servlet容器中。Servlet容器将用户的请求传递给Servlet应用,并将结果返回给用户。由于大部分Servlet应用都包含多个JSP页面,因此更准确地说是“Servlet/JSP应用”。  其中,Servlet API是开发Servlet的主要技术。而Servlet API有以下4个Java包:Java包包含的内容javax.servlet定义Servlet和Servlet容器之间契约的类和接口javax.servlet.http定义HTTP Servlet和Servlet容器之间契约的类和接口javax.servlet.annotation标注Servlet、Filter、Listener的标注。它还被标注原件定义元数据javax.servlet.descriptor包含提供程序化登陆web应用程序的配置信息的类型。  Servlet技术的核心是Servlet,它是所有Servlet类必须直接或间接实现的一个接口,而Servlet接口定义了Servlet与Servlet容器之间的契约。这个契约归结起来就是,Servlet容器将Servlet类载入内存,并在Servlet实例上调用具体的方法。当用户的请求使得Servlet容器调用Servlet的Service方法,会传入一个ServletRequest实例和一个ServletResponse实例,其中,ServletRequest中封装了当前的HTTP请求,而ServletResponse表示当前用户的HTTP响应。对于每一个应用程序,Servlet容器还会创建一个ServletContext实例,这个对象中封装了上下文(应用程序)的环境详情。每个上下文只有一个ServletContext,而且每个Servlet实例都有一个配置的ServletConfig。  Servlet的生命周期方法:  Servlet容器的生命周期方法作用init该方法在Servlet第一次被请求的时候,Servlet就会调用这个方法,而后不再被调用,所以可以用这个方法进行初始化工作。调用这个方法时,Servlet容器会传入一个ServletConfig。Service每当请求Servlet时,Servlet容器就会调用这个方法。第一次请求Servlet时,Servlet容器调用init方法和Service方法。后续的请求将只调用Service方法。destroy当要销毁Servlet时,Servlet容器就会调用这个方法。一般会在这个方法中编写清除代码。  在介绍一个Servlet中另外两个非生命周期的方法:Servlet容器的非生命周期方法作用getServletInfo这个方法会返回Servlet的描述getServletConfig这个方法会返回由Servlet容器传给init方法的ServletConfig。但是为了让getServletConfig返回一个非null值,必须将传给init方法的ServletConfig赋给一个类级变量。-------------------------------------------------------------------------------------------------------------------------------------------------   接下来是Servlet的各类接口:  ServletRequest 接口说明ServletRequest对于每一个HTTP请求,Servlet容器都会创建一个ServletRequest实例,并将它传给Servlet的Service方法。ServletRequest封装了关于这个请求的信息。  常用的方法有:    方法说明public int getContentLength()返回请求主体的字节数。public java.lang.String getContentType()返回请求主体的MIME类型。public java.lang.String getParameter(java.lang.String name)返回指定请求参数的值public java.lang.String getProtocol()返回这个HTTP请求的协议名称和版本  ServletResponse接口说明ServletResponse该接口表示一个Servlet响应。在调用Servlet的Service方法前,Servlet容器首先创建一个ServletResponse,并将它作为第二个参数传给Service方法。ServletResponse隐藏了向浏览器发送响应的复杂过程。  常用的方法: 方法说明getWriter()返回了一个可以向客户端发送文本的java.io.PrintWriter。默认情况下,PrintWriter对象使用ISO-8859-1编码。setContentType(“type”)设置响应的内容类型,并将”text/html”作为一个参数传入。如果没有设置相应内容类型,有些浏览器就会将HTML标签显示为普通文本。  ServletConfig  接口说明ServletConfig用于存储关于Servlet的配置信息。当Servlet容器初始化Servlet时,Servlet容器会给Servlet的init()方法传入一个ServletConfig。ServletConfig封装可以通过@WebServlet或描述符传给Servlet的配置信息。   常用的方法: 方法说明java.lang.String getInitParameter(java,lang.String name)为了从Servlet内部获取到初始参数的值,要在Servlet容器传给Servlet的init方法的ServletConfig中调用getInitParameter方法。java.util.Enumration<java.lang.String> getInitParameterNames()返回所有初始参数名称的一个Enumeration。String contactName = servletConfig.getInitParameter(“contactName”)获取contactName参数值  ServletContext接口说明ServletContext每个Web应用程序只有一个上下文,所以ServletContext可以存储这个上下文,并且ServletContext还可以共享从应用程序中的所有资料处访问到的信息,并且可以动态注册Web对象,而且是用ServletContext内部的Map保存。  常用的方法: 方法说明getServletContext().getInitParameter(String name)获取在项目下的web.xml中设置context的初始化参数this.getServletContext().log(“测试”)在web.xml文件中,使用logger元素来设置日志文件getAttribute(String name)/get AttributeNames()获取ServletContext中的属性setAttribute(String name, Object object)设置ServletContext中的属性removeAttribute(String name)移除ServletContext中的属性  GenericServlet接口说明GenericServletGenericServlet实现了Servlet和ServletConfig接口。将init方法中的ServletConfig赋给一个类级变量,以便可以通过getServletConfig获取,为Servlet接口中的所有方法提供默认的实现,而且提供包括ServletConfig中的方法。  Http Servlets    接口说明HttpServletHttpServlet类覆盖了javax.servlet.GenericServlet类。使用HttpServlet时,还要借助分别代表Servlet请求和Servlet响应的HttpServletRequest和HttpServletResponse对象。而HttpServlet与GenericServlet的差别在于,HttpServlet覆盖的是doGet或者doPost方法,而不是Service方法,而且使用的是HttpServletRequest和HttpServletResponse,而不是ServletRequest和ServletResponse。HttpServletRequest表示HTTP环境中的Servlet请求HttpServletResponse表示HTTP环境中的Servlet响应  各个接口常用的方法如下:  接口方法说明 HttpServletRequestjava.lang.String getContextPath()返回表示请求上下文的请求URI部分。 HttpServletRequestCookie[] getCookies()返回一个Cookie对象的数组。 HttpServletRequestjava.lang.String getHeader(java.lang.String name)返回指定HTTP标题的值。 HttpServletRequestjava.lang.String getMethod()返回生成这个请求的HTTP方法名称 HttpServletRequestjava.lang.String getQueryString()返回请求URL中的查询字符串。 HttpServletRequestHttpSession getSession()返回与这个请求相关的会话对象。如果没有,将创建一个新的会话对象。 HttpServletRequestHttpSession getSession(Boolean create)返回与这个请求相关的绘画对象,如果有,并且create参数为True,将创建一个新的会话对象。 HttpServletResponsevoid addCookie(Cookie cookie)给这个响应对象添加一个cookie。 HttpServletResponsevoid addHeader(java.lang.String name, java.lang.String value)给这个响应对象添加一个header。 HttpServletResponsevoid sendRedirect(java.lang.String location)发送一条响应码,将浏览器跳转到指定的位置。-------------------------------------------------------------------------------------------------------------------------------------------------  当用户提交HTML表单时,在表单元素中输入的值就会被当作请求参数发送到服务器。HTML输入域(文本域、隐藏域或者密码域)或者文本区的值,会被当作字符串发送到服务器。空的输入域或者文本区会发送空的字符串。  包含多个值的select元素发出一个字符串数组,可以通过ServletRequest.getParameterValues进行处理。  核查过的复选框会发送字符串"on"到服务器,未经核查的复选框则不向服务器发送任何内容,ServletRequest.getParameter(fieldName)返回null。  单选框将被选中按钮的值发送到服务器。如果没有选择任何按钮,将没有任何内容被发送到服务器,并且ServletRequest.getParameter(fieldName)返会null。  如果一个表单中包含多个输入同名的元素,那么所有值都会被提交,并且必须利用ServletRequest.getParameterValues来获取它们。ServletRequest.getParameter将只返回最后一个值。