...
Añadir esta clase que es idéntica a es.um.atica.seam.security.authentication.method.AuthenticationMethodSSO.java salvo porque sobrescribe al final el método preAuthenticate() (línea 9396):
| Bloque de código | ||||||
|---|---|---|---|---|---|---|
| ||||||
package es.um.atica.apium.security.authentication; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Objects; import org.jboss.seam.log.Log; import org.jboss.seam.log.Logging; import org.jboss.seam.util.Strings; import org.umu.atica.servicios.gesper.gente.entity.Persona; import org.umu.atica.servicios.gesper.gente.exceptions.PersonaException; import org.umu.atica.servicios.gesper.gente.exceptions.PersonaNotFoundException; import buscador.servicios.exceptions.ServiceNotFoundException; import es.um.atica.apium.security.authentication.AuthenticationManagerBean.AuthenticationType; import es.um.atica.seam.security.authentication.method.AuthenticationMethod; import es.um.atica.seam.utils.CasClient3Util; /** * Clase para definir el metodo de autenticación por SSO mediante CAS de la UMU. * * @author juanmiguelbg * @version 0.0.3 */ public class AuthenticationMethodSSO extends AuthenticationMethod { private static final Log LOG = Logging.getLog(AuthenticationMethodSSO.class); 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"; /* * (non-Javadoc) * * @see es.um.atica.util.FundeWebManager#getLog() */ @Override protected Log getLog() { return LOG; } @Override public boolean authenticate() { LOG.info("Autenticando a: #0", getCredentials().getUsername()); getStatusMessages().clearGlobalMessages(); try { if ( isDni( getCredentials().getUsername() ) ) { // Autenticacion Clave - DNI loadPersonaByDniCAS( getCredentials().getUsername() ); } else { // Autenticacion Correo UMU - Ticarum loadUser( getCredentials().getUsername() ); } return true; } catch (ServiceNotFoundException snfe) { LOG.error("Error al buscar el servicio de Gente", snfe); } catch (PersonaException pe) { LOG.error("Error: al obtener los datos del Usuario en GENTE.", pe); processErrorMessage(); } catch (PersonaNotFoundException pnfe) { LOG.error("Error: el usuario no se encuentra en GENTE.", pnfe); processErrorMessage(); } catch ( Throwable t ) { LOG.error("Error inesperado.", t); } return false; } private void loadPersonaByDniCAS( String username ) throws PersonaException, PersonaNotFoundException, ServiceNotFoundException { try { loadPersonaByIdentificador( username ); } catch ( PersonaNotFoundException pnfe ) { LOG.warn( "El usuario no se encuentra en GENTE, completamos con datos del CAS.", pnfe ); loadPersonaByDniClave( username ); } } private void loadPersonaByDniClave( String username ) { Map<String, Object> atributos = CasClient3Util.getPrincipalAttributes( CasClient3Util.getCasClient3Principal() ); LOG.info( "Atributos: #0", atributos ); String client = (String) atributos.get( CLIENT_NAME_KEY ); if ( !Strings.isEmpty( client ) && ( CLAVE_CLIENT_NAME.equals( client ) || CERT_CLIENT_NAME.equals( client ) ) ) { String nombre = new String( ( ( String ) atributos.get( FIRST_NAME_KEY ) ).getBytes(), StandardCharsets.UTF_8 ); String apellidos = new String( ( ( String ) atributos.get( FAMILY_NAME_KEY ) ).getBytes(), StandardCharsets.UTF_8 ); Persona persona = new Persona( username, nombre, apellidos, null ); getUmuIdentity().setPersona( persona ); } } @Override public void preAuthenticate() { final Map<String, Object> atributos = CasClient3Util.getPrincipalAttributes( CasClient3Util.getCasClient3Principal() ); final String clientcredentialType = ( String ) atributos.get( CLIENTAUTHENTICATION_METHOD_NAME_KEY ); iffinal ( !Strings.isEmpty( client ) && CLAVE_CLIENT_NAMEString client = ( String ) atributos.get( CLIENT_NAME_KEY ); boolean encontrado = false; for ( final AuthenticationType authType : AuthenticationType.values() ) { if ( Objects.equals( credentialType, authType.getAuthenticationMethod() ) && Objects.equals( client, authType.getClientName() ) ) { encontrado = true; break; } } if ( !encontrado ) { throw new AuthenticationMethodNotSupportedException( CLAVE_CLIENT_NAMEclient ); } } } |
AuthenticationFactorySSO.java
...