-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-write plugin scripts as ApplicationCommand (#920)
* Rewrite s2-quickstart as the ApplicationCommand * Rewrite s2-quickstart as the ApplicationCommand * Update S2QuickstartCommand.groovy * Rewrite s2-create-persistent-token as ApplicationCommand * Re-write s2-create-role-hierarchy-entry as ApplicationCommand * Update Gradle Enterprise publishAlwaysIf condition
- Loading branch information
1 parent
68e3a01
commit 2d6d5b6
Showing
8 changed files
with
494 additions
and
372 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
plugin/grails-app/commands/grails.plugin.springsecurity/CommandLineHelper.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package grails.plugin.springsecurity | ||
|
||
import grails.dev.commands.ExecutionContext | ||
import io.micronaut.core.naming.NameUtils | ||
import org.grails.build.parsing.CommandLine | ||
|
||
trait CommandLineHelper { | ||
|
||
static final boolean SUCCESS = true | ||
static final boolean FAILURE = false | ||
|
||
abstract ExecutionContext getExecutionContext() | ||
|
||
boolean isFlagPresent(String name) { | ||
final CommandLine commandLine = executionContext.commandLine | ||
if (commandLine.hasOption(name)) { | ||
return commandLine.optionValue(name) ? true : false | ||
} else { | ||
def value = commandLine?.undeclaredOptions?.get(name) | ||
return value ? true : false | ||
} | ||
} | ||
|
||
String flagValue(String name) { | ||
final CommandLine commandLine = executionContext.commandLine | ||
if (commandLine.hasOption(name)) { | ||
return commandLine.optionValue(name) | ||
} else { | ||
def value = commandLine?.undeclaredOptions?.get(name) | ||
return value | ||
} | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...in/grails-app/commands/grails.plugin.springsecurity/S2CreatePersistentTokenCommand.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2023 Puneet Behl. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package grails.plugin.springsecurity | ||
|
||
import grails.build.logging.ConsoleLogger | ||
import grails.build.logging.GrailsConsole | ||
import grails.codegen.model.Model | ||
import grails.dev.commands.GrailsApplicationCommand | ||
import groovy.transform.CompileStatic | ||
|
||
/** | ||
* Creates a persistent token domain class for the Spring Security Core plugin. | ||
* Usage: <code>./gradlew runCommand "-Pargs=s2-create-persistent-token [DOMAIN CLASS NAME]"</code> | ||
* | ||
* For example: <code>./gradlew runCommand "-Pargs=s2-create-persistent-token com.yourapp.PersistentLogin"</code> | ||
* | ||
* @author Puneet Behl | ||
* @since 6.0.0 | ||
*/ | ||
@CompileStatic | ||
class S2CreatePersistentTokenCommand implements GrailsApplicationCommand, CommandLineHelper, SkipBootstrap { | ||
|
||
@Delegate | ||
ConsoleLogger consoleLogger = GrailsConsole.getInstance() | ||
|
||
private final static USAGE_MESSAGE = ''' | ||
./gradlew runCommand "-Pargs=s2-create-persistent-token [DOMAIN CLASS NAME]" | ||
For example: ./gradlew runCommand "-Pargs=s2-create-persistent-token com.yourapp.PersistentLogin" | ||
''' | ||
|
||
@Override | ||
boolean handle() { | ||
|
||
if (args.size() == 0) { | ||
consoleLogger.error("Usage: " + USAGE_MESSAGE) | ||
return FAILURE | ||
} | ||
|
||
final String domainClass = args[0] | ||
final Model domainModel = model(domainClass) | ||
consoleLogger.addStatus ("\nCreating persistent token class $domainClass") | ||
render(template: template("PersistentLogin.groovy.template"), | ||
destination: file("grails-app/domain/$domainModel.packagePath/${domainModel.simpleName}.groovy"), | ||
model: domainModel, | ||
overrite: false | ||
) | ||
file('grails-app/conf/application.groovy').withWriterAppend { BufferedWriter writer -> | ||
writer.newLine() | ||
writer.writeLine 'grails.plugin.springsecurity.rememberMe.persistent = true' | ||
writer.writeLine "grails.plugin.springsecurity.rememberMe.persistentToken.domainClassName = '$domainClass'" | ||
writer.newLine() | ||
} | ||
return SUCCESS | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...grails-app/commands/grails.plugin.springsecurity/S2CreateRoleHierarchyEntryCommand.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2023 Puneet Behl. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package grails.plugin.springsecurity | ||
|
||
import grails.build.logging.ConsoleLogger | ||
import grails.build.logging.GrailsConsole | ||
import grails.codegen.model.Model | ||
import grails.dev.commands.GrailsApplicationCommand | ||
import groovy.transform.CompileStatic | ||
|
||
/** | ||
* Creates a domain class for a persistent role hierarchy for the Spring Security Core plugin | ||
* Usage: <code>./gradlew runCommand "-Pargs=s2-create-role-hierarchy-entry [DOMAIN CLASS NAME]" | ||
* For example: <code>./gradlew runCommand "-Pargs=s2-create-role-hierarchy-entry com.yourapp.RoleHierarchyEntry"</code> | ||
* | ||
* @author Puneet Behl | ||
* @since 6.0.0 | ||
*/ | ||
@CompileStatic | ||
class S2CreateRoleHierarchyEntryCommand implements GrailsApplicationCommand, CommandLineHelper, SkipBootstrap { | ||
|
||
private static final String USAGE_MESSAGE = ''' | ||
./gradlew runCommand "-Pargs=s2-create-role-hierarchy-entry [DOMAIN CLASS NAME]" | ||
For example: ./gradlew runCommand "-Pargs=s2-create-role-hierarchy-entry com.yourapp.RoleHierarchyEntry" | ||
''' | ||
|
||
@Delegate | ||
ConsoleLogger consoleLogger = GrailsConsole.getInstance() | ||
|
||
@Override | ||
boolean handle() { | ||
|
||
if (args.size() == 0) { | ||
consoleLogger.error("Usage: " + USAGE_MESSAGE) | ||
return FAILURE | ||
} | ||
|
||
final String domainClass = args[0] | ||
final Model domainModel = model(domainClass) | ||
|
||
consoleLogger.addStatus("\nCreating role hierarchy entry class $domainClass") | ||
render(template: template('RoleHierarchyEntry.groovy.template'), | ||
destination: file("grails-app/domain/$domainModel.packagePath/${domainModel.simpleName}.groovy"), | ||
model: domainModel, overwrite: false) | ||
|
||
file('grails-app/conf/application.groovy').withWriterAppend { BufferedWriter writer -> | ||
writer.newLine() | ||
writer.writeLine "grails.plugin.springsecurity.roleHierarchyEntryClassName = '$domainClass'" | ||
writer.newLine() | ||
} | ||
|
||
return SUCCESS | ||
} | ||
} |
Oops, something went wrong.
2d6d5b6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@puneetbehl -- the grails 6 gradle.properties file does not contain a gorm version.
Line 193 of the s2-quickstart command is looking for the gorm version to determine which version of User to use. (injectable service or not).
I don't know the appropriate way to determine gorm version now. Either the default gradle.properties needs to be fixed, or some other mechanism needs to figured out.
when I build an app and use s2-quickstart, I get the old version of User.groovy with the injected spring security service instead of the one with the Interceptor.