rest - Spring Security for RESTful API -


i'm building restful api using spring 4.1.6 , spring-boot-starter-data-rest.

to make rest api functional need last piece of puzzle: security. noticed spring has it's own spring-security-* packages can aid task.

i tried using spring-security-config , spring-security-web , works charm, exception if user not authenticated, spring redirect user login, giving html login form. because it's restful api, need error returned in json object if user lacks credentials or not have enough permissions read particular resource. i'm sure i'm not first ask question , searched on web people asking same thing, couldn't quite find was looking for. so.. should continue research in direction spring-security, or should find something?

any advice welcome, thank you

to change login form response custom http response need configure custom http response handler http security config. if using xml security configuration use configuration shown below, failurehandler used 1 available in spring security package. update url match yours.

<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:beans="http://www.springframework.org/schema/beans"     xmlns:sec="http://www.springframework.org/schema/security"     xsi:schemalocation="       http://www.springframework.org/schema/security       http://www.springframework.org/schema/security/spring-security-3.2.xsd       http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">      <!-- rest authentication entry point configuration -->     <http use-expressions="true" entry-point-ref="restauthenticationentrypoint">         <intercept-url pattern="/api/**" />         <sec:form-login authentication-failure-handler-ref="myfailurehandler" />          <logout />     </http>      <!-- using default failure handler -->     <beans:bean id="myfailurehandler"         class="org.springframework.security.web.authentication.simpleurlauthenticationfailurehandler" /> </beans:beans> 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -