Skip to content

Commit

Permalink
Merge pull request #23 from agorapulse/bug/fix-micronaut-security-ena…
Browse files Browse the repository at this point in the history
…bled-false

skip using MicronautSecurityUserArgumentBinder when micronaut.security.enabled is set to false
  • Loading branch information
wololock authored Mar 21, 2022
2 parents 879da50 + 7f2cd2f commit 61576ae
Show file tree
Hide file tree
Showing 80 changed files with 189 additions and 121 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/micronaut-compatibility.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/guide.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/src/docs/asciidoc/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ You can specify from which address the users can access the console
.Address Filter Configuration
----
console:
include::{root-dir}/examples/micronaut-console-example-application/src/main/resources/application.yml[tags=address]
include::{root-dir}/examples/micronaut-console-example-application/src/main/resources/application-secured.yml[tags=address]
----

WARNING: The addresses must start with a forward slash `/`.
Expand All @@ -171,7 +171,7 @@ You can specify which users can access the console
.User FilterConfiguration
----
console:
include::{root-dir}/examples/micronaut-console-example-application/src/main/resources/application.yml[tags=users]
include::{root-dir}/examples/micronaut-console-example-application/src/main/resources/application-secured.yml[tags=users]
----

You must use Micronaut Security Integration or define your own implementation of `TypedRequestArgumentBinder<User>` to
Expand All @@ -190,7 +190,7 @@ Micronaut Console integrates well with the Micronaut Security library.
[source]
.Micronaut Security Configuration
----
include::{root-dir}/examples/micronaut-console-example-application/src/main/resources/application.yml[tags=micronaut-security]
include::{root-dir}/examples/micronaut-console-example-application/src/main/resources/application-secured.yml[tags=micronaut-security]
----
<1> Enable Micronaut Security
<2> Enable login endpoint
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2020-2021 Agorapulse.
# Copyright 2020-2022 Agorapulse.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# tag::micronaut-security[]
micronaut:
security:
enabled: true # <1>
endpoints:
login:
enabled: true # <2>
token:
jwt:
enabled: true # <3>
signatures:
secret:
generator:
secret: pleaseChangeThisSecretForANewOne # <4>
intercept-url-map:
- pattern: /console/** # <5>
http-method: GET
access:
- isAnonymous()
- pattern: /console/** # <6>
http-method: POST
access:
- isAuthenticated()
# end::micronaut-security[]
console:
# tag::users[]
users:
- sherlock
# end::users[]
# tag::address[]
addresses:
- /127.0.0.1
- /0:0:0:0:0:0:0:1
# end::address[]
until: 2030-11-12T10:28:00Z
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
micronaut:
application:
name: micronaut-console-example
---
# tag::micronaut-security[]
micronaut:
security:
enabled: true # <1>
endpoints:
login:
enabled: true # <2>
token:
jwt:
enabled: true # <3>
signatures:
secret:
generator:
secret: pleaseChangeThisSecretForANewOne # <4>
intercept-url-map:
- pattern: /console/** # <5>
http-method: GET
access:
- isAnonymous()
- pattern: /console/** # <6>
http-method: POST
access:
- isAuthenticated()
# end::micronaut-security[]
enabled: false

console:
# tag::users[]
users:
- sherlock
# end::users[]
# tag::address[]
addresses:
- /127.0.0.1
- /0:0:0:0:0:0:0:1
# end::address[]
until: 2030-11-12T10:28:00Z
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SPDX-License-Identifier: Apache-2.0
Copyright 2020-2021 Agorapulse.
Copyright 2020-2022 Agorapulse.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 Agorapulse.
*
* 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
*
* https://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 micronaut.console.example

import com.agorapulse.gru.Gru
import com.agorapulse.gru.http.Http
import io.micronaut.context.ApplicationContext
import io.micronaut.runtime.server.EmbeddedServer
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification

class MicronautSecurityDisabledIntegrationSpec extends Specification {

@Shared @AutoCleanup ApplicationContext context
@Shared @AutoCleanup EmbeddedServer server

@AutoCleanup Gru gru = Gru.create(Http.create(this))

void setupSpec() {
context = ApplicationContext.builder().build()

context.start()

server = context.getBean(EmbeddedServer)
server.start()
}

void setup() {
gru.prepare(server.URL.toString())
}

void 'can access the console when micronaut.security.enabled is set to false'() {
expect:
gru.test {
post '/console/execute/result', {
content inline('"Hello World"'), 'text/groovy'
}
expect {
text inline('Hello World')
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@ class MicronautSecurityIntegrationSpec extends Specification {
@AutoCleanup Gru gru = Gru.create(Http.create(this))

void setupSpec() {
context = ApplicationContext.builder().build()
context = ApplicationContext.builder('secured').build()

context.start()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2020-2021 Agorapulse.
# Copyright 2020-2022 Agorapulse.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,7 @@ import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import jp.classmethod.aws.gradle.lambda.AWSLambdaInvokeTask
import jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask

// end::import[]

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SPDX-License-Identifier: Apache-2.0
Copyright 2020-2021 Agorapulse.
Copyright 2020-2022 Agorapulse.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SPDX-License-Identifier: Apache-2.0
Copyright 2020-2021 Agorapulse.
Copyright 2020-2022 Agorapulse.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2020-2021 Agorapulse.
# Copyright 2020-2022 Agorapulse.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions libs/micronaut-console/micronaut-console.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

dependencies {
annotationProcessor platform("io.micronaut:micronaut-bom:$micronautVersion")
implementation platform("io.micronaut:micronaut-bom:$micronautVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 Agorapulse.
* Copyright 2020-2022 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 61576ae

Please sign in to comment.