Using jsf to get SSO Ltpa-token exception - The internal portletrequest cannot be found. - Websphere

This is a discussion on Using jsf to get SSO Ltpa-token exception - The internal portletrequest cannot be found. - Websphere ; Hi all, Using Portal v.6.0.0.1. Normally when you want a portlet to access a ltpatoken from the credential vault, you can use the following stubcode (mind you, this is just an example-code): import javax.naming.Context; import javax.naming.InitialContext; import com.ibm.wps.sso.LTPATokenCredential; import com.ibm.portal.portlet.service.credentialvault.Cre ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Using jsf to get SSO Ltpa-token exception - The internal portletrequest cannot be found.

  1. Using jsf to get SSO Ltpa-token exception - The internal portletrequest cannot be found.

    Hi all,

    Using Portal v.6.0.0.1.

    Normally when you want a portlet to access a ltpatoken from the credential vault, you can use the following stubcode (mind you, this is just an example-code):

    import javax.naming.Context;
    import javax.naming.InitialContext;
    import com.ibm.wps.sso.LTPATokenCredential;
    import com.ibm.portal.portlet.service.credentialvault.Cre dentialVaultService;
    import com.ibm.portal.portlet.service.PortletServiceHome;

    ....
    getLTPAToken(PortletRequest request) {
    Context ctx = new InitialContext();
    PortletServiceHome cvHome = (PortletServiceHome)ctx.lookup("portletservice/com.ibm.portal.portlet.service.credentialvault.Cre dentialVaultService");
    CredentialVaultService cvService = (CredentialVaultService)cvHome.getPortletService(C redentialVaultService.class);
    Subject sub = cvService.getUserSubject(request);
    if (sub != null) {
    Iterator privKey=sub.getPrivateCredentials(LTPATokenCredent ial.class).iterator();
    LTPATokenCredential token = null;
    if(privKey.hasNext()) {
    return (LTPATokenCredential) privKey.next();
    }
    }
    return null;
    }


    If you would've configured SSO, the returned class contains a Ltpa-key.
    And it does, but not when using jsf. Since the request are not adressable directly you use the FacesContext to get the PortletRequest - PortletRequest request = (PortletRequest) FacesContext.getCurrentInstance().getExternalConte xt().getRequest();

    But using this to get the PortletRequest throws a IllegalStateException - The internal portlet request cannot be found. (pointing to "Subject sub = cvService.getUserSubject(request);")


    So what am I doing wrong? Is there a "feature" i miss in the jsf-spec?

    Thanks in advance,
    /Jonas V

  2. Re: Using jsf to get SSO Ltpa-token exception - The internalportlet request cannot be found.

    I assume the project was created with RAD7 and uses jsf-portletbridge.jar? If so, then the problem is due to the fact the jsf-portlet bridge wraps with request object and thus it stops being "internal portlet request" that one of the methods you are using apparently requires. To get to the orifinal request object you can use:
    Code:
    PortletRequest request = (PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    PorletRequest internalRequest = request.getPortletRequest();

  3. Re: Using jsf to get SSO Ltpa-token exception - The internalportlet request cannot be found.

    I suppose you mean:

    PortletRequestWrapper requestWrapper = (PortletRequestWrapper) FacesContext.getCurrentInstance().getExternalConte xt().getRequest();
    PortletRequest request = requestWrapper.getPortletRequest();

    And yes, it worked! Thank you, you really saved me on this one.
    If I had bothered to check the outgoing class from getExternalContext().getRequest(), then I would've seen that the request was wrapped to com.ibm.faces.portlet.httpbridge.RenderRequestWrap per.
    I just checked whether it was an ActionRequest or not (instance of...). *duh*


    /Jonas V

+ Reply to Thread