Código de Java - Guardar archivos de texto en java

Imágen de perfil
Val: 492
Bronce
Ha aumentado 1 puesto en Java (en relación al último mes)
Gráfica de Java

Guardar archivos de texto en javagráfica de visualizaciones


Java

Publicado el 23 de Diciembre del 2017 por Rafael Angel (81 códigos)
33.310 visualizaciones desde el 23 de Diciembre del 2017
Permite guardar un archivo de texto con la informacion que se ha escrito en un JTextArea.
Se muestra en forma ordenada y muy clara como se ha programado este simple ejemplo.
Tiene eventos con java.awt.event.ActionListener,entre otras bibliotecas.

Requerimientos

tener la maquina virtual java instalada y algun compilador java, preferiblemente NetBeans, DrJava o Geany.
Nota:
El programa fue editado en Geany pero solo es texto plano.

1.0
estrellaestrellaestrellaestrellaestrella(2)

Publicado el 23 de Diciembre del 2017gráfica de visualizaciones de la versión: 1.0
33.311 visualizaciones desde el 23 de Diciembre del 2017
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

Version unica para uso de ejemplo y para compartirse aqui deseando ayudar a los demas.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//Rafael Angel Montero Fernández.
//Correo: Sharkyc12@gmail.com
//Fecha 23 de diciembre del 2017.
 
//Estas son bibliotecas para poder guardar el archivo de texto.
import java.io.BufferedWriter;//Escribe la informacion en el archivo o sea lo graba en el disco duro.
import java.io.File;//Comprueva si existe el archivo.
import java.io.FileWriter;//Indica el archivo en el que se va a escribir.
import java.io.IOException;//Para el control de errores. Se debe poner entre public ....() y {}
import java.awt.FileDialog;//Muestra un dialogo salvar archivos.
/////////////////////////////////////
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
 
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
//El archivo java debe ser guardado con el nombre de la clase publica.
//Guardelo con el nombre Formulario.java
public class Formulario extends JFrame implements ActionListener
{
	private JLabel jlTexto;
	private JTextArea jtaTexto;
	private JButton jbSalir, jbGuardar;
	private JScrollPane jspTexto;//Todo JTextArea debe llevar asociado un JScrollPane.
	private Archivo archivo;
	private Font fuente;
 
	public Formulario()
	{
		//Configuarando las caracteristicas del form
		super("Guardar texto.");
		setSize(500,500);
		setLayout(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		setResizable(false);
		///////////////////////////////////////////////////
		fuente=new Font("Tahoma", Font.BOLD, 16);
		jlTexto=new JLabel("Escriba el texto");
		jlTexto.setBounds(1,1,150,25);
		getContentPane().add(jlTexto);
		//El JTextArea se agrega al JScrollPane.
		jtaTexto=new JTextArea();
		jtaTexto.setFont(fuente);
		jtaTexto.setToolTipText("Escriba el texto que quiera en el campo de texto");
		jtaTexto.setBounds(1,35,490,370);
		jspTexto=new JScrollPane(jtaTexto);
		jspTexto.setBounds(1,35,490,370);//El JScrollPane tiene las mismas coordenadas que el JTextArea.
		getContentPane().add(jspTexto);
		jbGuardar=new JButton("Guardar");
		jbGuardar.setToolTipText("Guarda lo que ha escrito en el campo de texto");
		jbGuardar.setBounds(10,425,100,25);
		getContentPane().add(jbGuardar);
		jbGuardar.addActionListener(this);
		jbSalir=new JButton("Salir");
		jbSalir.setBounds(385,425,100,25);
		jbSalir.addActionListener(this);
		getContentPane().add(jbSalir);
		archivo=new Archivo();
	}//Constructor
 
	public static void main(String args[])
	{
		Formulario frm=new Formulario();
		frm.show();
	}//main
 
	public void actionPerformed(ActionEvent evt)
	{
		click_guardar(evt);
		click_salir(evt);
	}//actionPerformed
 
	public void click_guardar(ActionEvent evt)
	{
		if(evt.getActionCommand().equalsIgnoreCase("Guardar"))
		{
			JOptionPane.showMessageDialog(null, archivo.escribir_archivo(jtaTexto.getText()) );
		}//if
	}//click_guardar
 
	public void click_salir(ActionEvent evt)
	{
		if(evt.getActionCommand().equalsIgnoreCase("Salir"))
		{
			System.exit(0);
		}//if
	}//click_salir	
 
}//Formulario
////////////////////////////////////////////////////////////
//Clase declarada en modo friend.
class Archivo
{
	private File flArchivo;
	private String Ruta_del_archivo;
	private BufferedWriter bwEscritor;
	private FileWriter fwArchivo_en_el_que_escribir;
	private FileDialog fdGuardar;
 
	public Archivo()
	{
		fdGuardar=new FileDialog(fdGuardar, "Guardar como", FileDialog.SAVE);
 
		Ruta_del_archivo="";
		flArchivo=new File(Ruta_del_archivo);
	}//Constructor
 
