//
// https://www.ramecera.it/myscrewdriver.html
// e-mail: screwdriver@ramecera.it
//
/* This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0 which accompanies this
 * distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html */
package it.ramecera.screwdriver.component;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import it.ramecera.salad.everyday.Candies;
import it.ramecera.salad.everyday.ExactException;
import it.ramecera.salad.everyday.Mix;
import it.ramecera.salad.file.Equipment;
import it.ramecera.screwdriver.CandyScrew;
import it.ramecera.screwdriver.Cst;
import it.ramecera.screwdriver.Markup;
import it.ramecera.screwdriver.Skill;
import it.ramecera.screwdriver.Train;
import it.ramecera.screwdriver.Wagon;
import it.ramecera.screwdriver.outfits.JspKit;

/** @author M. Maglioni */
final public class SpringSecurity_xml extends FileComponent {

	/** @param skill application main data
	 * @param snippetG name of the file containing the snippet */
	public SpringSecurity_xml(Skill skill, String snippetG) {
		super();
		this.skill = skill;
		this.snippetG = snippetG;
	}

	/** @throws ExactException exception specified by a numeric code */
	@Override
	public void synthesis(HashMap<String, Markup> markupE,
			List<Train> trainE, CandyScrew candyScrew)

			throws FileNotFoundException, IOException, ExactException {

		String g = skill.candies.snippetsYS + snippetG;
		producedMaterial = Equipment.oneString(g) + Candies.LF;

		producedMaterial += Candies.TABS
				+ "<s:http pattern=\"/resources/**\" security=\"none\"/>"
				+ Candies.LF;
		if (skill.authenticationProvider.equals("class")
				&& skill.authenticationMode != null
				&& skill.authenticationMode.equals("trivial")) {
			producedMaterial += Candies.TABS
					+ "<s:http auto-config=\"true\" use-expressions=\"true\">"
					+ Candies.LF;
		} else if (skill.authenticationProvider.equals("class")) {
			producedMaterial += Candies.TABS
					+ "<s:http entry-point-ref=\"loginEntryPoint\""
					+ " use-expressions=\"true\">" + Candies.LF;
		}
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<s:intercept-url pattern=\"/\" access=\"permitAll\"/>"
				+ Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<s:intercept-url pattern=\"/login/*\""
				+ " access=\"permitAll\"/>" + Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<s:intercept-url pattern=\"/logout\""
				+ " access=\"permitAll\"/>" + Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<s:intercept-url pattern=\"/answers/**\""
				+ " access=\"permitAll\"/>" + Candies.LF;

		/* LOOP ON ALL REQUEST MAPS */
		for (int i = 0; i < markupE.get("requmap").recurrenceE
				.size(); i++) {
			Wagon permitWagon = markupE.get("requmap").recurrenceE.get(
					i).wagonE.get("permit");
			Wagon goalWagon = markupE.get("requmap").recurrenceE.get(
					i).wagonE.get("goal");
			// Wagon redirectWagon = markupE.get ("requmap").
			// OccurrenceE
			// .get (i) .wagonE.get ("redirect");
			int z = 0;
			// GOAL CONTROL
			List<Train> tE = markupE.get("jsp").recurrenceE;
			if (goalWagon != null) {
				for (z = 0; z < tE.size(); z++) {
					if (tE.get(z).locomotor.text.equals(
							goalWagon.text)) {
						break;
					}
				}
				if (z == tE.size()) {
					ExactException ne = new ExactException();
					ne.code = 2300;
					ne.datum = "I've not found the JSP " + Mix.dress_A(
							goalWagon.text)
							+ " declared as \"goal\" in " + Mix.dress_A(
									"requestmap+" + markupE.get(
											"requmap").recurrenceE.get(
													i).locomotor.text)
							+ ".";
					ne.className = this.getClass().getName();
					throw ne;
				}
			}
			String[] segmentiE = Mix.separaPath(markupE.get(
					"requmap").recurrenceE.get(i).locomotor.text);
			JspKit jspKit = (JspKit) tE.get(z).locomotor.substance;

			// TREATMENT OF SECURITY SPRING PERMISSIONS

			if (permitWagon != null && permitWagon.text
					.equalsIgnoreCase("all")) {
				producedMaterial += Candies.TABS + Candies.TABS
						+ "<s:intercept-url pattern=\"/" + markupE.get(
								"requmap").recurrenceE.get(
										i).locomotor.text + "\""
						+ " access=\"permitAll\"/>" + Candies.LF;
				/* both in the case of a crud, but also in the case of a
				 * simple form (jspType == 1), the permission is the
				 * same as the mother (the mother is the one without the
				 * prefix "screw") */
				if (jspKit.crud | jspKit.jspType == 1) {
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<s:intercept-url pattern=\"/"
							+ segmentiE[0] + segmentiE[2] + "screw"
							+ segmentiE[1] + "*\""
							+ " access=\"permitAll\"/>" + Candies.LF;
				}
			} else if (permitWagon != null && permitWagon.text
					.equalsIgnoreCase("user")) {
				producedMaterial += Candies.TABS + Candies.TABS
						+ "<s:intercept-url pattern=\"/" + markupE.get(
								"requmap").recurrenceE.get(
										i).locomotor.text + "\""
						+ " access=\"hasRole('ROLE_USER')\"/>"
						+ Candies.LF;
				if (jspKit.crud) {
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<s:intercept-url pattern=\"/"
							+ segmentiE[0] + segmentiE[2] + "screw"
							+ segmentiE[1] + "*\""
							+ " access=\"hasRole('ROLE_USER')\"/>"
							+ Candies.LF;
				}
			} else if (permitWagon != null && permitWagon.text
					.equalsIgnoreCase("admin")) {
				producedMaterial += Candies.TABS + Candies.TABS
						+ "<s:intercept-url pattern=\"/" + markupE.get(
								"requmap").recurrenceE.get(
										i).locomotor.text + "\""
						+ " access=\"hasRole('ROLE_ADMIN')\"/>"
						+ Candies.LF;
				if (jspKit.crud) {
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<s:intercept-url pattern=\"/"
							+ segmentiE[0] + segmentiE[2] + "screw"
							+ segmentiE[1] + "*\""
							+ " access=\"hasRole('ROLE_ADMIN')\"/>"
							+ Candies.LF;
				}
			}
		}
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<s:intercept-url pattern=\"/**\""
				+ " access=\"permitAll\"/>" + Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<s:access-denied-handler"
				+ " error-page=\"/answers/errorPage\"/>" + Candies.LF;
		if (skill.authenticationProvider.equals("class")
				&& skill.authenticationMode != null
				&& skill.authenticationMode.equals("trivial")) {
			producedMaterial += Candies.TABS + Candies.TABS
					+ "<s:form-login login-page=\"/login/form\""
					+ Candies.LF;
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS + "login-processing-url=\"/login\""
					+ Candies.LF;
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS + "username-parameter=\"username\""
					+ Candies.LF;
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS + "password-parameter=\"password\""
					+ Candies.LF;
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS
					+ "authentication-failure-url=\"/login/form?error\""
					+ Candies.LF;
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS + "default-target-url=\"/default\""
					+ Candies.LF;
			/* this option is used to decide if you want to go, after a
			 * login, always to the home page or to the page that was
			 * requested a moment before the login (the latter is
			 * recommended, you click one less) */
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS
					+ "always-use-default-target=\"false\" />"
					+ Candies.LF;
		} else if (skill.authenticationProvider.equals("class")
				&& skill.authenticationMode != null
				&& skill.authenticationMode.equals("domain")) {
			producedMaterial += Candies.TABS + Candies.TABS
					+ "<s:custom-filter ref=\"domainFormLoginFilter\""
					+ Candies.LF;
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS + "position=\"FORM_LOGIN_FILTER\" />"
					+ Candies.LF;
		} else if (skill.authenticationProvider.equals("class")
				&& skill.authenticationMode != null
				&& skill.authenticationMode.equals("simple")) {
			producedMaterial += Candies.TABS + Candies.TABS
					+ "<s:custom-filter ref=\"simpleFormLoginFilter\""
					+ Candies.LF;
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS + "position=\"FORM_LOGIN_FILTER\" />"
					+ Candies.LF;
		}
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<s:logout logout-url=\"/logout\"" + Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS + Candies.TABS
				+ "logout-success-url=\"/login/form?logout\"/>"
				+ Candies.LF;
		producedMaterial += Candies.TABS + "</s:http>" + Candies.LF;

		if (skill.authenticationProvider != null) {
			/* let's see what value the xprovider + markup takes */
			switch (skill.authenticationProvider) {
			case "ldap":
				producedMaterial += Candies.TABS
						+ "<s:ldap-server id=\"ldapServer\""
						+ " ldif=\"classpath:/ldif/"
						+ skill.applicationNameLower + ".ldif\""
						+ Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ " root=\"dc=screw" + Mix.uppercaseFirstChar(
								skill.applicationNameLower)
						+ ",dc=com\"";
				/* closing ldap-server */
				producedMaterial += "/>" + Candies.LF;
				if (skill.ldapService) {
					producedMaterial += Candies.TABS
							+ "<s:ldap-user-service"
							+ " id=\"ldapUserService\""
							+ " server-ref=\"ldapServer\"" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "user-search-filter=\"(uid={0})\""
							+ " group-search-base=\"ou="
							+ skill.searchBase + "\"" + Candies.LF;
					if (skill.userDetailsClass != null) {
						producedMaterial += Candies.TABS + Candies.TABS
								+ "user-details-class=\""
								+ skill.userDetailsClass + "\"/>"
								+ Candies.LF;
					}
				}
				producedMaterial += Candies.TABS
						+ "<s:authentication-manager alias=\"authenticationManager\">"
						+ Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ "<s:ldap-authentication-provider"
						+ " server-ref=\"ldapServer\"" + Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ Candies.TABS
						+ "user-search-filter=\"(uid={0})\""
						+ " group-search-base=\"ou=" + skill.searchBase
						+ "\"" + Candies.LF;
				if (skill.userDetailsClass != null) {
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + "user-details-class=\""
							+ skill.userDetailsClass + "\">"
							+ Candies.LF;
				}
				if (skill.ldapPasswordMethod != null) {
					switch (skill.ldapPasswordMethod) {
					case "password-compare":
						producedMaterial += Candies.TABS
								+ "<s:password-compare/>" + Candies.LF;
						break;
					case "hash_ssha":
						producedMaterial += Candies.TABS + Candies.TABS
								+ "<s:password-compare hash=\"{ssha}\"/>"
								+ Candies.LF;
						break;
					default:
						producedMaterial += Candies.TABS + Candies.TABS
								+ "<s:password-compare hash=\"plaintext\" password-attribute=\""
								+ skill.ldapPasswordMethod + "\"/>"
								+ Candies.LF;
					}
				}
				producedMaterial += Candies.TABS + Candies.TABS
						+ "</s:ldap-authentication-provider>"
						+ Candies.LF;
				producedMaterial += Candies.TABS
						+ "</s:authentication-manager>" + Candies.LF;
				break;
			case "user-service":
				producedMaterial += Candies.TABS
						+ "<s:authentication-manager alias=\"authenticationManager\">"
						+ Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ "<s:authentication-provider>" + Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ "<s:user-service>" + Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ Candies.TABS
						+ "<s:user name=\"user1@example.com\" password=\"user1\" authorities=\"ROLE_USER\"/>"
						+ Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ Candies.TABS
						+ "<s:user name=\"admin1@example.com\" password=\"admin1\" authorities=\"ROLE_USER,ROLE_ADMIN\"/>"
						+ Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ "</s:user-service>" + Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ "</s:authentication-provider>" + Candies.LF;
				producedMaterial += Candies.TABS
						+ "</s:authentication-manager>" + Candies.LF;
				break;
			case "jdbc":
				Train t = markupE.get("hdefrail").recurrenceE.get(
						skill.railK);
				producedMaterial += Candies.TABS
						+ "<s:authentication-manager alias=\"authenticationManager\">"
						+ Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ "<s:authentication-provider>" + Candies.LF;
				producedMaterial += Candies.TABS + Candies.TABS
						+ Candies.TABS
						+ "<s:jdbc-user-service id=\"userDetailService\""
						+ Candies.LF + Candies.TABS + Candies.TABS
						+ Candies.TABS + "data-source-ref=\"" + Cst.RAIL
						+ t.locomotor.text + "DataSource\"";
				if (skill.groupAuthentication != null) {
					producedMaterial += Candies.LF + Candies.TABS
							+ Candies.TABS + Candies.TABS
							+ "group-authorities-by-username-query=\""
							+ skill.groupAuthentication + "\"";
				}
				if (skill.usersByUserName != null) {
					producedMaterial += Candies.LF + Candies.TABS
							+ Candies.TABS + Candies.TABS
							+ "users-by-username-query=\""
							+ skill.usersByUserName + "\"";
				}
				if (skill.authByUserName != null) {
					producedMaterial += Candies.LF + Candies.TABS
							+ Candies.TABS + Candies.TABS
							+ "authorities-by-username-query=\""
							+ skill.authByUserName + "\"";
				}
				producedMaterial += " />" + Candies.LF;
				if (skill.passEncoder != null && skill.passEncoder
						.equalsIgnoreCase("saltedSHA256")) {
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS
							+ "<s:password-encoder ref=\"passwordEncoder\" />"
							+ Candies.LF;
				}
				producedMaterial += Candies.TABS + Candies.TABS
						+ "</s:authentication-provider>" + Candies.LF;
				producedMaterial += Candies.TABS
						+ "</s:authentication-manager>" + Candies.LF;
				if (skill.passEncoder != null && skill.passEncoder
						.equalsIgnoreCase("saltedSHA256")) {
					producedMaterial += Candies.TABS
							+ "<bean:bean id=\"passwordEncoder\" "
							+ "xmlns=\"http://www.springframework.org/schema/beans\""
							+ Candies.LF + Candies.TABS + Candies.TABS
							+ "class=\"org.springframework.security."
							+ "crypto.password.StandardPasswordEncoder\" />"
							+ Candies.LF;
				}
				break;
			case "class":
				if (skill.authenticationMode == null) {
					/* non fare nulla */
				} else if (skill.authenticationMode.equals("domain")) {
					producedMaterial += Candies.TABS
							+ "<s:authentication-manager alias=\"authenticationManager\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<s:authentication-provider ref=\""
							+ skill.applicationNameLower
							+ "UserAuthenticationProvider\"/>"
							+ Candies.LF;
					producedMaterial += Candies.TABS
							+ "</s:authentication-manager>"
							+ Candies.LF;
					producedMaterial += Candies.TABS
							+ "<bean xmlns=\"http://www.springframework.org/schema/beans\""
							+ " id=\"domainFormLoginFilter\" "
							+ "class=\"" + skill.pckg
							+ ".web.authentication.DomainUsernamePasswordAuthenticationFilter\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"filterProcessesUrl\""
							+ " value=\"/login\"/>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"authenticationManager\""
							+ " ref=\"authenticationManager\"/>"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"usernameParameter\""
							+ " value=\"username\"/>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"passwordParameter\" "
							+ "value=\"password\"/>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"authenticationSuccessHandler\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS
							+ "<bean class=\"org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + Candies.TABS
							+ "<property name=\"defaultTargetUrl\" "
							+ "value=\"/default\"/>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + "</bean>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "</property>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"authenticationFailureHandler\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS
							+ "<bean class=\"org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + Candies.TABS
							+ "<property name=\"defaultFailureUrl\" value=\"/login/form?error\"/>"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + "</bean>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "</property>" + Candies.LF;
					producedMaterial += Candies.TABS + "</bean>"
							+ Candies.LF;
					producedMaterial += Candies.TABS
							+ "<bean xmlns=\"http://www.springframework.org/schema/beans\" id=\"loginEntryPoint\" class=\"org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<constructor-arg value=\"/login/form\"/>"
							+ Candies.LF;
					producedMaterial += Candies.TABS + "</bean>"
							+ Candies.LF;
				} else if (skill.authenticationMode.equals("simple")) {
					producedMaterial += Candies.TABS
							+ "<s:authentication-manager alias=\"authenticationManager\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<s:authentication-provider ref=\""
							+ skill.applicationNameLower
							+ "UserAuthenticationProvider\"/>"
							+ Candies.LF;
					producedMaterial += Candies.TABS
							+ "</s:authentication-manager>"
							+ Candies.LF;
					producedMaterial += Candies.TABS
							+ "<bean xmlns=\"http://www.springframework.org/schema/beans\""
							+ " id=\"simpleFormLoginFilter\" "
							+ "class=\"" + skill.pckg
							+ ".web.authentication.SimpleUsernamePasswordAuthenticationFilter\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"filterProcessesUrl\""
							+ " value=\"/login\"/>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"authenticationManager\""
							+ " ref=\"authenticationManager\"/>"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"usernameParameter\""
							+ " value=\"username\"/>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"passwordParameter\" "
							+ "value=\"password\"/>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"authenticationSuccessHandler\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS
							+ "<bean class=\"org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + Candies.TABS
							+ "<property name=\"defaultTargetUrl\" "
							+ "value=\"/default\"/>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + "</bean>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "</property>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<property name=\"authenticationFailureHandler\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS
							+ "<bean class=\"org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + Candies.TABS
							+ "<property name=\"defaultFailureUrl\" value=\"/login/form?error\"/>"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + "</bean>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "</property>" + Candies.LF;
					producedMaterial += Candies.TABS + "</bean>"
							+ Candies.LF;
					producedMaterial += Candies.TABS
							+ "<bean xmlns=\"http://www.springframework.org/schema/beans\" id=\"loginEntryPoint\" class=\"org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint\">"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<constructor-arg value=\"/login/form\"/>"
							+ Candies.LF;
					producedMaterial += Candies.TABS + "</bean>"
							+ Candies.LF;
				} else if (skill.authenticationMode.equals("trivial")) {
					if (skill.userTrivialADMIN != null
							& skill.passTrivialADMIN == null) {
						throw new ExactException("Non è stato"
								+ " impostato correttamente il markup «uspaformadmin+».",
								1301, this.getClass().getName(), "");
					}
					if (skill.userTrivialUSER != null
							& skill.passTrivialUSER == null) {
						throw new ExactException("Non è stato"
								+ " impostato correttamente il markup «uspaformuser+».",
								1302, this.getClass().getName(), "");
					}
					if (skill.userTrivialUSER == null
							& skill.passTrivialUSER == null) {
						throw new ExactException("Non sono stati"
								+ " impostati né il markup "
								+ "«uspaformuser+» né il markup"
								+ " «uspaformadmin+».", 1303, this
										.getClass().getName(), "");
					}
					producedMaterial += Candies.TABS
							+ "<s:authentication-manager>" + Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "<s:authentication-provider>"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + "<s:user-service>"
							+ Candies.LF;
					if (skill.userTrivialUSER != null) {
						producedMaterial += Candies.TABS + Candies.TABS
								+ Candies.TABS + Candies.TABS
								+ "<s:user name=\""
								+ skill.userTrivialUSER + "\" "
								+ "password=\"" + skill.passTrivialUSER
								+ "\" " + "authorities=\"ROLE_USER\" />"
								+ Candies.LF;
					}
					if (skill.userTrivialADMIN != null) {
						producedMaterial += Candies.TABS + Candies.TABS
								+ Candies.TABS + Candies.TABS
								+ "<s:user name=\""
								+ skill.userTrivialADMIN + "\" "
								+ "password=\"" + skill.passTrivialADMIN
								+ "\" "
								+ "authorities=\"ROLE_ADMIN\" />"
								+ Candies.LF;
					}
					producedMaterial += Candies.TABS + Candies.TABS
							+ Candies.TABS + "</s:user-service>"
							+ Candies.LF;
					producedMaterial += Candies.TABS + Candies.TABS
							+ "</s:authentication-provider>"
							+ Candies.LF;
					producedMaterial += Candies.TABS
							+ "</s:authentication-manager>"
							+ Candies.LF;
				}
				break;
			default:
				throw new ExactException("Il valore «"
						+ skill.authenticationProvider
						+ "» per il markup xprovider+ non è"
						+ " tra quelli previsti.", 1300, this.getClass()
								.getName(), "");
			}
		} else {
			producedMaterial += Candies.TABS
					+ "<s:authentication-manager />" + Candies.LF;
		}
		producedMaterial += "</beans>";
	}

	/* scritta solo per ottemperare alla className astratta
	 * FileComponent */
	@SuppressWarnings("javadoc")
	@Override
	/** @param markupE l'elenco dei markup
	 * @param skill insieme delle caratteristiche dell'applicazione
	 * @param recycleBin file dove sono spostati i file cancellati
	 * @throws ExactException eccezione precisata da un code numerico */
	public void directory(HashMap<String, Markup> markupE)

			throws ExactException {

	}
}
