<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ Copyright 2002-2024 the original author or authors.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      https://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<b:beans xmlns="http://www.springframework.org/schema/security"
	xmlns:b="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd">

	<tx:annotation-driven />

	<b:bean name="transactionManager" class="org.springframework.security.config.MockTransactionManager" />

	<b:bean class='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'/>

	<b:bean id="transactionalTarget" class="org.springframework.security.config.TransactionalTestBusinessBean">
		<intercept-methods use-authorization-manager="false">
			<protect method="*" access="ROLE_USER" />
		</intercept-methods>
	</b:bean>


	<b:bean id="target" class="org.springframework.security.config.TestBusinessBeanImpl">
		<!-- This will add a security interceptor to the bean -->
		<intercept-methods use-authorization-manager="false">
			<protect method="org.springframework.security.config.TestBusinessBean.set*" access="${admin.role}" />
			<protect method="get*" access="${admin.role},ROLE_USER" />
			<protect method="doSomething" access="ROLE_USER" />
		</intercept-methods>
	</b:bean>

	<b:bean id="transactionalTargetAuthorizationManager" class="org.springframework.security.config.TransactionalTestBusinessBean">
		<intercept-methods>
			<protect method="*" access="hasRole('ROLE_USER')" />
		</intercept-methods>
	</b:bean>


	<b:bean id="targetAuthorizationManager" class="org.springframework.security.config.TestBusinessBeanImpl">
		<!-- This will add a security interceptor to the bean -->
		<intercept-methods>
			<protect method="org.springframework.security.config.TestBusinessBean.set*" access="hasRole('${admin.role}')" />
			<protect method="get*" access="hasAnyRole('${admin.role}','ROLE_USER')" />
			<protect method="doSomething" access="hasRole('ROLE_USER')" />
			<protect method="*" access="permitAll"/>
		</intercept-methods>
	</b:bean>

	<b:bean id="targetCustomAuthorizationManager" class="org.springframework.security.config.TestBusinessBeanImpl">
		<!-- This will add a security interceptor to the bean -->
		<intercept-methods authorization-manager-ref="authorization-manager">
			<protect method="*" access="denyAll"/>
		</intercept-methods>
	</b:bean>

	<authentication-manager>
		<authentication-provider>
			<user-service>
				<user name="bob" password="bobspassword" authorities="ROLE_A,ROLE_B" />
				<user name="bill" password="billspassword" authorities="ROLE_A,ROLE_B,AUTH_OTHER" />
			</user-service>
		</authentication-provider>
	</authentication-manager>

	<b:bean id="authorization-manager" class="org.mockito.Mockito" factory-method="mock">
    <b:constructor-arg value="org.springframework.security.authorization.AuthorizationManager" type="java.lang.Class"/>
</b:bean>
</b:beans>