	public String escribir_archivo(String texto_a_guardar)
	{
		String mTextos[]=texto_a_guardar.split("\n"), respuesta="";//Se detecta el salto de linea, se va colocando en el vector.
	//JOptionPane.showMessageDialog(null,texto_a_guardar);
		fdGuardar.setVisible(true);
		fdGuardar.dispose();
		Ruta_del_archivo=fdGuardar.getDirectory()+fdGuardar.getFile() + ".txt";
		flArchivo=new File(Ruta_del_archivo);
		//Este condicional no afecta en nada la forma de guardar el archivo pero si es bueno usarlo para no borrar un trabajo previo.
		if(flArchivo.exists())
		{
			respuesta="El archivo ya existia y ha sido sobreescrito. \nEn la direccion: " +  flArchivo.getPath( ) ;
		}//if
		else
		{
			respuesta="El archivo ha sido creado exitosamente.\nEn la direccion: " +  flArchivo.getPath( ) ;
		}//else*/
 
		try{
			//Este bloque de codigo obligatoriamente debe ir dentro de un try.
			fwArchivo_en_el_que_escribir=new FileWriter(flArchivo);//De momento se deja hasta aqui, listo para escribir, se escribe en el momento de dar la orden.
			for (int i=0; i<=mTextos.length-1;i++)
			{
				//Se va escribiendo cada linea en el archivo de texto.
				fwArchivo_en_el_que_escribir.write(mTextos[i] + "\r\n" );
			}//for
			//Este metodo escribe el archivo en el disco duro.
			bwEscritor=new BufferedWriter(fwArchivo_en_el_que_escribir);
			bwEscritor.close();//Se cierra el archivo.		
		}catch(Exception ex){JOptionPane.showMessageDialog(null,ex.getMessage());}
 
		return respuesta;
	}//escribir_archivo
 
}//Class Archivo
///////////////////////////////////////////////////////////////////////////////



Comentarios sobre la versión: 1.0 (2)

juan totrres
28 de Octubre del 2021
estrellaestrellaestrellaestrellaestrella
Una pregunta si abro un archivo y escribo nuevas cosas, como puedo hacer para que guarde los cambios del archivo sin necesidad de que se vuelva abrir la ventana de dialogo
Responder
AuthUtils
21 de Febrero del 2022
estrellaestrellaestrellaestrellaestrella
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* https://opensso.dev.java.net/public/CDDLv1.0.html or
* opensso/legal/CDDLv1.0.txt
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: AuthUtils.java,v 1.33 2009/12/15 16:39:47 qcheng Exp $
*
* Portions Copyrighted 2010-2015 ForgeRock AS.
*/
package com.sun.identity.authentication.service;

import static org.forgerock.openam.session.SessionConstants.*;

import com.iplanet.am.util.Misc;
import com.iplanet.am.util.SystemProperties;
import com.iplanet.dpro.session.SessionException;
import com.iplanet.dpro.session.SessionID;
import com.iplanet.dpro.session.service.InternalSession;
import com.iplanet.sso.SSOException;
import com.iplanet.sso.SSOToken;
import com.iplanet.sso.SSOTokenManager;
import com.sun.identity.authentication.AuthContext;
import com.sun.identity.authentication.client.AuthClientUtils;
import com.sun.identity.authentication.client.ZeroPageLoginConfig;
import com.sun.identity.authentication.config.AMAuthConfigUtils;
import com.sun.identity.authentication.config.AMAuthLevelManager;
import com.sun.identity.authentication.server.AuthContextLocal;
import com.sun.identity.authentication.server.AuthXMLRequest;
import com.sun.identity.authentication.spi.AMLoginModule;
import com.sun.identity.authentication.spi.AMPostAuthProcessInterface;
import com.sun.identity.authentication.spi.AuthLoginException;
import com.sun.identity.authentication.util.AMAuthUtils;
import com.sun.identity.authentication.util.ISAuthConstants;
import com.sun.identity.common.ResourceLookup;
import com.sun.identity.policy.PolicyUtils;
import com.sun.identity.policy.plugins.AuthLevelCondition;
import com.sun.identity.policy.plugins.AuthSchemeCondition;
import com.sun.identity.policy.plugins.AuthenticateToRealmCondition;
import com.sun.identity.policy.plugins.AuthenticateToServiceCondition;
import com.sun.identity.security.AdminTokenAction;
import com.sun.identity.shared.Constants;
import com.sun.identity.shared.configuration.SystemPropertiesManager;
import com.sun.identity.shared.datastruct.CollectionHelper;
import com.sun.identity.shared.debug.Debug;
import com.sun.identity.shared.encode.CookieUtils;
import com.sun.identity.shared.encode.URLEncDec;
import com.sun.identity.sm.DNMapper;
import com.sun.identity.sm.SMSException;
import com.sun.identity.sm.ServiceConfig;
import com.sun.identity.sm.ServiceConfigManager;
import com.sun.identity.sm.ServiceSchema;
import com.sun.identity.sm.ServiceSchemaManager;
import java.net.URL;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.StringTokenizer;
import javax.security.auth.callback.Callback;
import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.forgerock.openam.session.SessionServiceURLService;
import org.forgerock.openam.shared.security.whitelist.RedirectUrlValidator;
import org.forgerock.util.Reject;

public class AuthUtils extends AuthClientUtils {

public static final String BUNDLE_NAME="amAuth";

/**
* Authentication type for Realm based authentication after
* Composite Advices
*/
public static final int REALM = 1;

/**
* Authentication type for Service based authentication after
* Composite Advices
*/
public static final int SERVICE = 2;

/**
* Authentication type for Module based authentication after
* Composite Advices
*/
public static final int MODULE = 3;


private static ArrayList pureJAASModuleClasses = new ArrayList();
private static ArrayList ISModuleClasses = new ArrayList();
private static Hashtable moduleService = new Hashtable();
private static ResourceBundle bundle;
static Debug utilDebug = Debug.getInstance("amAuthUtils");
private static String serviceURI = SystemProperties.get(
Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR) + "/UI/Login";

private static final SessionServiceURLService SESSION_SERVICE_URL_SERVICE = SessionServiceURLService.getInstance();

/*
* Private constructor to prevent any instances being created
*/
private AuthUtils() {
}

/* retrieve session */
public static com.iplanet.dpro.session.service.InternalSession
getSession(AuthContextLocal authContext) {

com.iplanet.dpro.session.service.InternalSession sess =
getLoginState(authContext).getSession();
if (utilDebug.messageEnabled()) {
utilDebug.message("returning session : " + sess);
}
return sess;
}

/* this method does the following
* 1. initializes authService (AuthD) if not already done.
* 2. parses the request parameters and stores in dataHash
* 3. Retrieves the AuthContext object from the global table
* 4. if this is found then updates the loginState request
* type to false and updates the parameter hash table in
* loginstate object.

* on error throws AuthException
*/

/**
* Returns the authentication context for a request.
*
* @param request HTTP Servlet Request.
* @param response HTTP Servlet Response.
* @param sid SessionID for this request.
* @param isSessionUpgrade <code>true</code> if session upgrade.
* @param isBackPost <code>true</code> if back posting.
* @return authentication context.
*/
public static AuthContextLocal getAuthContext(
HttpServletRequest request,
HttpServletResponse response,
SessionID sid,
boolean isSessionUpgrade,
boolean isBackPost) throws AuthException {
return getAuthContext(request,response,sid,
isSessionUpgrade,isBackPost,false);
}

/**
* Returns the authentication context for a request.
*
* @param request HTTP Servlet Request.
* @param response HTTP Servlet Response.
* @param sid SessionID for this request.
* @param isSessionUpgrade <code>true</code> if session upgrade.
* @param isBackPost <code>true</code> if back posting.
* @param isLogout <code>true</code> for logout.
* @return authentication context.
*/
public static AuthContextLocal getAuthContext(
HttpServletRequest request,
HttpServletResponse response,
SessionID sid,
boolean isSessionUpgrade,
boolean isBackPost,
boolean isLogout) throws AuthException {
utilDebug.message("In AuthUtils:getAuthContext");
Hashtable dataHash;
AuthContextLocal authContext = null;
LoginState loginState = null;
// initialize auth service.
AuthD ad = AuthD.getAuth();

try {
dataHash = parseRequestParameters(request);
authContext = retrieveAuthContext(request, sid);

if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtil:getAuthContext:sid is.. .: "
+ sid);
utilDebug.message("AuthUtil:getAuthContext:authContext is..: "
+ authContext);
}

if(!sid.isNull() && authContext == null && !isSessionUpgrade) {
String authCookieValue = getAuthCookieValue(request);
if ((authCookieValue != null) && (!authCookieValue.isEmpty())
&& (!authCookieValue.equalsIgnoreCase("LOGOUT"))) {
String cookieURL = null;
try {
SessionID sessionID = new SessionID(authCookieValue);
URL sessionServerURL = SESSION_SERVICE_URL_SERVICE.getSessionServiceURL(sessionID);
cookieURL = sessionServerURL.getProtocol()
+ "://" + sessionServerURL.getHost() + ":"
+ Integer.toString(sessionServerURL.getPort())
+ serviceURI;
} catch (SessionException e) {
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils:getAuthContext():"
+ e.toString());
}
}
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils:getAuthContext():"
+ "cookieURL : " + cookieURL);
}
if ((cookieURL != null) && (!cookieURL.isEmpty()) &&
(isLocalServer(cookieURL,true))) {
utilDebug.error("AuthUtils:getAuthContext(): "
+ "Invalid Session Timed out");
clearAllCookies(request, response);
throw new AuthException(
AMAuthErrorCode.AUTH_TIMEOUT, null);
}
}
}

