Ignore:
Timestamp:
11/15/12 11:01:02 (12 years ago)
Author:
vmipsl
Message:

account BD

Location:
ether_statistics/web/src/com/ether
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ether_statistics/web/src/com/ether/ControllerEponge.java

    r574 r667  
    11package com.ether; 
    22 
     3import com.ether.account.Account; 
    34import com.ether.annotation.ControllerMethod; 
    45import com.ether.annotation.ParamName; 
    5 import com.ether.user.User; 
    66import net.sf.json.JSONObject; 
    77import org.apache.commons.logging.Log; 
    88import org.apache.commons.logging.LogFactory; 
    99import org.jetbrains.annotations.NotNull; 
    10 import org.springframework.mail.javamail.JavaMailSenderImpl; 
    11 import org.springframework.mail.javamail.MimeMessageHelper; 
    1210 
    13 import javax.mail.MessagingException; 
    14 import javax.mail.internet.MimeMessage; 
    1511import javax.servlet.http.HttpServletRequest; 
     12import java.security.DigestException; 
     13import java.security.NoSuchAlgorithmException; 
    1614import java.util.HashMap; 
    1715import java.util.Map; 
     
    5654                             @ParamName(ParameterConstants.PARAMETER_PWD) final String password, 
    5755                             @NotNull final HttpServletRequest request ) 
    58             throws ServiceException 
     56            throws WebException 
    5957    { 
    6058        final JSONObject jSONUser = new JSONObject(); 
     
    6563            try 
    6664            { 
    67 //                final User user = getTapasService().getUserByEmail( login ); 
    68 //                final String encryptedPassword = EtherHelper.encryptPassword( password ); 
    69 //                if( user == null ) 
    70 //                    result.put( "errors", "login.error.notFound" ); 
    71 //                else if( !encryptedPassword.equals( user.getPassword() ) ) 
    72 //                    result.put( "errors", "login.error.wrongPassword" ); 
    73 //                else 
    74 //                { 
    75 //                    request.getSession().setAttribute( "SES_USER", user ); 
    76 //                    jSONUser.put( "name", user.getLastName() ); 
    77 //                    jSONUser.put( "firstName", user.getFirstName() ); 
    78 //                    jSONUser.put( "role", user.getRole().name() ); 
    79 //                } 
     65                final Account account = getEtherService().getAccountByLogin( login ); 
     66                final String encryptedPassword = EtherHelper.encryptPassword( password ); 
     67                if( account == null ) 
     68                    throw new WebException( WebException.WebCode.ERROR_LOGIN_NOT_FOUND, "No login found", WebException.getExceptionThrowable() ); 
     69                else if( !encryptedPassword.equals( account.getPassword() ) ) 
     70                    throw new WebException( WebException.WebCode.ERROR_PASSWORD, "Wrong password", WebException.getExceptionThrowable() ); 
     71                else 
     72                { 
     73                    request.getSession().setAttribute( "SES_ACCOUNT", account ); 
     74                    jSONUser.put( "name", account.getName() ); 
     75                    jSONUser.put( "role", account.getRole() ); 
     76                } 
    8077            } 
    81             catch( Exception e ) 
     78            catch( DigestException e ) 
    8279            { 
    83                 result.put( "errors", "login.error.failed" ); 
     80                throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "Error to encrypt password", WebException.getExceptionThrowable() ); 
     81            } 
     82            catch( NoSuchAlgorithmException e ) 
     83            { 
     84                throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "Error to encrypt password", WebException.getExceptionThrowable() ); 
     85            } 
     86            catch( ServiceException e ) 
     87            { 
     88                throw new WebException( WebException.WebCode.ERROR_LOGIN_NOT_FOUND, "Error no login found", WebException.getExceptionThrowable() ); 
    8489            } 
    8590        } 
     
    9297    @ControllerMethod(requestMandatory = true, jsonResult = true) 
    9398    public JSONObject logout( @NotNull final HttpServletRequest request ) 
    94             throws ServiceException 
     99            throws WebException 
    95100    { 
    96         request.getSession().setAttribute( "SES_USER", null ); 
     101        request.getSession().setAttribute( "SES_ACCOUNT", null ); 
    97102        request.getSession().invalidate(); 
    98103 
     
    100105    } 
    101106 
    102  
    103 //    @ControllerMethod(jsonResult = true) 
    104 //    public JSONObject createAccount( @NotNull @ParamName(ParameterConstants.PARAMETER_NAME) final String lastName, 
    105 //                                     @Nullable @ParamName(ParameterConstants.PARAMETER_FIRST_NAME) final String firstName, 
    106 //                                     @NotNull @ParamName(ParameterConstants.PARAMETER_EMAIL) final String email, 
    107 //                                     @NotNull @ParamName(ParameterConstants.PARAMETER_PWD) final String password, 
    108 //                                     @Nullable @ParamName(ParameterConstants.PARAMETER_LABORATORY) final String laboratory, 
    109 //                                     @Nullable @ParamName(ParameterConstants.PARAMETER_COUNTRY) final String country ) 
    110 //            throws ServiceException, WebException 
    111 //    { 
    112 //        try 
    113 //        { 
    114 //            final User existingUser = getTapasService().getUserByEmail( email ); 
    115 //            if( null == existingUser ) 
    116 //            { 
    117 //                final Date creationDate = new Date(); 
    118 // 
    119 //                final String encryptedPassword = EtherHelper.encryptPassword( password ); 
    120 //                final User user = new User( lastName, firstName, email, encryptedPassword, UserRole.USER, false, laboratory, country, creationDate ); 
    121 // 
    122 //                getTapasService().createUser( user ); 
    123 // 
    124 //                // Send email to administrator to inform there is a new account 
    125 //                sendEmailToAdministratorAndUser( user ); 
    126 //            } 
    127 //            else 
    128 //                throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User", WebException.getExceptionThrowable() ); 
    129 //        } 
    130 //        catch( DigestException e ) 
    131 //        { 
    132 //            throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" ); 
    133 //        } 
    134 //        catch( NoSuchAlgorithmException e ) 
    135 //        { 
    136 //            throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" ); 
    137 //        } 
    138 // 
    139 //        return new JSONObject(); 
    140 //    } 
    141  
    142     /** 
    143      * This method create and send an email to : 
    144      * - the administrator to inform there is a new created account 
    145      * - the user to inform his account is created 
    146      * 
    147      * @param user 
    148      * @throws WebException 
    149      */ 
    150     private void sendEmailToAdministratorAndUser( @NotNull final User user ) 
    151             throws WebException 
    152     { 
    153         try 
    154         { 
    155             final String host = getProperty( "mail.host" ); 
    156             final String webMaster = getProperty( "mail.webmaster" ); 
    157             final JavaMailSenderImpl sender = new JavaMailSenderImpl(); 
    158             sender.setHost( host ); 
    159  
    160             final MimeMessage message = sender.createMimeMessage(); 
    161             final MimeMessageHelper helper = new MimeMessageHelper( message ); 
    162  
    163             // Mail Admin 
    164             final String subjectAdmin = "[TAPAS] Nouveau compte utilisateur"; 
    165             final String contentAdmin = "Nouvelle création de compte : \n\n" + 
    166                     "   - Nom : " + user.getLastName() + '\n' + 
    167                     "   - Prénom : " + user.getFirstName() + '\n' + 
    168                     "   - Email : " + user.getEmail() + "\n\n" + 
    169                     "Le serveur de mail masqué"; 
    170  
    171             helper.setFrom( webMaster ); 
    172             helper.setTo( webMaster ); 
    173             helper.setSubject( subjectAdmin ); 
    174             helper.setText( contentAdmin ); 
    175             sender.send( message ); 
    176  
    177             // Mail User 
    178             final String subjectUser = "[TAPAS] New account"; 
    179             final String contentUser = "Dear " + user.getLastName() + "\n\n" + 
    180                     "Your account on TAPAS is now created. You can access to the website with your email as login and your password.\n\n" + 
    181                     "The TAPAS Administrator"; 
    182  
    183             helper.setFrom( webMaster ); 
    184             helper.setTo( user.getEmail() ); 
    185             helper.setSubject( subjectUser ); 
    186             helper.setText( contentUser ); 
    187             sender.send( message ); 
    188         } 
    189         catch( MessagingException e ) 
    190         { 
    191             throw new WebException( WebException.WebCode.ERROR_EMAIL_CANNOT_BE_SEND, "The email cannot be send to the TAPAS administrator or USER" ); 
    192         } 
    193     } 
    194  
    195 //    @ControllerMethod(downloadFile = DOWNLOAD_DATA_PROTOCOL_EN) 
    196 //    public void downloadFileDataProtocolEn() 
    197 //    { 
    198 //    } 
    199 // 
    200 //    @ControllerMethod(downloadFile = DOWNLOAD_DATA_PROTOCOL_FR) 
    201 //    public void downloadFileDataProtocolFr() 
    202 //    { 
    203 //    } 
    204 // 
    205107    private static final Log LOGGER = LogFactory.getLog( ControllerEponge.class ); 
    206  
    207108    private static final String VIEW_INIT = "init"; 
    208     private static final String VIEW_DATA_PROTOCOL_EN = "project/home_dataProtocol_en"; 
    209     // TODO : mettre les bons fichiers de Dataprotocol 
    210     private static final String DOWNLOAD_DATA_PROTOCOL_EN = "bib.txt"; 
    211     private static final String DOWNLOAD_DATA_PROTOCOL_FR = "bib.txt"; 
    212109} 
  • ether_statistics/web/src/com/ether/ControllerEther.java

    r574 r667  
    11package com.ether; 
    22 
     3import com.ether.account.Account; 
    34import com.ether.annotation.ControllerMethod; 
    45import com.ether.annotation.Mandatory; 
    56import com.ether.annotation.ParamName; 
    67import com.ether.annotation.UseJSON; 
    7 import com.ether.user.User; 
    88import net.sf.json.JSON; 
    99import net.sf.json.JSONArray; 
     
    113113            // Parse parameters 
    114114            final Object[] params = buildParams( methodDescription, request ); 
    115             final String defaultView = ( null != methodDescription.getDefaultView() && !"".equals( methodDescription.getDefaultView() ) ) ? methodDescription.getDefaultView() : methodDescription.getView(); 
    116  
    117115 
    118116            if( methodDescription.isRequestMandatory() ) 
    119117                params[params.length - 1] = request; //params = parametre de la methode du Controller 
    120118 
    121  
    122119            if( methodDescription.isLoginMandatory() ) 
    123120            { 
    124                 final User user = (User) request.getSession().getAttribute( "SES_USER" ); 
    125                 if( null == user ) 
    126                     return new ModelAndView( defaultView, "errors", "login.error.unknown" ); 
     121                final Account account = (Account) request.getSession().getAttribute( "SES_ACCOUNT" ); 
     122                if( null == account ) 
     123                { 
     124                    sendSerializedException( response, new WebException( WebException.WebCode.ERROR_LOGIN_NOT_FOUND, "No login found", WebException.getExceptionThrowable() ) ); 
     125                    return null; 
     126                } 
    127127            } 
    128128 
     
    135135//                    params[params.length - 1] = user; 
    136136//            } 
    137 // 
    138             if( methodDescription.isBackofficeMethod() ) 
    139             { 
    140                 final User user = (User) request.getSession().getAttribute( "SES_USER" ); 
    141                 if( null == user ) 
    142                 { 
    143                     return new ModelAndView( defaultView, "errors", "login.error.unknown" ); 
    144                 } 
    145                 else if( null != user && !user.isAccessToBO() ) 
    146                 { 
    147                     return new ModelAndView( defaultView, "errors", "login.error.bo.notAccepted" ); 
    148                 } 
    149             } 
    150137 
    151138            final Object result; 
     
    177164                return null; 
    178165            } 
    179 //            else if( null != methodDescription.getDownloadFile() && !"".equals( methodDescription.getDownloadFile() ) ) 
    180 //            { 
    181 //                final String fileName = methodDescription.getDownloadFile(); 
    182 //                final String downloadPath = getProperty( "downloadPath" ); 
    183 //                WebHelper.downloadFileToResponse( fileName, downloadPath, response ); 
    184 //                return null; 
    185 //            } 
    186166            else 
    187167            { 
     
    190170            } 
    191171        } 
    192         catch( Throwable e ) 
    193         { 
    194             throw new WebException( e ); 
     172        catch( IOException e ) 
     173        { 
     174            throw new WebException( WebException.WebCode.IO_EXCEPTION_ERROR, e ); 
    195175        } 
    196176    } 
  • ether_statistics/web/src/com/ether/ControllerStatistics.java

    r657 r667  
    3030            throws ServiceException 
    3131    { 
    32         return new ModelAndView( VIEW_ERRORS ); 
     32        return new ModelAndView( VIEW_INIT ); 
    3333    } 
    3434 
     
    3737            throws ServiceException 
    3838    { 
    39 //        final Calendar cal = Calendar.getInstance(); 
    40 //        final Date today = cal.getTime(); 
    41 //        cal.set( 1900, Calendar.JANUARY, 1 ); 
    42 //        final Date begin = cal.getTime(); 
    43 //        cal.set( Calendar.DST_OFFSET, 40001 ); 
    44 //        final Date bob = cal.getTime(); 
    4539        return new HashMap<String, Object>(); 
    4640    } 
     
    5650     * @throws ServiceException 
    5751     */ 
    58     @ControllerMethod(jsonResult = true) 
     52    @ControllerMethod(jsonResult = true, loginMandatory = true) 
    5953    public JSONObject searchMainStatisticsByProject( @Mandatory @ParamName(ParameterConstants.PARAMETER_NAME) final String projectName ) 
    6054            throws ServiceException 
     
    7064    private static final Log LOGGER = LogFactory.getLog( ControllerStatistics.class ); 
    7165 
     66    private static final String VIEW_INIT = "init"; 
    7267    private static final String VIEW_STATISTICS = "project/statistics"; 
    73     private static final String VIEW_VISUALIZATION_PARAMETER_BY_PLATEFORM = "visualization/visu_parameter_by_pf"; 
    74     private static final String VIEW_DOWNLOAD_OK = "data/access/extract3"; 
    75     private static final String VIEW_WORK = "project/inWork"; 
    76     public static final String VIEW_ERRORS = "project/errors"; 
    77  
    78     private static final String FORMAT_DEFAULT = "NASA-AMES"; 
    79     private static final String COMPRESSION_DEFAULT = "None"; 
    8068} 
  • ether_statistics/web/src/com/ether/WebException.java

    r574 r667  
    4141        ERROR_NO_REQUEST_HANDLING_METHOD, 
    4242        ERROR_NUMBER_OF_PARAM_TYPES_NOT_EQUAL_TO_PARAM_ANNOTATIONS, 
    43         USER_ALREADY_EXISTS, 
    4443        ERROR_ENCRYPT_PASSWORD, 
    45         ERROR_EMAIL_CANNOT_BE_SEND, 
    46         ERROR_XML_CREATION, 
    47         ERROR_NO_OBSERVATORY_FOUND, 
    48         ERROR_NO_USER_FOUND, 
     44        ERROR_PASSWORD, 
     45        ERROR_LOGIN_NOT_FOUND, 
    4946        ERROR_TO_READ_FILE_PROPERTIES, 
    50         ERROR_TO_REMOVE_USER, 
    51         ERROR_USERS_CREATION 
     47        IO_EXCEPTION_ERROR 
    5248    } 
    5349 
  • ether_statistics/web/src/com/ether/WebHelper.java

    r587 r667  
    22 
    33import com.ether.WebException.WebCode; 
    4 import com.ether.user.User; 
     4import com.ether.account.Account; 
    55import net.sf.json.JSONObject; 
    66import org.apache.commons.logging.Log; 
     
    8686        final JSONObject jSONPeople = new JSONObject(); 
    8787 
    88         final User user = (User) request.getSession().getAttribute( "SES_USER" ); 
    89         if( null == user ) 
     88        final Account account = (Account) request.getSession().getAttribute( "SES_ACCOUNT" ); 
     89        if( null == account ) 
    9090            return null; 
    9191 
    92         jSONPeople.put( "name", user.getLastName() ); 
    93         jSONPeople.put( "firstName", user.getFirstName() ); 
    94         jSONPeople.put( "role", user.getRole() ); 
     92        jSONPeople.put( "name", account.getName() ); 
     93        jSONPeople.put( "role", account.getRole() ); 
    9594        return jSONPeople; 
    9695    } 
Note: See TracChangeset for help on using the changeset viewer.