一个典型的web应用验证过程:
-
你访问首页,点击一个链接。
-
向服务器发送一个请求,服务器判断你是否在访问一个受保护的资源。
-
如果你还没有进行过认证,服务器发回一个响应,提示你必须进行认证。 响应可能是HTTP响应代码,或者是重新定向到一个特定的web页面。
-
依据验证机制,你的浏览器将重定向到特定的web页面,这样你可以添加表单, 或者浏览器使用其他方式校验你的身份(比如,一个基本校验对话框,cookie,或者X509证书,或者其他)。
-
浏览器会发回一个响应给服务器。 这将是HTTP POST包含你填写的表单内容,或者是HTTP头部,包含你的验证信息。
-
下一步,服务器会判断当前的证书是否是有效的, 如果他们是有效的,下一步会执行。 如果他们是非法的,通常你的浏览器会再尝试一次(所以你返回的步骤二)。
-
你发送的原始请求,会导致重新尝试验证过程。 有希望的是,你会通过验证,得到猪狗的授权,访问被保护的资源。 如果你有足够的权限,请求会成功。否则,你会收到一个HTTP错误代码403,意思是访问被拒绝。
常用类
• SecurityContextHolder,to provide access to the SecurityContext.提供访问SecurityContext的途径
• SecurityContext, to hold the Authentication and possibly request-specific security information.• Authentication, to represent the principal in a Spring Security-specific manner.
• GrantedAuthority, to reflect the application-wide permissions granted to a principal.
• UserDetails, to provide the necessary information to build an Authentication object from your application's DAOs or other source source of security data.
• UserDetailsService, to create a UserDetails when passed in a String-based username (or certificate ID or the like).