if (utilDebug.messageEnabled()) {
utilDebug.message("isSessionUpgrade :" + isSessionUpgrade);
utilDebug.message("BACK with Request method POST : "
+ isBackPost);
}

if ((authContext == null) && (isLogout)) {
return null;
}

if ((authContext == null) || (isSessionUpgrade) || (isBackPost)) {
try {
loginState = new LoginState();
InternalSession oldSession = null;
if (sid != null) {
oldSession = AuthD.getSession(sid);
loginState.setOldSession(oldSession);
}
if (isSessionUpgrade) {
loginState.setOldSession(oldSession);
loginState.setSessionUpgrade(isSessionUpgrade);
} else if (isBackPost) {
loginState.setOldSession(oldSession);
}
authContext =
loginState.createAuthContext(request,response,sid,dataHash);
authContext.setLoginState(loginState);
String queryOrg =
getQueryOrgName(request,getOrgParam(dataHash));
if (utilDebug.messageEnabled()) {
utilDebug.message("query org is .. : "+ queryOrg);
}
loginState.setQueryOrg(queryOrg);
} catch (AuthException ae) {
utilDebug.message("Error creating AuthContextLocal : ");
if (utilDebug.messageEnabled()) {
utilDebug.message("Exception " , ae);
}
throw new AuthException(ae);
}
} else {
utilDebug.message("getAuthContext: found existing request.");

authContext = processAuthContext(authContext,request,
response,dataHash,sid);
loginState = getLoginState(authContext);
loginState.setNewRequest(false);
}

} catch (Exception ee) {
if (utilDebug.messageEnabled()) {
utilDebug.message("Error creating AuthContextLocal : "
+ ee.getMessage());
}

throw new AuthException(ee);
}
return authContext;

}


// processAuthContext checks for arg=newsession in the HttpServletRequest
// if request has arg=newsession then destroy session and create a new
// AuthContextLocal object.

static AuthContextLocal processAuthContext(AuthContextLocal authContext,
HttpServletRequest request,
HttpServletResponse response,
Hashtable dataHash,
SessionID sid) throws AuthException {
// initialize auth service.
AuthD ad = AuthD.getAuth();

LoginState loginState = getLoginState(authContext);
com.iplanet.dpro.session.service.InternalSession sess = null;

if (utilDebug.messageEnabled()) {
utilDebug.message("in processAuthContext authcontext : "
+ authContext );
utilDebug.message("in processAuthContext request : " + request);
utilDebug.message("in processAuthContext response : " + response);
utilDebug.message("in processAuthContext sid : " + sid);
}

if (newSessionArgExists(dataHash, sid) &&
(loginState.getLoginStatus() == LoginStatus.AUTH_SUCCESS)) {
// destroy auth context and create new one.
utilDebug.message("newSession arg exists");
destroySession(loginState);
try{
loginState = new LoginState();
authContext = loginState.createAuthContext(request,response,
sid,dataHash);
authContext.setLoginState(loginState);
String queryOrg =
getQueryOrgName(request,getOrgParam(dataHash));
if (utilDebug.messageEnabled()) {
utilDebug.message("query org is .. : "+ queryOrg);
}
loginState.setQueryOrg(queryOrg);
} catch (AuthException ae) {
utilDebug.message("Error creating AuthContextLocal");
if (utilDebug.messageEnabled()) {
utilDebug.message("Exception " , ae);
}
throw new AuthException(AMAuthErrorCode.AUTH_ERROR, null);
}
} else {
boolean multipleTabsUsed =
Boolean.valueOf(SystemPropertiesManager.get(
Constants.MULTIPLE_TABS_USED, "false")).booleanValue();
if (ad.debug.messageEnabled()) {
ad.debug.message("AuthUtils .processAuthContext()."
+ Constants.MULTIPLE_TABS_USED+"="+multipleTabsUsed);
}
/**
* This flag indicates that the same user is running the auth login
* process in mutiple tabs of the same browser and if the auth
* is zero user intervention custom auth module using Redirect
* Callback, then there would be a situation that the same
* authContext is being used by mutiple threads running the
* auth process, so avoid this mutiple thread interference keep
* the process in this while loop until all the submit requirements
* have been met. This is a specific customer use case.
*/
if (multipleTabsUsed) {
while (authContext.submittedRequirements()) {
ad.debug.error("Currently processing submit Requirements");
if (ad.debug.messageEnabled()) {
ad.debug.message("watiting for submittedRequirements() "
+"to complete.");
}
}
} else {
if (authContext.submittedRequirements()) {
ad.debug.error("Currently processing submit Requirements");
throw new AuthException(
AMAuthErrorCode.AUTH_TOO_MANY_ATTEMPTS, null);
}
}
// update loginState - requestHash , sess
utilDebug.message("new session arg does not exist");
loginState.setHttpServletRequest(request);
loginState.setHttpServletResponse(response);
loginState.setParamHash(dataHash);
sess = ad.getSession(sid);
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtil :Session is .. : " + sess);
}
loginState.setSession(sess);
loginState.setRequestLocale(request);
if (checkForCookies(request)) {
loginState.setCookieDetect(false);
}
}
return authContext;
}

