Shiro Pull Request 914
https://stash.corp.netflix.com/projects/CME/repos/shiro/pull-requests/914
Summary
This particular pull request gives support for OAuth2 bearer tokens to the Shiro authentication framework. This enables Shiro to always be used with OAuth2-based applications, such since those that work with Google or Myspace for authentication.
Changes
The following changes were built to implement this particular feature:
- A innovative
OAuth2Tokenschool was added to be able to represent an OAuth2 bearer token. - The
ShiroFilterclass has been modified to help OAuth2 bearer expression authentication. - A new
OAuth2Realmclass has been added to supply the necessary authentication logic. - A new
OAuth2Filterclass has been added to offer a simple method to filter needs that require OAuth2 bearer token authentication.
Benefits
This feature offers the following advantages:
- Allows Shiro to be able to be used together with OAuth2-based applications.
- Simplifies typically the process of authenticating users in OAuth2-based applications.
- Provides a a lot more secure way to authenticate users inside OAuth2-based applications.
Utilization
To be able to use this have, you must primary add the next dependency to your project:
< dependency> < groupId> org. apache. shiro< /groupId> < artifactId> shiro-oauth2< /artifactId> < version> 2. 0. 0-SNAPSHOT< /version> < /dependency> Once you experience added the habbit, you can after that configure Shiro to use OAuth2 bearer token authentication. The following is an example of just how to do this particular:
// Create a new ShiroFilter example. ShiroFilter filter = new ShiroFilter(); // Set the sign in URL. filter. setLoginUrl("/login"); // Set typically the success URL. filtration system. setSuccessUrl("/home"); // Arranged the unauthorized LINK. filter. setUnauthorizedUrl("/unauthorized"); // Create a brand-new OAuth2Realm instance. OAuth2Realm realm = new OAuth2Realm(); // Set the realm on the ShiroFilter example. 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 have configured Shiro in order to use OAuth2 bearer token authentication, you can then make use of the OAuth2Token class to symbolize OAuth2 bearer bridal party. The following is usually an example of how to can this:
// Create a new OAuth2Token instance. OAuth2Token expression = new OAuth2Token("accessToken"); // Set typically the token on the particular SecurityContext. SecurityContext securityContext = SecurityUtils. getSubject(). getSession(); securityContext. setAuthentication(new OAuth2Authentication(token)); Conclusion
This function adds support intended for OAuth2 bearer bridal party to the Shiro authentication framework. This specific allows Shiro to be able to be used with OAuth2-based applications, such as those that use Google or perhaps Facebook for authentication.