学習目的のために、私は単純なSpring-hibernateアプリケーションです。1対多のdbアソシエーションがあり、ウェアハウスを追加したり、ウェアハウスごとにアイテムを追加したりできます。ここで、認証用のスプリングセキュリティを追加したかったのですが、サイトにアクセスしようとすると、HTTPERROR404が発生します。
web.xmlのspring-securityparは次のとおりです。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
これがspring-security.xmlです:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http use-expressions="true">
<intercept-url pattern="/record/**" access="permitAll" />
<form-login />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="password" authorities="supervisor, teller, user" />
<user name="dianne" password="emu" authorities="teller, user" />
<user name="scott" password="wombat" authorities="user" />
<user name="peter" password="opal" authorities="user" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
access="permitAll"
「access="hasRole('supervisor')」に変更すると、アプリケーションにアクセスしようとすると、ユーザー名とパスワードの入力を求められますが、入力すると404エラーが発生します。スプリングセキュリティがないと、「http:// localhost:8080 / testapp / record / list」にアクセスするとアプリは正常に動作します...このサイトを使用してスプリングセキュリティについて学習しました-http://static.springsource.org/spring -security / site / tutorial.html
これが私のMainControllerです:
@Controller
@RequestMapping("/record")
public class MainController {
protected static Logger logger = Logger.getLogger("controller");
@Resource(name="warehouseService")
private WarehouseService warehouseService;
@Resource(name="itemService")
private ItemService itemService;
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String getRecords(Model model) {
logger.debug("Received request to show records page");
// Retrieve all persons
List<Warehouse> warehouses = warehouseService.getAll();
// Prepare model object
List<WarehouseDTO> warehousesDTO = new ArrayList<WarehouseDTO>();
for (Warehouse warehouse: warehouses) {
// Create new data transfer object
WarehouseDTO dto = new WarehouseDTO();
dto.setId(warehouse.getId());
dto.setName(warehouse.getName());
dto.setAddress(warehouse.getAddress());
dto.setManager(warehouse.getManager());
dto.setItems(itemService.getAll(warehouse.getId()));
warehousesDTO.add(dto);
}
model.addAttribute("warehouses", warehousesDTO);
return "records";
}
何か案は?