public static LoginState getLoginState(AuthContextLocal authContext) {

LoginState loginState = null;
if (authContext != null) {
loginState = authContext.getLoginState();
}
return loginState;
}

public static Hashtable getRequestParameters(AuthContextLocal authContext) {
LoginState loginState = getLoginState(authContext);
if (loginState != null) {
return loginState.getRequestParamHash();
} else {
return new Hashtable();
}
}

// retrieve the sid from the LoginState object
public static String getSidString(AuthContextLocal authContext)
throws AuthException {
com.iplanet.dpro.session.service.InternalSession sess = null;
String sidString = null;
try {
if (authContext != null) {
LoginState loginState = authContext.getLoginState();
if (loginState != null) {
SessionID sid = loginState.getSid();
if (sid != null) {
sidString = sid.toString();
}
}
}
} catch (Exception e) {
if (utilDebug.messageEnabled()) {
utilDebug.message("Error retreiving sid.. :" + e.getMessage());
}
// no need to have error code since the method where this is called
// generates AUTH_ERROR
throw new AuthException("noSid", new Object[] {e.getMessage()});
}
return sidString;
}

/**
* Returns the Cookie object created based on the cookie name,
* Session ID and cookie domain. If Session is in invalid State then
* cookie is created with authentication cookie name , if
* Active/Inactive Session state AM Cookie Name will be used to create
* cookie.
*
* @param ac the AuthContext object
*@param cookieDomain the cookie domain for creating cookie
* @return Cookie object.
*/
public static Cookie getCookieString(AuthContextLocal ac,String cookieDomain) {

Cookie cookie=null;
String cookieName = getCookieName();
try {
String sidString= getSidString(ac);
LoginState loginState = getLoginState(ac);
if (loginState != null && loginState.isSessionInvalid()) {
cookieName = getAuthCookieName();
utilDebug.message("Create AM AUTH cookie");
}
cookie = createCookie(cookieName,sidString,cookieDomain);
if (CookieUtils.isCookieSecure()) {
cookie.setSecure(true);
}
} catch (Exception e) {
if (utilDebug.messageEnabled()) {
utilDebug.message("Error getting sid : " + e.getMessage());
}
}
if (utilDebug.messageEnabled()) {
utilDebug.message("Cookie is : " + cookie);
}
return cookie;
}

/**
* Returns the Logout cookie.
*
* @param ac the AuthContextLocal object
* @param cookieDomain the cookieDomain
* @return Logout cookie .
*/
public static Cookie getLogoutCookie(AuthContextLocal ac, String cookieDomain) {
LoginState loginState = getLoginState(ac);
SessionID sid = loginState.getSid();
String logoutCookieString = getLogoutCookieString(sid);
Cookie logoutCookie = createCookie(logoutCookieString,cookieDomain);
logoutCookie.setMaxAge(0);
return logoutCookie;
}

/*
* Return logout url from LoginState object.
* Caller should check for possible null value returned.
*/
public String getLogoutURL(AuthContextLocal authContext) {

try {
LoginState loginState = getLoginState(authContext);
if (loginState == null) {
// No default URL in case of logout. Taken care by LogoutBean.
return null;
}

String logoutURL = loginState.getLogoutURL();

if (utilDebug.messageEnabled()) {
if (logoutURL != null)
utilDebug.message("AuthUtils: getLogoutURL : " + logoutURL);
else
utilDebug.message("AuthUtils: getLogoutURL : null");
}

return logoutURL;

} catch (Exception e) {
utilDebug.message("Exception " , e);
return null;
}
}
// returns true if request is new else false.
public static boolean isNewRequest(AuthContextLocal ac) {

LoginState loginState = getLoginState(ac);
if (loginState.isNewRequest()) {
if (utilDebug.messageEnabled()) {
utilDebug.message("this is a newRequest");
}
return true;
} else {
if (utilDebug.messageEnabled()) {
utilDebug.message("this is an existing request");
}
return false;
}
}

/* return the successful login url */
public static String getLoginSuccessURL(AuthContextLocal authContext) {
String successURL = null;
LoginState loginState = getLoginState(authContext);
if (loginState == null) {
successURL = AuthD.getAuth().getDefaultSuccessURL();
} else {
successURL = getLoginState(authContext).getSuccessLoginURL();
}
return successURL;
}

/* return the failed login url */
public static String getLoginFailedURL(AuthContextLocal authContext) {

try {
LoginState loginState = getLoginState(authContext);
if (loginState == null) {
return AuthD.getAuth().getDefaultFailureURL();
}
String loginFailedURL=loginState.getFailureLoginURL();
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils: getLoginFailedURL "
+ loginFailedURL);
}

// remove the loginstate/authContext from the hashtable
//removeLoginStateFromHash(authContext);
// destroySession(authContext);
return loginFailedURL;
} catch (Exception e) {
utilDebug.message("Exception " , e);
return null;
}
}


