This repository has been archived by the owner on Nov 3, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for clearpass caching and MFA
- Loading branch information
1 parent
6070364
commit 3041d41
Showing
4 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
34 changes: 32 additions & 2 deletions
34
cas-mfa-duo/src/main/groovy/net/unicon/cas/mfa/authentication/duo/DuoCredentials.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
package net.unicon.cas.mfa.authentication.duo | ||
|
||
import org.jasig.cas.authentication.principal.UsernamePasswordCredentials | ||
import org.jasig.cas.authentication.principal.Credentials | ||
|
||
class DuoCredentials extends UsernamePasswordCredentials { | ||
class DuoCredentials implements Credentials { | ||
|
||
String username | ||
String signedDuoResponse | ||
|
||
@Override | ||
String toString() { | ||
return "[username: " + this.username + "]" | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false | ||
} | ||
|
||
final DuoCredentials that = (DuoCredentials) o; | ||
if (username != null ? !username.equals(that.username) : that.username != null) { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
@Override | ||
int hashCode() { | ||
username != null ? username.hashCode() : 0; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...rc/main/groovy/net/unicon/cas/mfa/authentication/duo/DuoMultiFactorWebflowConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package net.unicon.cas.mfa.authentication.duo; | ||
|
||
import org.jasig.cas.authentication.principal.AbstractPersonDirectoryCredentialsToPrincipalResolver; | ||
import org.jasig.cas.authentication.principal.Credentials; | ||
import org.jasig.cas.authentication.principal.CredentialsToPrincipalResolver; | ||
import org.jasig.cas.authentication.principal.Principal; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.List; | ||
|
||
/** | ||
* Initialize the application context with the needed webflow mfa configuration | ||
* as much as possible to simplify adding mfa into an existing overlay. | ||
* | ||
* @author Misagh Moayyed | ||
*/ | ||
@Component | ||
public class DuoMultiFactorWebflowConfigurer implements InitializingBean { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(DuoMultiFactorWebflowConfigurer.class); | ||
|
||
@Autowired | ||
private WebApplicationContext context; | ||
|
||
|
||
@PostConstruct | ||
public void afterPropertiesSet() throws Exception { | ||
try { | ||
final List resolvers = this.context.getBean("mfaCredentialsToPrincipalResolvers", List.class); | ||
resolvers.add(new DuoCredentialsToPrincipalResolver()); | ||
} catch (final Exception e) { | ||
LOGGER.error(e.getMessage(), e); | ||
} | ||
} | ||
|
||
private class DuoCredentialsToPrincipalResolver extends AbstractPersonDirectoryCredentialsToPrincipalResolver { | ||
|
||
@Override | ||
protected String extractPrincipalId(final Credentials credentials) { | ||
final DuoCredentials duoCredentials = (DuoCredentials) credentials; | ||
return duoCredentials.getUsername(); | ||
} | ||
|
||
@Override | ||
public boolean supports(final Credentials credentials) { | ||
return credentials != null && credentials instanceof DuoCredentials; | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...a/net/unicon/cas/mfa/authentication/principal/ChainingCredentialsToPrincipalResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.unicon.cas.mfa.authentication.principal; | ||
|
||
import org.jasig.cas.authentication.principal.Credentials; | ||
import org.jasig.cas.authentication.principal.CredentialsToPrincipalResolver; | ||
import org.jasig.cas.authentication.principal.Principal; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
/** | ||
* This is {@link ChainingCredentialsToPrincipalResolver} that chains a number of | ||
* principal resolvers together. | ||
* | ||
* @author Misagh Moayyed | ||
*/ | ||
public final class ChainingCredentialsToPrincipalResolver implements CredentialsToPrincipalResolver { | ||
private List<CredentialsToPrincipalResolver> chain; | ||
|
||
@Override | ||
public Principal resolvePrincipal(final Credentials credentials) { | ||
final Iterator<CredentialsToPrincipalResolver> it = this.chain.iterator(); | ||
while (it.hasNext()) { | ||
final CredentialsToPrincipalResolver resolver = it.next(); | ||
if (resolver.supports(credentials)) { | ||
final Principal p = resolver.resolvePrincipal(credentials); | ||
if (p != null) { | ||
return p; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean supports(final Credentials credentials) { | ||
return true; | ||
} | ||
|
||
public void setChain(final List<CredentialsToPrincipalResolver> chain) { | ||
this.chain = chain; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters