Commit 1bf305cd authored by Paul0523's avatar Paul0523

重构代码

parent 6b7eed13
......@@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>bigsys</artifactId>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -22,25 +22,25 @@
<dependencies>
<dependency>
<groupId>com.paul</groupId>
<artifactId>dubbo</artifactId>
<groupId>com.bigsys</groupId>
<artifactId>bigsys-dubbo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.paul</groupId>
<artifactId>shiro</artifactId>
<groupId>com.bigsys</groupId>
<artifactId>bigsys-shiro</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.paul</groupId>
<artifactId>redis-util</artifactId>
<groupId>com.bigsys</groupId>
<artifactId>bigsys-redis</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<artifactId>bigsys-spring</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
......
package com.paul.auth;
package com.bigsys.auth;
import com.paul.api.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -15,14 +13,13 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@Autowired
private TestService testService;
@RequestMapping(value = "/test")
@ResponseBody
public String testSay(@RequestParam(value = "name",defaultValue = "") String name){
StringBuffer sb = new StringBuffer();
sb.append("Dubbo: ").append(testService.sayHello(name));
sb.append("Dubbo: ").append("");
return sb.toString();
}
......
......@@ -16,7 +16,7 @@
<!--dubbo:protocol name="dubbo" port="20880" /-->
<!-- 声明需要暴露的服务接口 -->
<dubbo:reference interface="com.paul.api.TestService" id="testService" check="false" />
<dubbo:reference interface="TestService" id="testService" check="false" />
</beans>
\ No newline at end of file
......@@ -9,7 +9,7 @@
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.paul" />
<context:component-scan base-package="com.bigsys" />
<mvc:annotation-driven />
......
......@@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bigsys</artifactId>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
package com.paul;
package com.bigsys;
import junit.framework.Test;
import junit.framework.TestCase;
......
......@@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bigsys</artifactId>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
package com.paul;
import com.paul.api.TestService;
package com.bigsys.redis;
/**
* Hello world!
......
package com.paul.service;
package com.bigsys.redis.service;
import com.paul.api.TestService;
import com.bigsys.redis.api.TestService;
/**
* Created by fangzhipeng on 2017/8/15.
......
......@@ -16,8 +16,8 @@
<dubbo:protocol name="dubbo" port="20880" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.paul.api.TestService" ref="testService" />
<dubbo:service interface="com.bigsys.redis.api.TestService" ref="testService" />
<!-- 具体的实现bean -->
<bean id="testService" class="com.paul.service.TestServiceImpl" />
<bean id="testService" class="com.bigsys.redis.service.TestServiceImpl" />
</beans>
\ No newline at end of file
package com.paul;
package com.bigsys;
import junit.framework.Test;
import junit.framework.TestCase;
......
......@@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bigsys</artifactId>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -49,8 +49,8 @@
</dependency>
<dependency>
<groupId>com.paul</groupId>
<artifactId>spring</artifactId>
<groupId>com.bigsys</groupId>
<artifactId>bigsys-spring</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
......
package com.paul;
package com.bigsys.shiro;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by fangzhipeng on 2017/8/15.
*/
@RequestMapping(value = "/login")
@Controller
public class Login {
@RequestMapping(value = "/login")
public void login() {
@RequestMapping(value = "/test")
@ResponseBody
public String login() {
// Subject subject = SecurityUtils.getSubject();
// subject.login(new AuthenticationToken() {
// public Object getPrincipal() {
......@@ -23,7 +23,7 @@ public class Login {
// return null;
// }
// });
System.out.println("登录成功!");
return "hello shiro";
}
}
package com.bigsys.shiro.model;
/**
* Created by fangzhipeng on 2017/8/15.
*/
public class User {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.bigsys.shiro.realm;
import com.bigsys.shiro.model.User;
import com.bigsys.shiro.service.UserService;
import org.apache.shiro.authc.*;
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 javax.annotation.Resource;
/**
* Created by fangzhipeng on 2017/8/15.
*/
public class UserRealm extends AuthorizingRealm {
@Resource
private UserService userService;
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
String username = (String) principalCollection.fromRealm(getName()).iterator().next();
User user = userService.getByUsername(username);
if (user != null) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addRole("admin");
return info;
} else {
return null;
}
}
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
User user = userService.getByUsername(token.getUsername());
if (user != null) {
return new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), getName());
} else {
return null;
}
}
}
package com.bigsys.shiro.service;
import com.bigsys.shiro.model.User;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* Created by fangzhipeng on 2017/8/15.
*/
@Service("userService")
public class UserService {
public User getByUsername(String username) {
User user = new User();
user.setUsername(username);;
user.setPassword("123456");
return user;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="/login" />
<property name="successUrl" value="/login/loginSuccessFull" />
<property name="unauthorizedUrl" value="/login/unauthorized" />
<property name="filterChainDefinitions">
<value>
/home* = anon
/ = anon
/logout = logout
/role/** = roles[admin]
/permission/** = perms[permssion:look]
/** = authc
</value>
</property>
</bean>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.bigsys.shiro"></context:component-scan>
<mvc:annotation-driven />
<!-- Realm实现 -->
<bean id="userRealm" class="com.bigsys.shiro.realm.UserRealm">
</bean>
<!-- 安全管理器 -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="userRealm" />
</bean>
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login"/>
<property name="successUrl" value="/login/loginSuccessFull"/>
<property name="unauthorizedUrl" value="/login/unauthorized"/>
<property name="filterChainDefinitions">
<value>
/home* = anon
/ = anon
/logout = logout
/role/** = roles[admin]
/permission/** = perms[permssion:look]
/** = authc
</value>
</property>
</bean>
</beans>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录页面</title>
</head>
<body>
<form action="login.html">
<label>用户名:</label><input type="text" name="username">
<label>密码:</label><input type="password" name="password">
<input type="submit" name="提交"/>
</form>
</body>
</html>
\ No newline at end of file
package com.paul;
package com.bigsys;
import junit.framework.Test;
import junit.framework.TestCase;
......
......@@ -2,12 +2,10 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<description>spring 基础依赖</description>
<author>fangzhipeng</author>
<mail>750411463@qq.com</mail>
<parent>
<artifactId>bigsys</artifactId>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bigsys</artifactId>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
package com.paul;
package com.bigsys;
import junit.framework.Test;
import junit.framework.TestCase;
......
......@@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>bigsys</artifactId>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -14,10 +14,15 @@
<dependencies>
<dependency>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<artifactId>bigsys-spring</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.bigsys</groupId>
<artifactId>bigsys-shiro</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>bigsys-webdemo</finalName>
......
package com.paul.bigsys.webdemo;
package com.bigsys.webdemo;
import org.apache.shiro.web.servlet.ShiroFilter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
/**
* Created by fangzhipeng on 2017/8/15.
*/
......@@ -13,6 +16,9 @@ public class TestController {
@RequestMapping(value = "/hello")
@ResponseBody
public String hello() {
System.out.println("hit");
return "hello world";
}
......
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<import resource="spring-mvc.xml" />
<import resource="spring-mvc.xml"/>
<!--<import resource="classpath*:bigsys-shiro.xml"/>-->
</beans>
\ No newline at end of file
......@@ -9,8 +9,10 @@
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.paul" />
<context:component-scan base-package="com.bigsys.webdemo" />
<mvc:annotation-driven />
<mvc:resources mapping="/static/**" location="/,classpath:/static/"/>
</beans>
\ No newline at end of file
......@@ -11,7 +11,10 @@
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
<param-value>
classpath:applicationContext.xml
classpath*:bigsys-*.xml
</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
......@@ -20,6 +23,20 @@
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>encodingFilter</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>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.paul</groupId>
<groupId>com.bigsys</groupId>
<artifactId>bigsys</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment