VL Web(LANSA for the Web) :Current JOB changed other user ID

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
User avatar
Take4
Posts: 3
Joined: Thu Feb 16, 2017 7:04 pm

VL Web(LANSA for the Web) :Current JOB changed other user ID

Post by Take4 » Tue Oct 31, 2017 5:49 pm

I want to change user LWEB_JOB used by SRVROUTINE.
The application LOGIN process i IBM user ID and password is entered. This user ID you want to change the job.
LANSA for the Web can, so I think the API is missing.
API for checking user and password is found. It is a QSYGETPH.

Who knows the name of the API to change the job, please tell me.
If you have the sample more happy.
| | -- Take4 --
V -- LANSA Japan --

MarkD
Posts: 606
Joined: Wed Dec 02, 2015 9:56 am

Re: VL Web(LANSA for the Web) :Current JOB changed other user ID

Post by MarkD » Thu Nov 02, 2017 9:32 am

I think this little CL program might have what you need.
It validates a user profile and password using IBM supplied API QSYGETPH.
It optionally changes the current job to run under that user profile using IBM supplied API QWTSETP.
Changing an IBM i to run under a profile does not change some things such as the library list - see IBM documentation.

Code: Select all

PGM        PARM(&USERPROF &PASSWORD &CHANGEJOB &RETCODE &ERRORMSG)                     
                                                                                                    
   /********************************************************/                                       
   /* Check that the passed User Id and Password are valid */                                       
   /* Status Codes Returned :                              */                                       
   /* OK = USER OK                                         */                                       
   /* IU = INVALID USER ID                                 */                                       
   /* IP = INVALID PASSWORD                                */                                       
   /* EX = PASSWORD EXPIRED                                */                                       
   /* UD = USER PROFILE DISABLED                           */                                       
   /* ER = UNEXPECTED ERROR                                */                                       
   /********************************************************/                                       
                                                                                                    
   /* Received Parms */                                                                             
             DCL        VAR(&USERPROF) TYPE(*CHAR) LEN(10)                                          
             DCL        VAR(&PASSWORD) TYPE(*CHAR) LEN(128)                                         
             DCL        VAR(&CHANGEJOB) TYPE(*CHAR) LEN(1)                                          
                                                                                                    
   /* Returned Parms */                                                                             
             DCL        VAR(&RETCODE) TYPE(*CHAR) LEN(2)                                            
             DCL        VAR(&ERRORMSG) TYPE(*CHAR) LEN(132) 

   /* Local Variables */                                          
             DCL        VAR(&HANDLE) TYPE(*CHAR) LEN(12)                                            
             DCL        VAR(&RTNVAR) TYPE(*CHAR) LEN(8) VALUE(X'0000000000000000')                  
                                                                                                    
   /* Check User and Password for OS/400 V5R3 onwards */                                            
             CALL       PGM(QSYGETPH) PARM(&USERPROF &PASSWORD &HANDLE &RTNVAR X'00000080' +        
                          X'00000000')                                                              
                                                                                                    
   /* Invalid User                                             */                                   
             MONMSG     MSGID(CPF2203 CPF2204) EXEC(DO)                                             
                CHGVAR     VAR(&RETCODE) VALUE('IU')                                                
                CHGVAR     VAR(&ERRORMSG) VALUE('Invalid or unknown user profile.')                 
                GOTO       CMDLBL(END)                                                              
             ENDDO                                                                                  
                                                                                                    
   /* Unable to check this user                               */                                    
             MONMSG     MSGID(CPF22E9 CPF2213 CPF2217 CPF4AB8) EXEC(DO)                             
                CHGVAR     VAR(&RETCODE) VALUE('UV')                                                
                CHGVAR     VAR(&ERRORMSG) VALUE('Unable to access user profile details.')           
                GOTO       CMDLBL(END)                                                              
             ENDDO                                                                                  
                                                                                                    
   /* Password is invalid */                                                                        
             MONMSG     MSGID(CPF22E2) EXEC(DO)                                                     
                CHGVAR     VAR(&RETCODE) VALUE('IP')                                                
                CHGVAR     VAR(&ERRORMSG) VALUE('Invalid password.')                                
                GOTO       CMDLBL(END)                                                              
             ENDDO                                                                                  
                                                                                                    
   /* This profile has no password */                                                               
             MONMSG     MSGID(CPF22E5) EXEC(DO)                                                     
                CHGVAR     VAR(&RETCODE) VALUE('NO')                                                
                CHGVAR     VAR(&ERRORMSG) VALUE('No Password exists for this user.')                
                GOTO       CMDLBL(END)                                                              
             ENDDO                                                                                  
                                                                                                    
   /* Profile is disabled */                                                                        
             MONMSG     MSGID(CPF22E3) EXEC(DO)                                                     
                CHGVAR     VAR(&RETCODE) VALUE('UD')                                                
                CHGVAR     VAR(&ERRORMSG) VALUE('User Profile is disabled.')                        
                GOTO       CMDLBL(END)                                                              
             ENDDO                                                                                  
                                                                                                    
   /* Password has expired */                                                                       
             MONMSG     MSGID(CPF22E4) EXEC(DO)                                                     
                CHGVAR     VAR(&RETCODE) VALUE('EX')                                                
                CHGVAR     VAR(&ERRORMSG) VALUE('The password has expired.')                        
                GOTO       CMDLBL(END)                                                              
             ENDDO                                                                                  
                                                                                                    
   /* Unspecified error */                                                                          
             MONMSG     MSGID(MCH0000 CPF0000) EXEC(DO)                                             
                CHGVAR     VAR(&RETCODE) VALUE('ER')                                                
                CHGVAR     VAR(&ERRORMSG) VALUE('No error message available')                       
                RCVMSG     MSG(&ERRORMSG)                                                           
                MONMSG     MSGID(MCH0000 CPF0000)                                                   
                GOTO       CMDLBL(END)                                                              
             ENDDO                                                                                  
                                                                                                    
                                                                                                    
   /*    No error so far so swap job to be that user      */                                        
                            
                                                                                                    
             IF         COND(&CHANGEJOB = 'Y') THEN(DO)                                             
                                                                                                    
                CHGVAR     VAR(&RTNVAR) VALUE(X'0000000000000000')                                  
                                                                                                    
                CALL       PGM(QWTSETP) PARM(&HANDLE &RTNVAR)                                       
                                                                                                    
                MONMSG     MSGID(MCH0000 CPF0000) EXEC(DO)                                          
                   CHGVAR     VAR(&RETCODE) VALUE('ER')                                             
                   CHGVAR     VAR(&ERRORMSG) VALUE('No error message available')                    
                   RCVMSG     MSG(&ERRORMSG)                                                        
                   MONMSG     MSGID(MCH0000 CPF0000)                                                
                   GOTO       CMDLBL(END)                                                           
                ENDDO                                                                               
                                                                                                    
             ENDDO                                                                                  
                                                                                                    
   /* No error at all if we reach this point in the code */                                         
                                                                                                    
             CHGVAR     VAR(&RETCODE)  VALUE('OK')                                                  
             CHGVAR     VAR(&ERRORMSG) VALUE(' ')                                                   
                                                                                                    
   /* End the program */                                                                            
                                                                                                    