/* return filename - will use FileLookUp API
* for UI only - this returns the relative path
*/
public static String getFileName(AuthContextLocal authContext,String fileName) {

LoginState loginState = getLoginState(authContext);
String relFileName = null;
if (loginState != null) {
relFileName =
getLoginState(authContext).getFileName(fileName);
}
if (utilDebug.messageEnabled()) {
utilDebug.message("getFileName:AuthUtilsFile name is :"
+ relFileName);
}
return relFileName;
}

public static boolean getInetDomainStatus(AuthContextLocal authContext) {
return getLoginState(authContext).getInetDomainStatus();
}

public static boolean newSessionArgExists(
Hashtable dataHash, SessionID sid) {

String arg = (String)dataHash.get("arg");
if (arg != null && arg.equals("newsession")) {
if (retrieveAuthContext(sid) != null) {
return true;
} else {
return false;
}
}
return false;
}

public static String encodeURL(String url,
AuthContextLocal authContext,
HttpServletResponse response) {
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils:input url is :"+ url);
}
LoginState loginState = getLoginState(authContext);
String encodedURL;

if (loginState==null) {
encodedURL = url;
} else {
encodedURL = loginState.encodeURL(url,response);
}
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils:encoded url is :"+encodedURL);
}

return encodedURL;
}

// return the locale
public static String getLocale(AuthContextLocal authContext) {
// initialize auth service.
AuthD ad = AuthD.getAuth();

if (authContext == null) {
return ad.getPlatformLocale();
}

LoginState loginState = getLoginState(authContext);
if (loginState == null) {
return ad.getPlatformLocale();
}

return loginState.getLocale();
}

static void destroySession(LoginState loginState) {
try {
if (loginState != null) {
loginState.destroySession();
}
} catch (Exception e) {
utilDebug.message("Error destroySEssion : " , e);
}
}

public static void destroySession(AuthContextLocal authContext) {
if (authContext != null) {
LoginState loginState = getLoginState(authContext);
destroySession(loginState);
}
}

/**
* Returns <code>true</code> if the session has timed out or the page has
* timed out.
*
* @param authContext the authentication context object for the request.
* @return <code>true</code> if timed out else false.
*/
public static boolean sessionTimedOut(AuthContextLocal authContext) {
boolean timedOut = false;

LoginState loginState = getLoginState(authContext);

if (loginState != null) {
timedOut = loginState.isTimedOut();

if (!timedOut) {
InternalSession sess = loginState.getSession();
if (sess != null) {
timedOut = sess.isTimedOut();
}
loginState.setTimedOut(timedOut);
}

if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils.sessionTimedOut: " + timedOut);
}
}
return timedOut;
}

public static Cookie createlbCookie(AuthContextLocal authContext,
String cookieDomain, boolean persist) throws AuthException {
Cookie lbCookie=null;
try {
if (utilDebug.messageEnabled()) {
utilDebug.message("cookieDomain : " + cookieDomain);
}
LoginState loginState = getLoginState(authContext);
lbCookie = loginState.setlbCookie(cookieDomain, persist);
return lbCookie;
} catch (Exception e) {
utilDebug.message("Unable to create Load Balance Cookie");
throw new AuthException(AMAuthErrorCode.AUTH_ERROR, null);
}

}

public static void setlbCookie(AuthContextLocal authContext,
HttpServletRequest request, HttpServletResponse response)
throws AuthException {
String cookieName = getlbCookieName();
if (cookieName != null && cookieName.length() != 0) {
Set domains = getCookieDomainsForReq(request);
if (!domains.isEmpty()) {
for (Iterator it = domains.iterator(); it.hasNext(); ) {
String domain = (String)it.next();
Cookie cookie = createlbCookie(authContext, domain, false);
CookieUtils.addCookieToResponse(response, cookie);
}
} else {
CookieUtils.addCookieToResponse(response,
createlbCookie(authContext, null, false));
}
}
}

/* return the indexType for this request */
public static int getCompositeAdviceType(AuthContextLocal authContext) {
int type = 0;
try {
LoginState loginState = getLoginState(authContext);
if (loginState != null) {
type = loginState.getCompositeAdviceType();
}
if (utilDebug.messageEnabled()) {
utilDebug.message("in getCompositeAdviceType, type : " + type);
}
} catch (Exception e) {
if (utilDebug.messageEnabled()) {
utilDebug.message("Error in getCompositeAdviceType : "
+ e.toString());
}
}
return type;
}

/* return the indexType for this request */
public static AuthContext.IndexType getIndexType(AuthContextLocal authContext) {

try {
AuthContext.IndexType indexType = null;
LoginState loginState = getLoginState(authContext);

if (loginState != null) {
indexType = loginState.getIndexType();
}
if (utilDebug.messageEnabled()) {
utilDebug.message("in getIndexType, index type : " + indexType);
}
return indexType;
} catch (Exception e) {
if (utilDebug.messageEnabled()) {
utilDebug.message("Error in getIndexType : " + e.toString());
}
return null;
}
}

/* return the indexName for this request */
public static String getIndexName(AuthContextLocal authContext) {

try {
String indexName = null;
LoginState loginState = getLoginState(authContext);

if (loginState != null) {
indexName = loginState.getIndexName();
}
if (utilDebug.messageEnabled()) {
utilDebug.message("in getIndexName, index Name : " + indexName);
}
return indexName;
} catch (Exception e) {
if (utilDebug.messageEnabled()) {
utilDebug.message("Error in getIndexName : " + e.toString());
}
return null;
}
}

public static Callback[] getRecdCallback(AuthContextLocal authContext) {
LoginState loginState = getLoginState(authContext);
Callback[] recdCallback = null;
if (loginState != null) {
recdCallback = loginState.getRecdCallback();
}

if ( recdCallback != null ) {
if (utilDebug.messageEnabled()) {
for (int i = 0; i < recdCallback.length; i++) {
utilDebug.message("in getRecdCallback, recdCallback["
+ i + "] :" + recdCallback[i]);
}
}
}
else {
utilDebug.message("in getRecdCallback, recdCallback is null");
}

return recdCallback;
}

