//Controller
@RequestMapping(value = "/SC_A01_01_MasterRegisterIni", method = RequestMethod.GET)
public String init(Model model, Authentication authentication) {
log.info("init Start!");
SC_A01_01_MasterRegisterForm masterForm = new SC_A01_01_MasterRegisterForm();
// disable button
disableButton(model, masterForm, "0", authentication);
model.addAttribute("createForm", masterForm);
model.addAttribute(Const.TITLE, Const.VIEW_MASTER_REGISTER);
log.info("init End!");
return "SC_A01_01_MasterRegister";
}
Как смоделировать аутентификацию?
publi c String init (Модель модели, Аутентификация аутентификация )
Я хочу фиктивную аутентификацию, см. Мой код
@BeforeEach
public void setup() {
request = mockHelp_ROLE_BUSINESS_PLAN_HttpServletRequest();
masterRegisterController.masterRegisterService = masterRegisterService;
mockMvc = MockMvcBuilders.standaloneSetup(masterRegisterController).build();
}
@Test
@WithMockUser(roles="ROLE_BUSINESS_PLAN")
void testInit() throws Exception {
mockMvc.perform(get("/SC_A01_01_MasterRegisterIni")).andExpect(status().isOk())
.andExpect(view().name("SC_A01_01_MasterRegister"))
.andExpect(model().attribute(Const.TITLE, Const.VIEW_MASTER_REGISTER));
}
при запуске, ошибка
java.lang.IllegalStateException: Unable to create SecurityContext using @org.springframework.security.test.context.support.WithMockUser(authorities=[], password=password, roles=[ROLE_BUSINESS_PLAN], setupBefore=TEST_METHOD, username=, value=user)
at org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener.createTestSecurityContext(WithSecurityContextTestExecutionListener.java:126)
at org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener.createTestSecurityContext(WithSecurityContextTestExecutionListener.java:96)
Caused by: java.lang.IllegalArgumentException: roles cannot start with ROLE_ Got ROLE_BUSINESS_PLAN