0

I'm writing application (Java + Spring Boot with security on backend), Angularjs on front. I need to send file to backend with share token (security purpose). I have got csrf enabled on backend and interceptor in angular to use it when I create http request. But it doesn't work with ng-dropzone.

I added dropzone config:

$scope.logoDropzoneConfig = {
                parallelUploads: 1,
                maxFileSize: 30,
                url: '/api/companies/upload/logo',
            };

But I have got type=org.springframework.security.access.AccessDeniedException, message=Access is denied.

It is possible to write custom method to send files instead of url in config?

4
  • Can you disable csrf only for /api/companies/upload/logo with spring-security when uploading with dropzone ? http.csrf().ignoringAntMatchers("/api/companies/upload/logo") Commented Jul 3, 2016 at 16:34
  • @MGR my application have to be secure. I don't want to disable csrf for any service. It's not a solution. Commented Jul 4, 2016 at 8:24
  • Yes I just asked. We can talk about implementing CSRF with REST Services and not form submission but it's not the point here. How did you implemented CSRF token in your AngularJS app? (in meta tags? in a cookie ? [+ headers]) Commented Jul 4, 2016 at 15:02
  • I post my answer below. Commented Jul 4, 2016 at 17:48

1 Answer 1

1

I resolve this problem this night. In dropzone configuration I can pass headers so, i pass authorization token like below:

$scope.logoDropzoneConfig = {
                parallelUploads: 1,
                maxFileSize: 30,
                url: '/api/companies/upload/logo',
                headers: {
                    'Authorization' :AuthServerProvider.getToken()
                }
            };

Simple, isn't it ?:)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.