-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: jakarta PermitAll DenyAll RolesAllowed annotations (#775)
- Loading branch information
Showing
11 changed files
with
235 additions
and
19 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
...ations/src/main/java/io/micronaut/security/annotation/JakartaDenyAllAnnotationMapper.java
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,31 @@ | ||
/* | ||
* Copyright 2017-2020 original authors | ||
* | ||
* 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 io.micronaut.security.annotation; | ||
|
||
import io.micronaut.core.annotation.Internal; | ||
|
||
/** | ||
* Allows using the {@link jakarta.annotation.security.DenyAll} annotation in Micronaut. | ||
* | ||
* @author Fredrik Hov | ||
*/ | ||
@Internal | ||
public class JakartaDenyAllAnnotationMapper extends DenyAllAnnotationMapper { | ||
@Override | ||
public String getName() { | ||
return "jakarta.annotation.security.DenyAll"; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ions/src/main/java/io/micronaut/security/annotation/JakartaPermitAllAnnotationMapper.java
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,31 @@ | ||
/* | ||
* Copyright 2017-2020 original authors | ||
* | ||
* 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 io.micronaut.security.annotation; | ||
|
||
import io.micronaut.core.annotation.Internal; | ||
|
||
/** | ||
* Allows using the {@link jakarta.annotation.security.PermitAll} annotation in Micronaut. | ||
* | ||
* @author Fredrik Hov | ||
*/ | ||
@Internal | ||
public class JakartaPermitAllAnnotationMapper extends PermitAllAnnotationMapper { | ||
@Override | ||
public String getName() { | ||
return "jakarta.annotation.security.PermitAll"; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...s/src/main/java/io/micronaut/security/annotation/JakartaRolesAllowedAnnotationMapper.java
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,31 @@ | ||
/* | ||
* Copyright 2017-2020 original authors | ||
* | ||
* 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 io.micronaut.security.annotation; | ||
|
||
import io.micronaut.core.annotation.Internal; | ||
|
||
/** | ||
* Allows using the {@link jakarta.annotation.security.RolesAllowed} annotation in Micronaut. | ||
* | ||
* @author Fredrik Hov | ||
*/ | ||
@Internal | ||
public class JakartaRolesAllowedAnnotationMapper extends RolesAllowedAnnotationMapper { | ||
@Override | ||
public String getName() { | ||
return "jakarta.annotation.security.RolesAllowed"; | ||
} | ||
} |
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
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
5 changes: 4 additions & 1 deletion
5
...ions/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationMapper
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
io.micronaut.security.annotation.PermitAllAnnotationMapper | ||
io.micronaut.security.annotation.JakartaPermitAllAnnotationMapper | ||
io.micronaut.security.annotation.RolesAllowedAnnotationMapper | ||
io.micronaut.security.annotation.DenyAllAnnotationMapper | ||
io.micronaut.security.annotation.JakartaRolesAllowedAnnotationMapper | ||
io.micronaut.security.annotation.DenyAllAnnotationMapper | ||
io.micronaut.security.annotation.JakartaDenyAllAnnotationMapper |
39 changes: 39 additions & 0 deletions
39
security/src/test/groovy/io/micronaut/security/denyall/JakartaDenyAllSpec.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,39 @@ | ||
package io.micronaut.security.denyall | ||
|
||
import io.micronaut.context.annotation.Replaces | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.context.env.Environment | ||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.security.annotation.Secured | ||
import io.micronaut.security.rules.SecurityRule | ||
|
||
import jakarta.annotation.security.DenyAll | ||
|
||
class JakartaDenyAllSpec extends DenyAllSpec { | ||
|
||
@Requires(env = Environment.TEST) | ||
@Requires(property = 'spec.name', value = "DenyAllSpec") | ||
@Replaces(DenyAllSpec.BookController.class) | ||
@Controller(DenyAllSpec.controllerPath) | ||
@Secured(SecurityRule.IS_ANONYMOUS) | ||
static class BookController { | ||
|
||
@DenyAll | ||
@Get("/denied") | ||
String denied() { | ||
"You will not see this" | ||
} | ||
|
||
@Get("/index") | ||
String index() { | ||
"You will not see this" | ||
} | ||
|
||
@Secured(SecurityRule.DENY_ALL) | ||
@Get("/secureddenied") | ||
String securedDenyAll() { | ||
"You will not see this" | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
security/src/test/groovy/io/micronaut/security/permitall/JakartaPermitAllSpec.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,38 @@ | ||
package io.micronaut.security.permitall | ||
|
||
import io.micronaut.context.annotation.Replaces | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.context.env.Environment | ||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
|
||
import jakarta.annotation.security.PermitAll | ||
|
||
class JakartaPermitAllSpec extends PermitAllSpec { | ||
|
||
@Requires(env = Environment.TEST) | ||
@Requires(property = 'spec.name', value = 'PermitAllSpec') | ||
@Replaces(PermitAllSpec.BookController.class) | ||
@Controller(PermitAllSpec.controllerPath) | ||
static class BookController { | ||
|
||
@PermitAll | ||
@Get("/books") | ||
Map<String, Object> list() { | ||
[books: ['Building Microservice', 'Release it']] | ||
} | ||
} | ||
|
||
@Requires(env = Environment.TEST) | ||
@Requires(property = 'spec.name', value = 'PermitAllSpec') | ||
@Replaces(PermitAllSpec.LanguagesController.class) | ||
@Controller(PermitAllSpec.controllerPath) | ||
@PermitAll | ||
static class LanguagesController { | ||
|
||
@Get("/languages") | ||
Map<String, Object> list() { | ||
[languages: ['Groovy', 'Java']] | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
security/src/test/groovy/io/micronaut/security/rolesallowed/JakartaRolesAllowedSpec.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,39 @@ | ||
package io.micronaut.security.rolesallowed | ||
|
||
import io.micronaut.context.annotation.Replaces | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.context.env.Environment | ||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
|
||
import jakarta.annotation.security.RolesAllowed | ||
|
||
class JakartaRolesAllowedSpec extends RolesAllowedSpec { | ||
|
||
@Requires(env = Environment.TEST) | ||
@Requires(property = 'spec.name', value = 'RolesAllowedSpec') | ||
@Replaces(RolesAllowedSpec.BookController.class) | ||
@RolesAllowed(['ROLE_USER']) | ||
@Controller(RolesAllowedSpec.controllerPath) | ||
static class BookController { | ||
|
||
@RolesAllowed(['ROLE_USER', 'ROLE_ADMIN']) | ||
@Get("/books") | ||
Map<String, Object> list() { | ||
[books: ['Building Microservice', 'Release it']] | ||
} | ||
|
||
@Get("/classlevel") | ||
Map<String, Object> classlevel() { | ||
[books: ['Building Microservice', 'Release it']] | ||
} | ||
|
||
@RolesAllowed(['ROLE_ADMIN', 'ROLE_MANAGER']) | ||
@Get("/forbidenbooks") | ||
Map<String, Object> forbiddenList() { | ||
[books: ['Building Microservice', 'Release it']] | ||
} | ||
} | ||
|
||
|
||
} |
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