/**
* Returns the resource based on the default values.
*
* @param request HTTP Servlet Request.
* @param fileName name of the file
* @return Path to the resource.
*/
public static String getDefaultFileName(
HttpServletRequest request,
String fileName) {
// initialize auth service.
AuthD ad = AuthD.getAuth();

String locale = ad.getPlatformLocale();
String filePath = getFilePath(getClientType(request));
String fileRoot = getFileRoot();
String orgDN;
try {
orgDN = getDomainNameByRequest(request, parseRequestParameters(request));
} catch (Exception ex) {
//in case we are unable to determine the realm from the incoming
//requests, let's fallback to top level realm
orgDN = getOrganizationDN("/", false, request);
}
String orgFilePath = getOrgFilePath(orgDN);
String templateFile = null;
try {
templateFile = ResourceLookup.getFirstExisting(
ad.getServletContext(),
fileRoot,locale,orgFilePath,filePath,fileName,
templatePath);
} catch (Exception e) {
templateFile = new StringBuffer().append(templatePath)
.append(fileRoot).append(Constants.FILE_SEPARATOR)
.append(fileName).toString();
}
if (utilDebug.messageEnabled()) {
utilDebug.message("getDefaultFileName:templateFile is :" +
templateFile);
}
return templateFile;
}

/* returns the orgDN for the request */
public static String getOrgDN(AuthContextLocal authContext) {
String orgDN = null;
LoginState loginState = getLoginState(authContext);
if (loginState != null) {
orgDN = loginState.getOrgDN();
}
if (utilDebug.messageEnabled()) {
utilDebug.message("orgDN is : " + orgDN);
}
return orgDN;
}

/* create auth context for org */
public static AuthContextLocal getAuthContext(String orgName)
throws AuthException {
return getAuthContext(orgName,"0",false, null);
}

public static AuthContextLocal getAuthContext(String orgName,
String sessionID) throws AuthException {
return getAuthContext(orgName,sessionID,false, null);
}

public static AuthContextLocal getAuthContext(String orgName,
HttpServletRequest req) throws AuthException {
return getAuthContext(orgName, "0", false, req);
}

public static AuthContextLocal getAuthContext(String orgName,
String sessionID, boolean logout) throws AuthException {
return getAuthContext(orgName, sessionID, logout, null);
}

public static AuthContextLocal getAuthContext(HttpServletRequest req,
String sessionID) throws AuthException {
return getAuthContext(null, sessionID, false, req);
}

/** Returns the AuthContext Handle for the Request.
* @param orgName OrganizationName in request
* @param sessionID Session ID for this request
* @param isLogout a boolean which is true if it is a Logout request
* @param req HttpServletRequest
* @return AuthContextLocal object
*/
public static AuthContextLocal getAuthContext(String orgName,
String sessionID, boolean isLogout, HttpServletRequest req)
throws AuthException {
return getAuthContext(orgName, sessionID, isLogout, req, null, null);
}

/* create auth context for org and sid, if sessionupgrade then
* save the previous authcontext and create new authcontext
* orgName - organization name to login to
* sessionId - sessionID of the request - "0" if new request
* isLogout - is this a logout request
* @param orgName OrganizationName in request
* @param sessionID Session ID for this request
* @param isLogout a boolean which is true if it is a Logout request
* @param req HttpServletRequest
* @param indexType Index Type
* @param indexName Index Name
* @return AuthContextLocal object
*/
public static AuthContextLocal getAuthContext(String orgName,
String sessionID, boolean isLogout, HttpServletRequest req,
String indexType, AuthXMLRequest xmlReq)
throws AuthException {
return getAuthContext(orgName, sessionID, isLogout, req,indexType,
xmlReq,false);
}

