Shiro Pull Request 914
https://stash.corp.netflix.com/projects/CME/repos/shiro/pull-requests/914
Brief summary
This kind of pull request brings support for OAuth2 bearer tokens for you to the Shiro authentication framework. This enables Shiro to always be used with OAuth2-based applications, such as those that make use of Google or Myspace for authentication.
Changes
The right away changes were manufactured to implement this particular feature:
- A innovative
OAuth2Tokencourse was added to represent an OAuth2 bearer token. - The
ShiroFilterclass has been modified to assist OAuth2 bearer symbol authentication. - A new
OAuth2Realmclass was added to supply the necessary authentication logic. - A new
OAuth2Filterclass has been added to offer a simple approach to filter demands that require OAuth2 bearer token authentication.
Benefits
This feature gives the following rewards:
- Allows Shiro to be used with OAuth2-based applications.
- Simplifies the process of authenticating users in OAuth2-based applications.
- Provides an even more secure way in order to authenticate users inside of OAuth2-based applications.
Consumption
To be able to use this have, you must first of all add the following dependency to your current project:
< dependency> < groupId> org. apache. shiro< /groupId> < artifactId> shiro-oauth2< /artifactId> < version> 2. 0. 0-SNAPSHOT< /version> < /dependency> Once you have got added the addiction, you can next configure Shiro for you to use OAuth2 bearer token authentication. Typically the following is a great example of exactly how to do this particular:
// Create a new ShiroFilter example. ShiroFilter filter = new ShiroFilter(); // Set the get access URL. filter. setLoginUrl("/login"); // Set this success URL. filter. setSuccessUrl("/home"); // Set the unauthorized WEB LINK. filter. setUnauthorizedUrl("/unauthorized"); // Create a new OAuth2Realm instance. OAuth2Realm realm = brand new OAuth2Realm(); // Established the realm in the ShiroFilter instance. filter. setRealm(realm); // Add the OAuth2Filter to the ShiroFilter instance. filter. addFilter("oauth2", new OAuth2Filter()); // Set the ShiroFilter instance on this ServletContext. ServletContext servletContext = getServletContext(); servletContext. setAttribute(ShiroFilter. FILTER_NAME, filter); Once you possess configured Shiro to use OAuth2 bearer token authentication, an individual can then make use of the OAuth2Token class to symbolize OAuth2 bearer bridal party. The following will be an example associated with how to carry out this:
// Produce a new OAuth2Token instance. OAuth2Token symbol = new OAuth2Token("accessToken"); // Set the particular token on the particular SecurityContext. SecurityContext securityContext = SecurityUtils. getSubject(). getSession(); securityContext. setAuthentication(new OAuth2Authentication(token)); Conclusion
This have adds support with regard to OAuth2 bearer bridal party to the Shiro authentication framework. This allows Shiro to be able to be used along with OAuth2-based applications, these kinds of as those that use Google or perhaps Facebook for authentication.