Estás viendo una versión antigua de esta página. Ve a la versión actual.

Comparar con el actual Ver el historial de la página

« Anterior Versión 8 Siguiente »

Pasos a seguir en aplicaciones NO FundeWeb 2.0

Hay que modificar o añadir las siguientes carpetas y ficheros. Los cambios indicados concretos son los específicos para la aplicación INTERCAMBIO.

query.xml

  • Se ha añadido una query para obtener el correo a través del DNI.
<QUERY ID="ObtieneCorreoDniBD">
	<SQL>
		SELECT email
	      FROM umdp.usuarios_intercambio    
	     WHERE dni = ?   
	     UNION
	    SELECT email
	      FROM intercambio.usuarios_extra    
	     WHERE dni = ?  
	</SQL>
</QUERY>


VerificaUser.java

  • Se definen de manera estática los diferentes tipos de autenticaciones
  • En el método setCasUser se hace la distinción de si estamos recibiendo un correo electrónico (acceso CAS) o un DNI (acceso con certificado)
  • El método verificaUserSSO se ha adaptado para la nueva funcionalidad
  • Especial atención 
	private final String SSOAuthenticationMethods[] = {
			"SSO_CORREO( \"LdapAuthenticationHandler\", \"\", \"label.authentication.type.correoum\" )",
			"SSO_CLAVE( \"DelegatedClientAuthenticationHandler\", \"Cl@ve\", \"label.authentication.type.clave\" )",
			"SSO_CERT( \"DelegatedClientAuthenticationHandler\", \"Cert\", \"label.authentication.type.cert\" )",
			"SSO_CMN( \"DelegatedClientAuthenticationHandler\", \"CMN\", \"label.authentication.type.cmn\" )"
	};

	private static final String CLIENT_NAME_KEY = "clientName";
	private static final String AUTHENTICATION_METHOD_NAME_KEY = "authenticationMethod";
	private static final String CLAVE_CLIENT_NAME = "Cl@ve";
	private static final String CERT_CLIENT_NAME = "Cert";
	private static final String FIRST_NAME_KEY = "FirstName";
	private static final String FAMILY_NAME_KEY = "FamilyName";


	public void setupCasUser( javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res,
			javax.servlet.http.HttpSession session ) {
		setCasUser( req.getRemoteUser() );
		setReq( req );
	}

	public void setCasUser( String dniOrCorreo ) {
		if ( ( dniOrCorreo != null ) && ( !dniOrCorreo.equals( "" ) ) ) {
			if ( isValidEmailAddress( dniOrCorreo ) ) {
				correo = dniOrCorreo;
			} else {
				dni = dniOrCorreo;
			}
		}
	}

	public boolean isValidEmailAddress( String email ) {
		final String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
		final java.util.regex.Pattern p = java.util.regex.Pattern.compile( ePattern );
		final java.util.regex.Matcher m = p.matcher( email );
		return m.matches();
	}

	public void verificarAuthMethodSSO() {
		final String[] ssoAuthenticationMethods = getSSOAuthenticationMethods();

		if ( ssoAuthenticationMethods.length > 0 ) {

			final AttributePrincipalImpl attPrinImpl = ( AttributePrincipalImpl ) getReq().getUserPrincipal();
			final Map<String, Object> atributos = attPrinImpl.getAttributes();

			final String credentialType = ( String ) atributos.get( AUTHENTICATION_METHOD_NAME_KEY );
			final String client = ( String ) atributos.get( CLIENT_NAME_KEY );

			boolean encontrado = false;
			for ( final String authType : ssoAuthenticationMethods ) {
				// separando por comillas
				final String[] aux = authType.split( "\"" );

				if ( ( "LdapAuthenticationHandler" ).equals( credentialType )
						|| ( credentialType.equals( aux[1] ) && ( client.equals( aux[3] ) ) ) ) {
					encontrado = true;
					break;
				}
			}
			if ( !encontrado ) {
				throw new AuthenticationMethodNotSupportedException( client );
			}
		}
	}

	public UsuarioIntercambio verificaUserSSO() {
		CallableStatement cs = null;
		String dnic = "";
		codigo = "011";
		ResultSet rs = null;
		try {
			if ( !correo.equals( "" ) ) {
				cs = conn.prepareCall( getQuery( "ObtieneDniCorreoBD" ) );
				cs.setString( 1, correo );
				cs.registerOutParameter( 2, java.sql.Types.VARCHAR );
				cs.setQueryTimeout( 4 );
				cs.execute();
				dnic = cs.getString( 2 );
			} else {
				// hay que eliminar la letra
				dnic = dni;
				dnic = dnic.substring( 0, 8 );
				cs = conn.prepareCall( getQuery( "ObtieneCorreoDniBD" ) );
				cs.setString( 1, dnic );
				cs.setString( 2, dnic );
				cs.registerOutParameter( 2, java.sql.Types.VARCHAR );
				cs.setQueryTimeout( 4 );
				rs = cs.executeQuery();
				if ( rs.next() ) {
					correo = rs.getString( 1 );
				}
			}

			if ( ( dnic != null ) && !dnic.equals( "" ) ) {
				user = new UsuarioIntercambio( conn, dnic, codigo, correo.toLowerCase() );
				user.setIPCliente( userIPCliente );
				user.setIPInternet( userIPInternet );
				return user;
			}
		}
		catch ( final Exception ex ) {
			LOG.error( "Error VerificaUserSSO: " + ex );
		}
		finally {
			try {
				if ( cs != null ) {
					cs.close();
				}
			}
			catch ( final SQLException e2 ) {}
		}
		return null;
	}

AuthenticationMethodNotSupportedException.java

package intercambio.com.authentication.exceptions;

public class AuthenticationMethodNotSupportedException extends RuntimeException {

	private static final long serialVersionUID = -7140000370097499128L;

	private static final String MENSAJE = "Authentication method not supported: ";

	public AuthenticationMethodNotSupportedException( String message ) {
		super( MENSAJE + message );
	}

	public AuthenticationMethodNotSupportedException( Throwable cause ) {
		super( MENSAJE, cause );
	}

	public AuthenticationMethodNotSupportedException( String message, Throwable cause ) {
		super( MENSAJE + message, cause );
	}
}

  • Sin etiquetas