@Test void testUpdateAuthenticationRestAuthenticationToken() { Object principal = mock(Object.class); Object credentials = mock(Object.class); String token = "token"; RestAuthenticationToken restAuthenticationToken = new RestAuthenticationToken(principal, credentials, emptyList(), token); Authentication updatedAuthentication = authenticationAuthoritiesUpdaterImpl.updateAuthentication( restAuthenticationToken, updatedAuthorities); assertEquals( new RestAuthenticationToken(principal, credentials, updatedAuthorities, token), updatedAuthentication); }
@Override public Authentication updateAuthentication( Authentication authentication, List<GrantedAuthority> updatedAuthorities) { Authentication newAuthentication; if (authentication instanceof TwoFactorAuthenticationToken) { TwoFactorAuthenticationToken twoFactorAuthenticationToken = (TwoFactorAuthenticationToken) authentication; newAuthentication = new TwoFactorAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, twoFactorAuthenticationToken.getVerificationCode(), twoFactorAuthenticationToken.getSecretKey()); } else if (authentication instanceof SystemSecurityToken) { newAuthentication = authentication; } else if (authentication instanceof RestAuthenticationToken) { RestAuthenticationToken restAuthenticationToken = (RestAuthenticationToken) authentication; newAuthentication = new RestAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, restAuthenticationToken.getToken()); } else if (authentication instanceof RecoveryAuthenticationToken) { RecoveryAuthenticationToken recoveryAuthenticationToken = (RecoveryAuthenticationToken) authentication; newAuthentication = new RecoveryAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, recoveryAuthenticationToken.getRecoveryCode()); } else if (authentication instanceof UsernamePasswordAuthenticationToken) { newAuthentication = new UsernamePasswordAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities); } else if (authentication instanceof RunAsUserToken) { RunAsUserToken runAsUserToken = (RunAsUserToken) authentication; newAuthentication = new RunAsUserTokenDecorator(runAsUserToken, updatedAuthorities); } else if (authentication instanceof AnonymousAuthenticationToken) { AnonymousAuthenticationToken anonymousAuthenticationToken = (AnonymousAuthenticationToken) authentication; newAuthentication = new AnonymousAuthenticationTokenDecorator( anonymousAuthenticationToken, updatedAuthorities); } else { throw new SessionAuthenticationException( format("Unknown authentication type '%s'", authentication.getClass().getSimpleName())); } return newAuthentication; }
AuthenticationAuthoritiesUpdaterImpl implements AuthenticationAuthoritiesUpdater { @Override public Authentication updateAuthentication( Authentication authentication, List<GrantedAuthority> updatedAuthorities) { Authentication newAuthentication; if (authentication instanceof TwoFactorAuthenticationToken) { TwoFactorAuthenticationToken twoFactorAuthenticationToken = (TwoFactorAuthenticationToken) authentication; newAuthentication = new TwoFactorAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, twoFactorAuthenticationToken.getVerificationCode(), twoFactorAuthenticationToken.getSecretKey()); } else if (authentication instanceof SystemSecurityToken) { newAuthentication = authentication; } else if (authentication instanceof RestAuthenticationToken) { RestAuthenticationToken restAuthenticationToken = (RestAuthenticationToken) authentication; newAuthentication = new RestAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, restAuthenticationToken.getToken()); } else if (authentication instanceof RecoveryAuthenticationToken) { RecoveryAuthenticationToken recoveryAuthenticationToken = (RecoveryAuthenticationToken) authentication; newAuthentication = new RecoveryAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, recoveryAuthenticationToken.getRecoveryCode()); } else if (authentication instanceof UsernamePasswordAuthenticationToken) { newAuthentication = new UsernamePasswordAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities); } else if (authentication instanceof RunAsUserToken) { RunAsUserToken runAsUserToken = (RunAsUserToken) authentication; newAuthentication = new RunAsUserTokenDecorator(runAsUserToken, updatedAuthorities); } else if (authentication instanceof AnonymousAuthenticationToken) { AnonymousAuthenticationToken anonymousAuthenticationToken = (AnonymousAuthenticationToken) authentication; newAuthentication = new AnonymousAuthenticationTokenDecorator( anonymousAuthenticationToken, updatedAuthorities); } else { throw new SessionAuthenticationException( format("Unknown authentication type '%s'", authentication.getClass().getSimpleName())); } return newAuthentication; } }
AuthenticationAuthoritiesUpdaterImpl implements AuthenticationAuthoritiesUpdater { @Override public Authentication updateAuthentication( Authentication authentication, List<GrantedAuthority> updatedAuthorities) { Authentication newAuthentication; if (authentication instanceof TwoFactorAuthenticationToken) { TwoFactorAuthenticationToken twoFactorAuthenticationToken = (TwoFactorAuthenticationToken) authentication; newAuthentication = new TwoFactorAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, twoFactorAuthenticationToken.getVerificationCode(), twoFactorAuthenticationToken.getSecretKey()); } else if (authentication instanceof SystemSecurityToken) { newAuthentication = authentication; } else if (authentication instanceof RestAuthenticationToken) { RestAuthenticationToken restAuthenticationToken = (RestAuthenticationToken) authentication; newAuthentication = new RestAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, restAuthenticationToken.getToken()); } else if (authentication instanceof RecoveryAuthenticationToken) { RecoveryAuthenticationToken recoveryAuthenticationToken = (RecoveryAuthenticationToken) authentication; newAuthentication = new RecoveryAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, recoveryAuthenticationToken.getRecoveryCode()); } else if (authentication instanceof UsernamePasswordAuthenticationToken) { newAuthentication = new UsernamePasswordAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities); } else if (authentication instanceof RunAsUserToken) { RunAsUserToken runAsUserToken = (RunAsUserToken) authentication; newAuthentication = new RunAsUserTokenDecorator(runAsUserToken, updatedAuthorities); } else if (authentication instanceof AnonymousAuthenticationToken) { AnonymousAuthenticationToken anonymousAuthenticationToken = (AnonymousAuthenticationToken) authentication; newAuthentication = new AnonymousAuthenticationTokenDecorator( anonymousAuthenticationToken, updatedAuthorities); } else { throw new SessionAuthenticationException( format("Unknown authentication type '%s'", authentication.getClass().getSimpleName())); } return newAuthentication; }  }
AuthenticationAuthoritiesUpdaterImpl implements AuthenticationAuthoritiesUpdater { @Override public Authentication updateAuthentication( Authentication authentication, List<GrantedAuthority> updatedAuthorities) { Authentication newAuthentication; if (authentication instanceof TwoFactorAuthenticationToken) { TwoFactorAuthenticationToken twoFactorAuthenticationToken = (TwoFactorAuthenticationToken) authentication; newAuthentication = new TwoFactorAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, twoFactorAuthenticationToken.getVerificationCode(), twoFactorAuthenticationToken.getSecretKey()); } else if (authentication instanceof SystemSecurityToken) { newAuthentication = authentication; } else if (authentication instanceof RestAuthenticationToken) { RestAuthenticationToken restAuthenticationToken = (RestAuthenticationToken) authentication; newAuthentication = new RestAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, restAuthenticationToken.getToken()); } else if (authentication instanceof RecoveryAuthenticationToken) { RecoveryAuthenticationToken recoveryAuthenticationToken = (RecoveryAuthenticationToken) authentication; newAuthentication = new RecoveryAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, recoveryAuthenticationToken.getRecoveryCode()); } else if (authentication instanceof UsernamePasswordAuthenticationToken) { newAuthentication = new UsernamePasswordAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities); } else if (authentication instanceof RunAsUserToken) { RunAsUserToken runAsUserToken = (RunAsUserToken) authentication; newAuthentication = new RunAsUserTokenDecorator(runAsUserToken, updatedAuthorities); } else if (authentication instanceof AnonymousAuthenticationToken) { AnonymousAuthenticationToken anonymousAuthenticationToken = (AnonymousAuthenticationToken) authentication; newAuthentication = new AnonymousAuthenticationTokenDecorator( anonymousAuthenticationToken, updatedAuthorities); } else { throw new SessionAuthenticationException( format("Unknown authentication type '%s'", authentication.getClass().getSimpleName())); } return newAuthentication; }  @Override Authentication updateAuthentication(
      Authentication authentication, List<GrantedAuthority> updatedAuthorities); }
