Posted: 26 Aug 2019 14:17 EDT Last activity: 27 Aug 2019 9:44 EDT
How do I set a user identifier using Java in Pega?
I'm working on setting up SSO in Pega. I think I'm making some progress, but I've run into an issue I don't know how to resolve. We use an API Gateway to authenticate a user and a cookie is set containing the user's ID. I can get this ID from the cookie using Java in my authentication activity, however, I can't set the .pyUserIdentifier parameter. I'm trying to use the following code:
Just as an FYI, I grabbed this from some generated Java code from when this value was being defaulted using an Obj-Open method. However, in this case, I get an NPE because myStepPage is null.
Is there a better way for me to set the ID of the current user so that when a user connects to the system they are automatically logged in? Or, is there a way I can make sure that myStepPage is not null, such as defaulting to a reasonable value?
Do you have a model operator? If yes, you can do an obj-open and retrieve the model operator on a page, say, Operator. Read the cookie containing the User ID and set pyUserIdentifier on Operator page with the cookie value. You are basically replacing the model operator's pyUserIdentifier with the cookie value. Set Param.pyOperPage to the Operator page in your authentication activity. Check OOTB activities IACAuthentication and IACAuthVerification for how to do this.
Looks like you're using PRCustom style authentication. A OTB servlet would be /PRCustom using authservice of CustomSample.
With this type of authentication your goal is to return a Clipboard page of class Data-Admin-Operator-ID. The Authentication activity is called with parameters and you return parameters for error handling or success. The pyOperPage parameter is of type Java and is expecting the Clipboard page of the user you want to login: pram.pyOperPage = @Java(myStepPage)
You can also look at activities Code-Security.AuthenticationLDAP and Code-Security.AuthenticationLDAPVerifyCredentials for examples.