GithubHelp home page GithubHelp logo

matrixcrawler / grails-spring-security-oauth2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from enr/s2oauth

8.0 5.0 10.0 445 KB

Spring security Oauth Grails 3 plugin

License: Apache License 2.0

Groovy 98.37% Java 1.63%

grails-spring-security-oauth2's Introduction

Spring Security OAuth2 Plugin

Build Status Download

Main differences with the Grails 2 plugin:

Installation

Add the following dependencies in build.gradle

dependencies {
...
    compile 'org.grails.plugins:spring-security:3.+'
    compile 'org.grails.plugins:spring-security-oauth2:1.1.0'
...
}

You will also need at least one provider extension, i.e the grails-spring-security-oauth2-google plugin Change the version to reflect the actual version you would like to use.

You can configure the following parameters in your application.yml. This is fully optional

grails:
    plugin:
        springsecurity:
            oauth2:
                active: true    #whether the whole plugin is active or not
                registration:
                    askToLinkOrCreateAccountUri: '/oauth2/ask' # The URI that is called to aks the user to either create a new account or link to an existing account
                    roleNames: ['ROLE_USER'] #A list of role names that should be automatically granted to an OAuth User. The roles will be created if they do not exist

Once you have an User domain class, initialize this plugin by using the init script grails init-oauth2 <domain-class-package> <user-class-name> <oauthid-class-name> In example: grails init-oauth2 com.yourapp User OAuthID That will create the domain class com.yourapp.oAuthID

Finally add:

static hasMany = [oAuthIDs: OAuthID]

to your user domain class.

Extensions

List of known extension

How to create a new provider plugin

  1. Create a new plugin with grails create-plugin spring-security-oauth2-myProvider
  2. Add the following plugins as dependency in build.gradle:
    • provided 'org.grails.plugins:spring-security-core:3.+'
    • provided 'org.grails.plugins:spring-security-oauth2:1.1.+'
  3. Create a service in your plugin that extends OAuth2AbstractProviderService and implement the abstract methods. You can override the other methods for fine-tuning if needed.

License

Apache 2

grails-spring-security-oauth2's People

Contributors

aitmanas avatar matrixcrawler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

grails-spring-security-oauth2's Issues

Failed to initialize class [grails.plugin.springsecurity.oauth2.SpringSecurityOAuth2Controller] from plugin [springSecurityOauth2] : grails/plugin/springsecurity/ControllerMixin

Seen a similar issue here:

This is | grails 3.1.10 | Gradle 2.10, following dependencies:

compile 'org.grails.plugins:spring-security-oauth2:1.1.0'
    compile 'org.grails.plugins:spring-security-oauth2-google:1.1.0'
    //Custom for datingsite plugins
    compile 'org.springframework:spring-test:2.5'
    compile 'org.springframework.social:spring-social-facebook:2.0.3.RELEASE'
    compile 'org.springframework.security:spring-security-core:4.0.3.RELEASE'
    compile 'org.springframework.security:spring-security-web:4.0.3.RELEASE'
    compile 'org.grails.plugins:spring-security-core:3.0.3'
    compile 'org.grails.plugins:spring-security-facebook:0.18'

Line 77 is

    static void main(String[] args) {
        GrailsApp.run(Application, args)
    }

Also grails/plugin/springsecurity/ControllerMixin thought things changed from grails/plugin to grails/plugins

Unsure do I need to upgrade/downgrade ?

