Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:08:19+00:00 2026-06-17T15:08:19+00:00

I have a Spring Service layer that is secured with @PreAuthorize annotation. So far

  • 0

I have a Spring Service layer that is secured with @PreAuthorize annotation. So far this has been used through a web application. Now I need to enable our SpringBatch jobs to use these services.

What’s the most straight-forward way to enable jobs to authorize them before calling these service methods?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:08:21+00:00Added an answer on June 17, 2026 at 3:08 pm

    I had the same problem, here is what I did to solve it :

    In my tasklet, I called this method :

    securityUtility.authenticateAs("login", "password");
    

    Here is the definition of my authenticateAs method written in my SecurityUtility class injected in my tasklet, implementing ApplicationContextAware :

    /**
     * Authenticate a user
     * @param username
     * @param password
     * @return
     */
    public Authentication authenticateAs(String username, String password) {
        ProviderManager providerManager = (ProviderManager)applicationContext.getBean("authenticationManager");
        Authentication authentication = providerManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
        setAuthentication(authentication);
        return authentication;
    }
    

    It works well, let me know if you need more details 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spring roo web service that I am currently building out but
I have a web service written in Spring MVC. It can be used by
I'm using spring ws 2.0.2.RELEASE I have a web service that creates a sales
I have a web service that returns this string via the jQuery $.ajax() call
In a Spring web application I have several DAO and service layer beans. One
I have a Web Service ( model-layer ) which communicates with Database. This module
I have a web-application in java, spring framework, hibernate on tomcat, that has basically
I have a spring-based Web Service. I now want to build a sort of
I have application that look like below without spring (prior) UI-> service --> javabean
I am using Spring 3.1 and have my DAO and service layer(transactional) written. However

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.