END:         ENDPGM

MarkD
Posts: 606
Joined: Wed Dec 02, 2015 9:56 am

Re: VL Web(LANSA for the Web) :Current JOB changed other user ID

Post by MarkD » Thu Nov 02, 2017 9:42 am

Also, remember that L4Web jobs are inherently stateless.

This means that a sequence of L4Web requests made by a single browser client session may get routed into different L4Web jobs on the IBM i server at different times. Also, requests from other browser clients may get routed into the L4Web job that you were assigned a few milliseconds ago.

So you have to check and possibly change the L4Web job's user on every single interaction with a client - not just at logon time.

The trap here is that during development and testing (light loads) your client browser requests may keep getting assigned to the same L4Web job.

If you had assumed that a client browser's request will always get routed into the same L4Web job then your design error may not show up until the system is under load.

AbelS
Posts: 24
Joined: Wed Nov 16, 2016 1:43 pm
Location: Sydney, Australia
Contact:

Re: VL Web(LANSA for the Web) :Current JOB changed other user ID

Post by AbelS » Thu Nov 02, 2017 2:47 pm

Some important warnings/caveats if you change user profiles yourself within a running web job:

1. Any tables already opened won't be rechecked for authority
2. LANSA won't be aware of the user profile change (LANSA authority checks)
3. If the user profile has a different CCSID, results may be unpredictable (Don't use in these cases!)
4. You need to restore the original user profile when you are done (best done at the earliest possible opportunity, to avoid application errors bypassing this step)
5. It might work in limited cases, but it would be your responsibility

HTH

KevinW
Posts: 28
Joined: Thu May 26, 2016 11:18 am

Re: VL Web(LANSA for the Web) :Current JOB changed other user ID

Post by KevinW » Thu Nov 02, 2017 3:12 pm

Also, using the CL program as is entails a profile handle leak, and may cause an out of user handles error condition if it is called often enough in the one job (20000?). It needs to release the profile handle after using it.

User avatar
Take4
Posts: 3
Joined: Thu Feb 16, 2017 7:04 pm

Re: VL Web(LANSA for the Web) :Current JOB changed other user ID

Post by Take4 » Thu Nov 09, 2017 4:48 pm

I thank you, one and all!

I was able to do it.
I thank for much advice.
| | -- Take4 --
V -- LANSA Japan --

caseywhite
Posts: 98
Joined: Thu May 26, 2016 1:17 am

Re: VL Web(LANSA for the Web) :Current JOB changed other user ID

Post by caseywhite » Sat Dec 08, 2018 7:39 am

I know this thread is old but thought I would check in since this is something I want to do as well. Since you need the user and password, my assumption is that you will have cached the password of the user at the time of logon as a persistent variable on the server because you are going to need it each time you make a call to the QSYGETPH API. Is that the method you used?

MarkD
Posts: 606
Joined: Wed Dec 02, 2015 9:56 am

Re: VL Web(LANSA for the Web) :Current JOB changed other user ID

Post by MarkD » Mon Dec 10, 2018 9:19 am

Yes, you would need to.

This is the simple model that VLF applications us for doing this.
I think it could be reused in any VL-Web application unchanged ……………..


Every server module is defined with a set of persistent strings that contain the logged on user, password, required library list, etc. These are set as the user logs on and persist on the server for the duration of the session. There are shipped examples about this and generated code will create them.


There is an associated singleton “server-side manager” VL reusable part with InitalizeServerRoutine and TerminateServerRoutine methods. The InitalizeServerRoutine is passed all the persistent user details.


Every server module in an application declares the persistent strings and server-side manager. It invokes InitalizeServerRoutine at the start of every SRVROUTINE and TerminateServerRoutine at its completion.


This allows InitalizeServerRoutine to know the details of the logged-on user and to adjust the job and library list accordingly. Additionally, it can be optimized to not change the job’s user if it’s already correct, ditto for library list.

caseywhite
Posts: 98
Joined: Thu May 26, 2016 1:17 am

Re: VL Web(LANSA for the Web) :Current JOB changed other user ID

Post by caseywhite » Tue Dec 11, 2018 5:11 am

Thanks.

Post Reply