/* create auth context for org and sid, if sessionupgrade then
* save the previous authcontext and create new authcontext
* orgName - organization name to login too
* sessionId - sessionID of the request - "0" if new request
* isLogout - is this a logout request - if yes then no session
* upgrade - this is the case where session is VALID so need
* to use this flag to determine if session upgrade is needed.
* this is used mainly for Logout/Abort.
* @param orgName OrganizationName in request
* @param sessionID Session ID for this request
* @param isLogout a boolean which is true if it is a Logout request
* @param req HttpServletRequest
* @param indexType Index Type
* @param indexName Index Name
* @param forceAuth force auth flag
* @return AuthContextLocal object
*/
public static AuthContextLocal getAuthContext(String orgName,
String sessionID, boolean isLogout, HttpServletRequest req,
String indexType, AuthXMLRequest xmlReq, boolean forceAuth)
throws AuthException {
AuthContextLocal authContext = null;
SessionID sid = null;
com.iplanet.dpro.session.service.InternalSession sess = null;
LoginState loginState = null;
boolean sessionUpgrade = false;
AuthD ad = AuthD.getAuth();
int sessionState = -1;
SSOToken ssot = null;
String indexName = null;
if (xmlReq != null) {
indexName = xmlReq.getIndexName();
}

if (utilDebug.messageEnabled()) {
utilDebug.message("orgName : " + orgName);
utilDebug.message("sessionID is " + sessionID);
utilDebug.message("sessionID is " + sessionID.length());
utilDebug.message("isLogout : " + isLogout);
}
try {
if ((sessionID != null) && (!sessionID.equals("0"))) {
sid = new SessionID(sessionID);
authContext = retrieveAuthContext(req, sid);

// check if this sesson id is active, if yes then it
// is a session upgrade case.
loginState = getLoginState(authContext);
if (loginState != null) {
sess = loginState.getSession();
} else {
sess = AuthD.getSession(sessionID);
}
if (sess == null) {
sessionUpgrade = false;
} else {
sessionState = sess.getState();
if (utilDebug.messageEnabled()) {
utilDebug.message("sid from sess is : " + sess.getID());
utilDebug.message("sess is : " + sessionState);
}
if (!((sessionState == INVALID) || (isLogout))) {
ssot = AuthUtils.
getExistingValidSSOToken(sid);
if ((indexType != null) && (indexName != null)) {
Hashtable indexTable = new Hashtable();
indexTable.put(indexType, indexName);
if (forceAuth) {
sessionUpgrade = true;
} else {
sessionUpgrade = checkSessionUpgrade(ssot,
indexTable);
}
} else {
sessionUpgrade = true;
}
}
if (utilDebug.messageEnabled()) {
utilDebug.message("session upgrade is : "+ sessionUpgrade);
}
}
}

if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtil:getAuthContext:sid is.. .: " + sid);
utilDebug.message("AuthUtil:getAuthContext:authContext is.. .: "
+ authContext);
utilDebug.message("AuthUtil:getAuthContext:sessionUpgrade is.. .: "
+ sessionUpgrade);
utilDebug.message("AuthUtil:getAuthContext:ForceAuth is.. .: "
+ forceAuth);
}

if ((orgName == null) && (sess == null)) {
utilDebug.error("Cannot create authcontext with null org " );
throw new AuthException(AMAuthErrorCode.AUTH_TIMEOUT, null);
} else if (orgName == null) {
orgName = sess.getClientDomain();
}
if ((ssot != null) && !(sessionUpgrade)) {
xmlReq.setValidSessionNoUpgrade(true);
return null;
}

if (((ssot == null) && (loginState == null)) ||
(sessionUpgrade)) {
try {
loginState = new LoginState();
InternalSession oldSession = null;
if (sid != null) {
oldSession = AuthD.getSession(sid);
loginState.setOldSession(oldSession);
}
if (sessionUpgrade) {
loginState.setOldSession(oldSession);
loginState.setSessionUpgrade(sessionUpgrade);
}
authContext = loginState.createAuthContext(sid,orgName,req);
authContext.setLoginState(loginState);
String queryOrg = getQueryOrgName(null,orgName);
if (utilDebug.messageEnabled()) {
utilDebug.message("query org is .. : "+ queryOrg);
}
loginState.setQueryOrg(queryOrg);
} catch (AuthException ae) {
utilDebug.message("Error creating AuthContextLocal 2: ");
if (utilDebug.messageEnabled()) {
utilDebug.message("Exception " , ae);
}
throw new AuthException(ae);
}
} else {
// update loginState
try {
com.iplanet.dpro.session.service.InternalSession
requestSess = ad.getSession(sessionID);
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtil :Session is .. : " + requestSess);
}
loginState = getLoginState(authContext);
if (loginState != null) {
loginState.setSession(requestSess);
loginState.setNewRequest(false);
}
} catch (Exception ae) {
utilDebug.message("Error Retrieving AuthContextLocal" );
if (utilDebug.messageEnabled()) {
utilDebug.message("Exception " , ae);
}
throw new AuthException(AMAuthErrorCode.AUTH_ERROR, null);
}

}
if (forceAuth){
loginState.setForceAuth(forceAuth);
}


} catch (Exception ee) {
if (utilDebug.messageEnabled()) {
utilDebug.message("Creating AuthContextLocal 2: ", ee);
}

throw new AuthException(ee);
}
return authContext;
}

/**
* Returns a set of authentication modules whose authentication
* level equals to or greater than the specified authLevel. If no such
* module exists, an empty set will be returned.
*
* @param authLevel authentication level.
* @param organizationDN DN for the organization.
* @param clientType Client type, e.g. "genericHTML".
* @return Set of authentication modules whose authentication level
* equals to or greater that the specified authentication level.
*/
public static Set getAuthModules(
int authLevel,
String organizationDN,
String clientType) {
return AMAuthLevelManager.getInstance().getModulesForLevel(authLevel,
organizationDN, clientType);
}

/* return the previous Internal Session */
public static InternalSession getOldSession(AuthContextLocal authContext) {
LoginState loginState = getLoginState(authContext);
InternalSession oldSession = loginState.getOldSession();
return oldSession;
}


/* retreive the authcontext based on the req */
public static AuthContextLocal getOrigAuthContext(SessionID sid)
throws AuthException {
AuthContextLocal authContext = null;
// initialize auth service.
AuthD ad = AuthD.getAuth();
try {
authContext = retrieveAuthContext(sid);
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtil:getOrigAuthContext:sid is.:"+sid);
utilDebug.message("AuthUtil:getOrigAuthContext:authContext is:"
+ authContext);
}
com.iplanet.dpro.session.service.InternalSession sess =
getLoginState(authContext).getSession();
if (utilDebug.messageEnabled()) {
utilDebug.message("Session is : "+ sess);
if (sess != null) {
utilDebug.message("Session State is : "+ sess.getState());
}
utilDebug.message("Returning Orig AuthContext:"+authContext);
}

if (sess == null) {
return null;
} else {
int status = sess.getState();
if (status == INVALID){
return null;
}
return authContext;
}

} catch (Exception e) {
return null;
}
}

/* check if the session is active */
public static boolean isSessionActive(AuthContextLocal oldAuthContext) {
try {
com.iplanet.dpro.session.service.InternalSession sess =
getSession(oldAuthContext);
if (utilDebug.messageEnabled()) {
utilDebug.message("Sess is : " + sess);
}
boolean sessionValid = false;
if (sess != null) {
if (sess.getState() == VALID) {
sessionValid = true;
}
if (utilDebug.messageEnabled()) {
utilDebug.message("Sess State is : " + sess.getState());
utilDebug.message("Is Session Active : " + sessionValid);
}
}
return sessionValid;
} catch (Exception e) {
return false;
}
}

/* retreive session property */
public static String getSessionProperty(String property,
AuthContextLocal oldAuthContext) {
String value = null;
try {
com.iplanet.dpro.session.service.InternalSession sess =
getSession(oldAuthContext);
if (sess != null) {
value = sess.getProperty(property);
}
} catch (Exception e) {
utilDebug.message("Error : " ,e);
}
return value;
}

/* return session upgrade - true or false */
public static boolean isSessionUpgrade(AuthContextLocal authContext) {
boolean isSessionUpgrade = false;
LoginState loginState = getLoginState(authContext);
if (loginState != null) {
isSessionUpgrade = loginState.isSessionUpgrade();
}
return isSessionUpgrade;
}

public static void setCookieSupported(AuthContextLocal ac, boolean flag) {
LoginState loginState = getLoginState(ac);
if (loginState==null) {
return;
}
if (utilDebug.messageEnabled()) {
utilDebug.message("set cookieSupported to : " + flag);
utilDebug.message("set cookieDetect to false");
}
loginState.setCookieSupported(flag);
}

