-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
773cf71
commit 9f6ca71
Showing
5 changed files
with
386 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.oauth.ch03; | ||
|
||
import com.my.util.HttpURLClient; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@WebServlet("/ProtectedServlet-ch03") | ||
public class ProtectedServlet extends HttpServlet { | ||
|
||
|
||
|
||
|
||
|
||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
//省略验证代码 | ||
|
||
String accessToken = request.getParameter("token"); | ||
|
||
//根据当时授权的token对应的权限范围,做相应的处理动作 | ||
//不同权限对应不同的操作 | ||
String[] scope = OauthServlet.tokenScopeMap.get(accessToken); | ||
|
||
StringBuffer sbuf = new StringBuffer(); | ||
for(int i=0;i<scope.length;i++){ | ||
sbuf.append(scope[i]).append("|"); | ||
} | ||
|
||
if(sbuf.toString().indexOf("query")>0){ | ||
queryGoods(""); | ||
} | ||
|
||
if(sbuf.toString().indexOf("add")>0){ | ||
addGoods(""); | ||
} | ||
|
||
if(sbuf.toString().indexOf("del")>0){ | ||
delGoods(""); | ||
} | ||
|
||
//不同的用户对应不同的数据 | ||
String user = OauthServlet.tokenMap.get(accessToken); | ||
queryOrders(user); | ||
} | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
private String queryGoods(String id){ | ||
return ""; | ||
} | ||
|
||
private boolean addGoods(String goods){ | ||
return true; | ||
} | ||
|
||
private boolean delGoods(String id){ | ||
return true; | ||
} | ||
|
||
private String queryOrders(String user){ | ||
return ""; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.