Perform authentication on your behalf-proxy mode and Authentication Proxy Mode

Source: Internet
Author: User

Perform authentication on your behalf-proxy mode and Authentication Proxy Mode

By taking advantage of the cooperation of the data room charging system, I took out the big talk Design Model Book. I was in charge of logging on to layer B, and I was always thinking about the design mode that I could add. During the first data center reconstruction, I watched C # code write VB. NET has finished the three layers in a week. Now, I have found an example of proxy mode on the Internet, which is really easy to understand .. After learning these things, we can look at the design pattern again, which is different ~

 

Let's first review what is the proxy mode? Do you still remember the story of Dai Li's crush? You can think back to the big story in design.

 

 

Definition of proxy mode:

 

ProvidesProxyTo control access to this object. In some cases, an object is not suitable or cannot directly reference another object, and the proxy object can be used between the client and the target object.Role of intermediary.

 

Proxy UML diagram:

 

 

 

Proxy benefits:

 

1. Separate the processing of business logic and transactions.

2. Add an intermediate layer to protect the target object.

3. Strong scalability and reduced coupling.

 

 

 

Disadvantages of proxy:

 

Because proxy objects are added between the client and the real theme, some types of proxy modes may cause slow request processing. Implementing the proxy mode requires additional work, and the implementation of some proxy modes is very complicated.

 

 

When do I need to use the proxy mode:

 

1. The client cannot operate on the target object. A remote object proxy is created on the client, so that the client can operate on the remote object, just like the target object. Because both of them implement the same interface.

2. In addition to the current features, we need to provide other features.

 

Graphical proxy mode (how to use IDC login ):

 

A logon transaction is required to perform a series of authentication. In fact, logon involves three parts: Enter the user name and password (whether the U-layer authentication is empty) → authenticate → log on successfully and close the connection. At this time, there are several methods to verify the identity. We can write a transaction into the implementation class, write a proxy interface, proxy class, and directly call our proxy class at the U layer. A line of code is enough. In this way, the U layer does not need to see how B is implemented, because it is directly oriented to the proxy class, it does not need to know how B is implemented.

 

 

Practice proxy mode (LOGIN ):

We need three classes: the proxy interface ILoginProxy and the proxy class LoginProxy to implement the logon layer B Worklogbll.


<span style="font-size:18px;"><span style="font-size:18px;">Imports EntityPublic Interface ILoginProxy    Function TestUser(enUser As UserEntity) As List(Of UserEntity)End Interface</span></span>


 

<span style="font-size:18px;"><span style="font-size:18px;">Imports EntityPublic Class LoginProxy : Implements ILoginProxy    Dim worklogbll As New WorklogBLL    Public Function TestUser(ByVal enUser As UserEntity) As List(Of UserEntity) Implements ILoginProxy.TestUser        Return worklogbll.TestUser(enUser)    End FunctionEnd Class</span></span>


<Span style = "font-size: 18px;"> <span style = "font-size: 18px; "> '************************************* * ******** 'file Name: worklogBLL 'namespace: bll' internal volume: 'function: 'file relation:' OPERATOR: Zhou zhou' small group: xx' generation Date: 11:28:16 'version No: v1.0.0.0 'modify log: 'copyright description: '*************************************** * ***** Imports EntityImports FactoryPublic Class WorklogBLL: implements ILoginProxy Public facWork As New Factory. dataFactory 'instantiate the Factory Public facUser As New Factory. dataFactory 'instantiate the factory Public iWork As IDAL. IWorklog = facWork. createworklog' defines the interface Public iUser As IDAL. IUser = facUser. createuser' defines the interface ''' <summary> ''' to verify whether the user has successfully logged on ''' </summary> ''' <param name = "enUser"> upload ID user entity </param> ''' <returns> </returns> ''' <remarks> </remarks> Public Function TestUser (enUser As UserEntity) as List (Of UserEntity) Implements ILoginProxy. testUser If iUser. selectuserbyidpwd (enUser ). count> 0 Then If iWork. userisonwork (enUser ). count> 0 then': The operation record is greater than 0. It indicates that the instance is on the machine. The instance goes down first, and Then the instance is on the machine. userlevel = iUser. selectuserbyidpwd (enUser) (0 ). userlevel iWork. userupdatelogin (enUser) iWork. userinsertlogin (enUser) Else 'inserts a new work record, enUser. userlevel = iUser. selectuserbyidpwd (enUser) (0 ). userlevel iWork. userinsertlogin (enUser) End If Return iUser. selectuserbyidpwd (enUser) End Function </span>

<Span style = "font-size: 18px;"> Private Sub button#click (sender As Object, e As EventArgs) handles Button1.Click Dim enUser As New UserEntity Dim Userinfo As New List (Of UserEntity) enUser. userID = "4" enUser. pwd = "2" Dim iLoginProxy As ILoginProxy iLoginProxy = New LoginProxy Userinfo = iLoginProxy. testUser (enUser) MsgBox (Userinfo (0 ). userlevel) If Userinfo. count> 0 Then FrmHomepage. show () Me. hide () If Userinfo (0 ). userlevel. trim () = "general user" Then FrmHomepage. toolStripMenuItem. enabled = True FrmHomepage. operator ToolStripMenuItem. enabled = False FrmHomepage. administrator ToolStripMenuItem. enabled = False ElseIf Userinfo (0 ). userlevel. trim () = "operator" Then FrmHomepage. toolStripMenuItem. enabled = True FrmHomepage. operator ToolStripMenuItem. enabled = True FrmHomepage. administrator ToolStripMenuItem. enabled = False ElseIf Userinfo (0 ). userlevel. trim () = "Administrator" Then FrmHomepage. toolStripMenuItem. enabled = True FrmHomepage. operator ToolStripMenuItem. enabled = True FrmHomepage. administrator ToolStripMenuItem. enabled = True End If End Sub </span>


The U layer completes the login transaction processing in one sentence, isn't it easy ~
Userinfo = iLoginProxy.TestUser(enUser)

 

Summary:


By using the design model, you can achieve what you do not dare to think about ~ Then, if we do it boldly, we always deny our own ideas. We always feel that any design model is inappropriate. Is it too far-fetched! In fact, the cooperative version of the machine room is an opportunity for hands-on training. It's right to think about it! As long as you stand firm, I use the design pattern of XX to solve which problem, and it will be successful!

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.