public static boolean isCookieSupported(AuthContextLocal ac) {
LoginState loginState = getLoginState(ac);
if (loginState==null) {
return false;
}
return loginState.isCookieSupported();
}

public static boolean isCookieSet(AuthContextLocal ac) {
LoginState loginState = getLoginState(ac);
if (loginState==null) {
return false;
}
return loginState.isCookieSet();
}

/**
* Returns true if cookies found in the request.
*
* @param req HTTP Servlet Request.
* @param ac authentication context.
* @return <code>true</code> if cookies found in request.
*/
public static boolean checkForCookies(HttpServletRequest req, AuthContextLocal ac){
LoginState loginState = getLoginState(ac);
if (loginState!=null) {
utilDebug.message("set cookieSet to false.");
loginState.setCookieSet(false);
loginState.setCookieDetect(false);
}
// came here if cookie not found , return false
return (
(CookieUtils.getCookieValueFromReq(req,getAuthCookieName()) != null)
||
(CookieUtils.getCookieValueFromReq(req,getCookieName()) !=null));
}

public static String getLoginURL(AuthContextLocal authContext) {
LoginState loginState = getLoginState(authContext);
if (loginState==null) {
return null;
}
return loginState.getLoginURL();
}

public static AuthContextLocal getAuthContextFromHash(SessionID sid) {
AuthContextLocal authContext = null;
if (sid != null) {
authContext = retrieveAuthContext(sid);
}
return authContext;
}

// Gets Callbacks per Page state
public static Callback[] getCallbacksPerState(AuthContextLocal authContext,
String pageState) {
LoginState loginState = getLoginState(authContext);
Callback[] recdCallback = null;
if (loginState != null) {
recdCallback = loginState.getCallbacksPerState(pageState);
}
if ( recdCallback != null ) {
if (utilDebug.messageEnabled()) {
for (int i = 0; i < recdCallback.length; i++) {
utilDebug.message("in getCallbacksPerState, recdCallback["
+ i + "] :" + recdCallback[i]);
}
}
}
else {
utilDebug.message("in getCallbacksPerState, recdCallback is null");
}
return recdCallback;
}

// Sets (saves) Callbacks per Page state
public static void setCallbacksPerState(AuthContextLocal authContext,
String pageState, Callback[] callbacks) {
LoginState loginState = getLoginState(authContext);

if (loginState != null) {
loginState.setCallbacksPerState(pageState, callbacks);
}
if ( callbacks != null ) {
if (utilDebug.messageEnabled()) {
for (int i = 0; i < callbacks.length; i++) {
utilDebug.message("in setCallbacksPerState, callbacks["
+ i + "] :" + callbacks[i]);
}
}
}
else {
utilDebug.message("in setCallbacksPerState, callbacks is null");
}
}

/**
* Returns the SessionID . This is required to added the
* session server , port , protocol info to the Logout Cookie.
* SessionID is retrieved from Auth service if a handle on
* the authcontext object is there otherwise retrieve from
* the request object.
*
* @param authContext is the AuthContext which is
* handle to the auth service
* @param request is the HttpServletRequest object
* @return returns the SessionID
*/
public static SessionID getSidValue(AuthContextLocal authContext,
HttpServletRequest request) {
SessionID sessionId = null;
if (authContext != null) {
utilDebug.message("AuthContext is not null");
try {
String sid = getSidString(authContext);
if (sid != null) {
sessionId = new SessionID(sid);
}
} catch (Exception e) {
utilDebug.message("Exception getting sid",e);
}
}

if (sessionId == null) {
utilDebug.message("Sid from AuthContext is null");
sessionId = new SessionID(request);
}

if (utilDebug.messageEnabled()) {
utilDebug.message("sid is : " + sessionId);
}
return sessionId;
}

/**
* Returns true if cookie is supported otherwise false.
* the value is retrieved from the auth service if a
* handle on the auth context object is there otherwise
* check the HttpServletRequest object to see if the
* OpenAM cookie is in the request header
*
* @param authContext is the handle to the auth service
* for the request
* @param request is the HttpServletRequest Object for the
* request
*
* @return boolean value indicating whether cookie is supported
* or not.
*/
public static boolean isCookieSupported(AuthContextLocal authContext,
HttpServletRequest request) {
boolean cookieSupported;
if (authContext != null) {
utilDebug.message("AuthContext is not null");
cookieSupported = isCookieSupported(authContext);
} else {
cookieSupported = checkForCookies(request,null);
}

if (utilDebug.messageEnabled()) {
utilDebug.message("Cookie supported" + cookieSupported);
}
return cookieSupported;
}

/**
* Returns the previous index type after module is selected in authlevel
* or composite advices.
* @param ac the is the AuthContextLocal instance.
* @return AuthContext.IndexType.
*/
public static AuthContext.IndexType getPrevIndexType(AuthContextLocal ac) {
LoginState loginState = getLoginState(ac);
if (loginState != null) {
return loginState.getPreviousIndexType();
} else {
return null;
}
}

/**
* Returns whether the auth module is or the auth chain contains pure JAAS
* module(s).
* @param configName a string of the configuratoin name.
* @return 1 for pure JAAS module; -1 for module(s) provided by IS only.
*/
public static int isPureJAASModulePresent(
String configName, AMLoginContext amlc)
throws AuthLoginException {

if (AuthD.isEnforceJAASThread()) {
return 1;
}
int returnValue = -1;

Configuration ISConfiguration = null;
try {
ISConfiguration = Configuration.getConfiguration();
} catch (Exception e) {
return 1;
}

AppConfigurationEntry[] entries =
ISConfiguration.getAppConfigurationEntry(configName);
if (entries == null) {
throw new AuthLoginException("amAuth",
AMAuthErrorCode.AUTH_CONFIG_NOT_FOUND, null);
}
// re-use the obtained configuration
amlc.setConfigEntries(entries);

for (int i = 0; i < entries.length; i++) {
String className = entries[i].getLoginModuleName();
if (utilDebug.messageEnabled()) {
utilDebug.message("
Responder

Comentar la versión: 1.0

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s4357