AuthenticationAuthoritiesUpdaterImpl implements AuthenticationAuthoritiesUpdater { @Override public Authentication updateAuthentication( Authentication authentication, List<GrantedAuthority> updatedAuthorities) { Authentication newAuthentication; if (authentication instanceof TwoFactorAuthenticationToken) { TwoFactorAuthenticationToken twoFactorAuthenticationToken = (TwoFactorAuthenticationToken) authentication; newAuthentication = new TwoFactorAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, twoFactorAuthenticationToken.getVerificationCode(), twoFactorAuthenticationToken.getSecretKey()); } else if (authentication instanceof SystemSecurityToken) { newAuthentication = authentication; } else if (authentication instanceof RestAuthenticationToken) { RestAuthenticationToken restAuthenticationToken = (RestAuthenticationToken) authentication; newAuthentication = new RestAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, restAuthenticationToken.getToken()); } else if (authentication instanceof RecoveryAuthenticationToken) { RecoveryAuthenticationToken recoveryAuthenticationToken = (RecoveryAuthenticationToken) authentication; newAuthentication = new RecoveryAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities, recoveryAuthenticationToken.getRecoveryCode()); } else if (authentication instanceof UsernamePasswordAuthenticationToken) { newAuthentication = new UsernamePasswordAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), updatedAuthorities); } else if (authentication instanceof RunAsUserToken) { RunAsUserToken runAsUserToken = (RunAsUserToken) authentication; newAuthentication = new RunAsUserTokenDecorator(runAsUserToken, updatedAuthorities); } else if (authentication instanceof AnonymousAuthenticationToken) { AnonymousAuthenticationToken anonymousAuthenticationToken = (AnonymousAuthenticationToken) authentication; newAuthentication = new AnonymousAuthenticationTokenDecorator( anonymousAuthenticationToken, updatedAuthorities); } else { throw new SessionAuthenticationException( format("Unknown authentication type '%s'", authentication.getClass().getSimpleName())); } return newAuthentication; }  @Override Authentication updateAuthentication(
      Authentication authentication, List<GrantedAuthority> updatedAuthorities);  }