Skip to content

Commit

Permalink
Merge pull request #14 from daedafusion/mark/anonymous_subjects
Browse files Browse the repository at this point in the history
Anonymous Subject Support
  • Loading branch information
markphilpot committed Dec 13, 2019
2 parents 6da1882 + aa8f430 commit b7a8ca2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.daedafusion.sf.AbstractService;
import com.daedafusion.security.authentication.providers.TokenExchangeProvider;
import com.daedafusion.sf.LifecycleListener;
import org.apache.log4j.Logger;

import java.util.*;
Expand All @@ -18,22 +19,22 @@ public class TokenExchangeImpl extends AbstractService<TokenExchangeProvider> im
@Override
public Subject exchange(Token... tokens)
{
Set<AuthenticatedPrincipal> aps = getAPs(Arrays.stream(tokens));
return exchange(Arrays.asList(tokens));
}

if(!aps.isEmpty())
@Override
public Subject exchange(List<Token> tokens)
{
Set<AuthenticatedPrincipal> aps;

if(tokens.size() == 0)
{
return new Subject(aps);
aps = getAnonymousAPs();
}
else
{
return null;
aps = getAPs(tokens.stream());
}
}

@Override
public Subject exchange(List<Token> tokens)
{
Set<AuthenticatedPrincipal> aps = getAPs(tokens.stream());

if(!aps.isEmpty())
{
Expand All @@ -48,11 +49,22 @@ public Subject exchange(List<Token> tokens)
private Set<AuthenticatedPrincipal> getAPs(Stream<Token> tokens)
{
return tokens
.flatMap(token -> getProviders().stream().flatMap(tep -> tep.exchange(token).stream()))
.flatMap(token -> getProviders().stream()
.filter(ap -> !ap.supportsAnonymous())
.flatMap(tep -> tep.exchange(token).stream()))
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}

private Set<AuthenticatedPrincipal> getAnonymousAPs()
{
return getProviders().stream()
.filter(TokenExchangeProvider::supportsAnonymous)
.flatMap(tep -> tep.exchange(() -> "anonymous").stream())
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}

@Override
public List<Token> exchange(Subject subject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public interface TokenExchangeProvider extends Provider
* @return true if token was destroyed and/or rendered invalid, false otherwise. Null if token wasn't valid
*/
Boolean destroyToken(Token token);

boolean supportsAnonymous();
}

0 comments on commit b7a8ca2

Please sign in to comment.