Friday, June 10, 2011

LTPAToken from the credential vault (JaasSubjectCredential)

Retrieve the token from the credential vault (JaasSubjectCredential) and build up the http connection from that credential.

JaasSubjectCredential cred = null;
        try {
        cred = getLTPAToken(request);
        } catch (PortletServiceUnavailableException e) {
        e.printStackTrace();
        } catch (NamingException e) {
        e.printStackTrace();
        } catch (CredentialVaultException e) {
        e.printStackTrace();
        }
        URLConnection docConnection = cred.getAuthenticatedConnection(new URL("<inputURL>"));



 private JaasSubjectCredential getLTPAToken(PortletRequest request) throws NamingException, CredentialVaultException,
        PortletServiceUnavailableException {
    Context ctx = new InitialContext();
    PortletServiceHome cvHome = (PortletServiceHome) ctx
        .lookup("portletservice/com.ibm.portal.portlet.service.credentialvault.CredentialVaultService");
    CredentialVaultService cvService = (CredentialVaultService) cvHome.getPortletService(CredentialVaultService.class);
    JaasSubjectCredential credential = null;
    try {
        credential = (JaasSubjectCredential) cvService.getCredential(CredentialVaultService.PREDEFINED_SLOT_USER_JAAS_SUBJECT,
            CredentialTypes.LTPA_TOKEN, new HashMap(), request);
    } catch (CredentialVaultException e) {
        e.printStackTrace();
    }
    return credential;
    }

No comments:

Post a Comment