Actual error:

ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplicationPostProcessor' defined in xxxx.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is grails.plugins.exceptions.PluginException: Failed to initialize class [grails.plugin.springsecurity.oauth2.SpringSecurityOAuth2Controller] from plugin [springSecurityOauth2] : grails/plugin/springsecurity/ControllerMixin
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:120)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
	at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:55)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:365)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:354)
	at grails.boot.GrailsApp$run.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
	at xxxxx.Application.main(Application.groovy:77)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is grails.plugins.exceptions.PluginException: Failed to initialize class [grails.plugin.springsecurity.oauth2.SpringSecurityOAuth2Controller] from plugin [springSecurityOauth2] : grails/plugin/springsecurity/ControllerMixin
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 23 common frames omitted
Caused by: grails.plugins.exceptions.PluginException: Failed to initialize class [grails.plugin.springsecurity.oauth2.SpringSecurityOAuth2Controller] from plugin [springSecurityOauth2] : grails/plugin/springsecurity/ControllerMixin
	at org.grails.plugins.BinaryGrailsPlugin.initializeProvidedArtefacts(BinaryGrailsPlugin.java:154)
	at org.grails.plugins.BinaryGrailsPlugin.<init>(BinaryGrailsPlugin.java:88)
	at grails.plugins.DefaultGrailsPluginManager.createBinaryGrailsPlugin(DefaultGrailsPluginManager.java:391)
	at grails.plugins.DefaultGrailsPluginManager.findCorePlugins(DefaultGrailsPluginManager.java:378)
	at grails.plugins.DefaultGrailsPluginManager.attemptLoadPlugins(DefaultGrailsPluginManager.java:330)
	at grails.plugins.DefaultGrailsPluginManager.loadPlugins(DefaultGrailsPluginManager.java:240)
	at grails.boot.config.GrailsApplicationPostProcessor.initializeGrailsApplication(GrailsApplicationPostProcessor.groovy:87)
	at grails.boot.config.GrailsApplicationPostProcessor.setApplicationContext(GrailsApplicationPostProcessor.groovy:211)
	at grails.boot.config.GrailsApplicationPostProcessor.<init>(GrailsApplicationPostProcessor.groovy:76)
	at grails.boot.config.GrailsAutoConfiguration.grailsApplicationPostProcessor(GrailsAutoConfiguration.groovy:62)
	at myprofessions.Application.grailsApplicationPostProcessor(Application.groovy)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 24 common frames omitted
Caused by: java.lang.NoClassDefFoundError: grails/plugin/springsecurity/ControllerMixin
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775)
	at org.grails.plugins.BinaryGrailsPlugin.initializeProvidedArtefacts(BinaryGrailsPlugin.java:152)
	... 40 common frames omitted
Caused by: java.lang.ClassNotFoundException: grails.plugin.springsecurity.ControllerMixin
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 56 common frames omitted

Heroku support

When I deploy my application in Heroku, the callback returns with the following URL: http: // localhost: 8080 / ....

SpringSecurityOauth2BaseService not initialized

When I want to use the GSP method "oauth2:ifLoggedInWith" with Facebook, the SpringSecurityOauth2BaseService oAuth2BaseService is not initialized, so the GSP crashes with the error:
2017-03-28 10:04:32.328 ERROR --- [nio-8080-exec-1] .a.c.c.C.[.[.[.[grailsDispatcherServlet] : Servlet.service() for servlet [grailsDispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: [views/home/index.gsp:64] Error executing tag <oauth2:ifLoggedInWith>: Cannot invoke method sessionKeyForAccessToken() on null object] with root cause

OAuth2Exception when connecting accts with hidden email addresses

Many Github accts choose to hide their email address in settings (this is different than simply marking the email private, which can still be requested by the connecting app). When these users connect an app using this plugin, an exception will be thrown from GithubOAuth2Service.createSpringAuthToken. Since the username is still available though, it a better approach might be to add username to the GithubOauth2SpringToken. and proceed with token creation, since User creation can may be able to use that as the unique username instead.

Could not resolve property: username of: User

The username field is transient in my User class. I need only the user's email for the auth. So, I get an error because this field is not present in the database. How change this?

No checks for required configurations

I was getting a bizarre error only to realize I had not included all required configurations. I think there should be a meaningful check at startup to flag for missing configurations. In my case it was oauth2.domainClass, which there is no documentation for at all - at least that I could find.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.