Chris,

Try something like this:

package edu.lsu.sso.cas.web.flow;

import org.inspektr.common.ioc.annotation.NotNull;
import org.jasig.cas.ticket.TicketGrantingTicket;
import org.jasig.cas.ticket.registry.TicketRegistry;
import org.jasig.cas.web.support.WebUtils;
import org.springframework.webflow.action.AbstractAction;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;

/**
 * Sample Spring Web Flow action that will extract the user principal
information and
 * store it within the flow scope for Chris Whittle of J.B. Hunt.
 *
 * @author Andrew Feller <[email protected]>
 */
public class PrincipalExtractorAction extends AbstractAction {

    /** TicketRegistry for storing and retrieving tickets as needed. */
    @NotNull
    private TicketRegistry ticketRegistry;

    @Override
    protected Event doExecute(RequestContext context) throws Exception {

        String tgtId = WebUtils.getTicketGrantingTicketId(context);

        // Throw an exception if the TGT wasn't put into the flow or request
scope 
        if (tgtId == null) {
            logger.warn("Mising TGT in flow scope and cannot continue");
            throw new RuntimeException("Missing TGT in flow scope and cannot
continue");
        }

        final TicketGrantingTicket tgt = (TicketGrantingTicket)
this.ticketRegistry.getTicket(tgtId, TicketGrantingTicket.class);

        // Throw an exception if the TGT doesn't exist within the ticket
registry
        if (tgt == null) {
            logger.warn("Invalid TGT in flow scope and cannot continue");
            throw new RuntimeException("Invalid TGT in flow scope and cannot
continue");
        }

        // Put the user principal into the flow scope or wherever you desire
        context.getFlowScope().put("principal",
tgt.getAuthentication().getPrincipal().getId());

        return success();
    }

    /**
     * Method to set the TicketRegistry.
     * 
     * @param ticketRegistry the TicketRegistry to set.
     */
    public void setTicketRegistry(TicketRegistry ticketRegistry) {
        this.ticketRegistry = ticketRegistry;
    }
}


On 7/19/09 4:59 PM, "[email protected]" <[email protected]>
wrote:

> Is there anyway to get the principal?

-- 
Andrew Feller, Business System Programmer
LSU University Information Services
200 Frey Computing Services Center
Baton Rouge, LA 70803
Office: 225.578.3737
Fax: 225.578.6400



-- 
You are currently subscribed to [email protected] as: 
[email protected]
To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user

Reply via email to