Search in sources :

Example 11 with ISecurityContext

use of org.apereo.portal.security.ISecurityContext in project uPortal by Jasig.

the class CachedPasswordUserInfoService method getPassword.

/**
     * Retrieves the users password by iterating over the user's security contexts and returning the
     * first available cached password.
     *
     * @param baseContext The security context to start looking for a password from.
     * @return the users password
     */
private String getPassword(ISecurityContext baseContext) {
    String password = null;
    IOpaqueCredentials oc = baseContext.getOpaqueCredentials();
    if (oc instanceof NotSoOpaqueCredentials) {
        NotSoOpaqueCredentials nsoc = (NotSoOpaqueCredentials) oc;
        password = nsoc.getCredentials();
    }
    // If still no password, loop through subcontexts to find cached credentials
    Enumeration en = baseContext.getSubContexts();
    while (password == null && en.hasMoreElements()) {
        ISecurityContext subContext = (ISecurityContext) en.nextElement();
        password = this.getPassword(subContext);
    }
    return password;
}
Also used : Enumeration(java.util.Enumeration) IOpaqueCredentials(org.apereo.portal.security.IOpaqueCredentials) ISecurityContext(org.apereo.portal.security.ISecurityContext) NotSoOpaqueCredentials(org.apereo.portal.security.provider.NotSoOpaqueCredentials)

Example 12 with ISecurityContext

use of org.apereo.portal.security.ISecurityContext in project uPortal by Jasig.

the class UnionSecurityContext method authenticate.

public synchronized void authenticate() throws PortalSecurityException {
    // lets chaining invoke authentication on all subcontexts
    // then sets resulting principal, descriptor and isauth based on
    // first authenticated context.
    super.authenticate();
    Enumeration e = getSubContexts();
    while (e.hasMoreElements()) {
        ISecurityContext subCtx = (ISecurityContext) e.nextElement();
        if (subCtx.isAuthenticated()) {
            this.myPrincipal = new ChainingPrincipal(subCtx.getPrincipal());
            this.myAdditionalDescriptor = subCtx.getAdditionalDescriptor();
            this.isauth = true;
            break;
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ISecurityContext(org.apereo.portal.security.ISecurityContext)

Example 13 with ISecurityContext

use of org.apereo.portal.security.ISecurityContext in project uPortal by Jasig.

the class ChainingSecurityContext method authenticate.

/**
     * We walk the chain of subcontexts assigning principals and opaqueCredentials from the parent.
     * Note that the contexts themselves should resist actually performing the assignment if an
     * assignment has already been made to either the credentials or the UID.
     */
public synchronized void authenticate() throws PortalSecurityException {
    int i;
    Enumeration e = mySubContexts.elements();
    while (e.hasMoreElements()) {
        ISecurityContext sctx = ((Entry) e.nextElement()).getCtx();
        // The principal and credential are now set for all subcontexts in Authentication
        try {
            if (sctx instanceof IParentAwareSecurityContext) {
                ((IParentAwareSecurityContext) sctx).authenticate(this);
            } else {
                sctx.authenticate();
            }
        } catch (Exception ex) {
            log.error("Exception authenticating subcontext " + sctx, ex);
        }
        // Stop attempting to authenticate if authenticated and if the property flag is set
        if (stopWhenAuthenticated && sctx.isAuthenticated()) {
            break;
        }
    }
    // Zero out the actual credentials if it isn't already null
    if (this.myOpaqueCredentials.credentialstring != null) {
        for (i = 0; i < this.myOpaqueCredentials.credentialstring.length; i++) this.myOpaqueCredentials.credentialstring[i] = 0;
        myOpaqueCredentials.credentialstring = null;
    }
    return;
}
Also used : Enumeration(java.util.Enumeration) IParentAwareSecurityContext(org.apereo.portal.security.IParentAwareSecurityContext) ISecurityContext(org.apereo.portal.security.ISecurityContext) PortalSecurityException(org.apereo.portal.security.PortalSecurityException)

Example 14 with ISecurityContext

use of org.apereo.portal.security.ISecurityContext in project uPortal by Jasig.

the class Authentication method configureSecurityContextChain.

/**
     * Recurse through the {@link ISecurityContext} chain, setting the credentials for each. TODO
     * This functionality should be moved into the {@link
     * org.apereo.portal.security.provider.ChainingSecurityContext}.
     *
     * @param principals
     * @param credentials
     * @param person
     * @param securityContext
     * @param baseContextName
     * @throws PortalSecurityException
     */
private void configureSecurityContextChain(final Map<String, String> principals, final Map<String, String> credentials, final IPerson person, final ISecurityContext securityContext, final String baseContextName) throws PortalSecurityException {
    this.setContextParameters(principals, credentials, baseContextName, securityContext, person);
    // load principals and credentials for the subContexts
    for (final Enumeration<String> subCtxNames = securityContext.getSubContextNames(); subCtxNames.hasMoreElements(); ) {
        final String fullSubCtxName = subCtxNames.nextElement();
        //Strip off the base of the name
        String localSubCtxName = fullSubCtxName;
        if (fullSubCtxName.startsWith(baseContextName + ".")) {
            localSubCtxName = localSubCtxName.substring(baseContextName.length() + 1);
        }
        final ISecurityContext sc = securityContext.getSubContext(localSubCtxName);
        this.configureSecurityContextChain(principals, credentials, person, sc, fullSubCtxName);
    }
}
Also used : ISecurityContext(org.apereo.portal.security.ISecurityContext)

Aggregations

ISecurityContext (org.apereo.portal.security.ISecurityContext)14 IPerson (org.apereo.portal.security.IPerson)8 Enumeration (java.util.Enumeration)5 PortalSecurityException (org.apereo.portal.security.PortalSecurityException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 IUserInstance (org.apereo.portal.user.IUserInstance)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 AuthorizationException (org.apereo.portal.AuthorizationException)1 PortalException (org.apereo.portal.PortalException)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IAdditionalDescriptor (org.apereo.portal.security.IAdditionalDescriptor)1 IOpaqueCredentials (org.apereo.portal.security.IOpaqueCredentials)1