Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint to retrieve all request mappings as JSON #265

Merged
merged 3 commits into from
Jul 31, 2017

Conversation

chrismayer
Copy link
Collaborator

This introduces an HTTP-endpoint /endpointdoc which delivers all mapped HTTP endpoints as JSON objects. Hereby all instances (types and methods) annotated with @RequestMapping annotations in @Controller classes are analyzed.

This is very useful to build an automated API documentation for all HTTP endpoints.

Sample output:

{
    name : null,
    patternsCondition : {
        patterns : [ "/my-super-shogun-endpoint" ],
        empty : false
    },
    methodsCondition : {
        methods : [ "POST", "PUT" ],
        empty : false
    },
    paramsCondition : {
        expressions : [],
        empty : true
    },
    headersCondition : {
        expressions : [],
        empty : true
    },
    consumesCondition : {
        expressions : [ {
            mediaType : {
                type : "application",
                subtype : "json",
                parameters : {},
                qualityValue : 1,
                charSet : null,
                wildcardType : false,
                concrete : true,
                wildcardSubtype : false
            },
            negated : false
        } ],
        empty : false,
        consumableMediaTypes : [ {
            type : "application",
            subtype : "json",
            parameters : {},
            qualityValue : 1,
            charSet : null,
            wildcardType : false,
            concrete : true,
            wildcardSubtype : false
        } ]
    },
    producesCondition : {
        expressions : [],
        empty : true,
        producibleMediaTypes : []
    },
    customCondition : null
}

This introduces an HTTP endpoint which delivers all HTTP endpoints as JSON
objects. Hereby all instances (types and methods) annotated with @RequestMapping
annotations in @controller classes are analyzed.
@marcjansen
Copy link
Member

Nice! How well does this play with swagger? Is this related somehow? Is the format you return otherwise standardized?

@chrismayer
Copy link
Collaborator Author

This is default format Spring offers us out of the box. I doubt that there is any relation to Swagger or that this is a standardized format.

springfox seems to offer a nice way to get a Swagger-compatible API-documentation. Maybe someone finds the time to test and come up with another PR extending this EndpointDocController.

@marcjansen
Copy link
Member

Ping @buehner wrt to security

I am 👍

@buehner
Copy link
Member

buehner commented Jul 28, 2017

Nice addition! Thx @chrismayer

Regarding security we can think about encapsulating the trivial controller logic in a service. The service could easily be secured with an annotation to avoid that everyone can consume this endpoint to retrieve information for possible attacks!?

But i'm not really sure in this point...

@chrismayer
Copy link
Collaborator Author

Thanks for the feedback guys!

I agree that we can encapsulate the logic in service, so we are able to secure this interface.

@buehner: Do you have a suggestion for a security level? I would suggest

hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(returnObject, 'READ')

like is done in other GET requests.

@buehner
Copy link
Member

buehner commented Jul 31, 2017

I think hasPermission(returnObject, 'READ') only makes sense if there is a PermissionEvaluator for the returnObject. But even without a permission evaluator this would not break anything, so 👍 as we can still add a permission evaluator for such a scenario in follow up PRs

In order to secure the endpoint to retrieve all request mappings this
introduces a service layer with a '@PreAuthorize' annotation.
@chrismayer
Copy link
Collaborator Author

Right @buehner, hasPermission(returnObject, 'READ') makes no sense here. I just added another commit introducing a service layer, which is secured, so only "admins" can access the endpoint.

Would be cool if you could have another look at it.

*
* @author Christian Mayer
*/
@Service("endpoinDocService")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think there is a small typo (missing "t") 😉

* The service layer instance
*/
@Autowired
@Qualifier("endpoinDocService")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above. (missing "t") 😉

@buehner
Copy link
Member

buehner commented Jul 31, 2017

Just found a small typo. If this is fixed: Feel free to merge 👍

@chrismayer
Copy link
Collaborator Author

Thanks again for your review @buehner! I adressed your comment and will merge now.

@chrismayer chrismayer merged commit e218096 into terrestris:master Jul 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants