@Test public void testMergeNoAuthSchemePrivate() { Client c = new Client(); c.setId(IdUtil.next()); c.setClientSecret("secret"); O2Principal p1 = new O2Principal(c); O2Principal p2 = new O2Principal(); O2Principal merged = p1.merge(p2); assertEquals(p1, merged); assertNotSame(p1, merged); }
public O2Principal merge(final Principal newPrincipal) { O2Principal principal = safeCast(newPrincipal, O2Principal.class) .orElse(null); if (isNull(principal)) { return new O2Principal(contextClient, oAuthToken); } O2Principal merged = new O2Principal( sameOrOne(contextClient, principal.contextClient), sameOrOne(oAuthToken, principal.oAuthToken) ); long validSchemes = Stream.of(getScheme(), principal.getScheme()) .map(O2AuthScheme::valueOf) .distinct() .filter(s -> !s.equals(O2AuthScheme.None)) .count(); if (validSchemes > 1) { throw new AccessDeniedException(); } return merged; }
O2Principal implements Principal { public O2Principal merge(final Principal newPrincipal) { O2Principal principal = safeCast(newPrincipal, O2Principal.class) .orElse(null); if (isNull(principal)) { return new O2Principal(contextClient, oAuthToken); } O2Principal merged = new O2Principal( sameOrOne(contextClient, principal.contextClient), sameOrOne(oAuthToken, principal.oAuthToken) ); long validSchemes = Stream.of(getScheme(), principal.getScheme()) .map(O2AuthScheme::valueOf) .distinct() .filter(s -> !s.equals(O2AuthScheme.None)) .count(); if (validSchemes > 1) { throw new AccessDeniedException(); } return merged; } }
O2Principal implements Principal { public O2Principal merge(final Principal newPrincipal) { O2Principal principal = safeCast(newPrincipal, O2Principal.class) .orElse(null); if (isNull(principal)) { return new O2Principal(contextClient, oAuthToken); } O2Principal merged = new O2Principal( sameOrOne(contextClient, principal.contextClient), sameOrOne(oAuthToken, principal.oAuthToken) ); long validSchemes = Stream.of(getScheme(), principal.getScheme()) .map(O2AuthScheme::valueOf) .distinct() .filter(s -> !s.equals(O2AuthScheme.None)) .count(); if (validSchemes > 1) { throw new AccessDeniedException(); } return merged; } O2Principal();  O2Principal(final Client client);  O2Principal(final OAuthToken token); private  O2Principal(final Client client, final OAuthToken token); }
O2Principal implements Principal { public O2Principal merge(final Principal newPrincipal) { O2Principal principal = safeCast(newPrincipal, O2Principal.class) .orElse(null); if (isNull(principal)) { return new O2Principal(contextClient, oAuthToken); } O2Principal merged = new O2Principal( sameOrOne(contextClient, principal.contextClient), sameOrOne(oAuthToken, principal.oAuthToken) ); long validSchemes = Stream.of(getScheme(), principal.getScheme()) .map(O2AuthScheme::valueOf) .distinct() .filter(s -> !s.equals(O2AuthScheme.None)) .count(); if (validSchemes > 1) { throw new AccessDeniedException(); } return merged; } O2Principal();  O2Principal(final Client client);  O2Principal(final OAuthToken token); private  O2Principal(final Client client, final OAuthToken token); OAuthToken getOAuthToken(); @Override String getName(); @Override boolean implies(final Subject subject); String getScheme(); Client getContext(); O2Principal merge(final Principal newPrincipal); @Override boolean equals(final Object o); @Override int hashCode(); }
O2Principal implements Principal { public O2Principal merge(final Principal newPrincipal) { O2Principal principal = safeCast(newPrincipal, O2Principal.class) .orElse(null); if (isNull(principal)) { return new O2Principal(contextClient, oAuthToken); } O2Principal merged = new O2Principal( sameOrOne(contextClient, principal.contextClient), sameOrOne(oAuthToken, principal.oAuthToken) ); long validSchemes = Stream.of(getScheme(), principal.getScheme()) .map(O2AuthScheme::valueOf) .distinct() .filter(s -> !s.equals(O2AuthScheme.None)) .count(); if (validSchemes > 1) { throw new AccessDeniedException(); } return merged; } O2Principal();  O2Principal(final Client client);  O2Principal(final OAuthToken token); private  O2Principal(final Client client, final OAuthToken token); OAuthToken getOAuthToken(); @Override String getName(); @Override boolean implies(final Subject subject); String getScheme(); Client getContext(); O2Principal merge(final Principal newPrincipal); @Override boolean equals(final Object o); @Override int hashCode();  }