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;
}
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;
}
}
}
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;
}
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);
}
}
Aggregations