Custom Http Authorization Header with Spring Secur

2020-02-24 12:06发布

We are building a Restful service using Grails framework and are providing security for it using Spring Security plugin. I wanted to check with you all on best approach to take when you want to authenticate using Custom Authorization header. More on this approach can be read here Custom HTTP Authorization Header

In my case, client id and secret is stored in Ldap and header comes with SHA1 encryption. What would be the best approach to implement this using Spring Security?

I have asked same question in Grails mailing list too.

Any insight would be helpful. Thanks.

~Abhi

2条回答
▲ chillily
2楼-- · 2020-02-24 12:33

You have to implement your own Filter, Authentication Provider and Authentication token (to pass data to your Provider).

See:

查看更多
beautiful°
3楼-- · 2020-02-24 12:36

List item

If you are using basic authorization header, then following configuration works for you in context-security.xml file.

< http  auto-config="true" use-expressions="true" pattern="/project/api/**">
        < intercept-url pattern="/**" access="isFullyAuthenticated()" requires-channel="${security.requires.channel}" method="POST"/>
        < custom-filter ref="basicAuthenticationFilter" position="PRE_AUTH_FILTER"/>
    < /http>    
    < beans:bean id="basicAuthenticationFilter" class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter">
        < beans:property name="authenticationManager" ref="authenticationManager" />
        < beans:property name="authenticationEntryPoint" ref="authenticationEntryPoint" />      
    < /beans:bean>

I have used same approach for rest services But you need to be careful that whatever scheme you use for encoding username and password, same scheme you should use in filter for decoding 'Authorization' header information. If you are using some custom scheme for encoding 'Authorization' header, then you need to extend 'BasicAuthenticationFilter' and provide appropriate decoding of 'Authorization' header

查看更多
登录 后发表回答