BoschIoTSuiteOAuthProviderAuthCode extends AbstractOAuthProvider { @Override public boolean canHandle(Authentication auth) { if (!(auth instanceof OAuth2Authentication)) { return false; } OAuth2Authentication oauth2Auth = (OAuth2Authentication) auth; if (oauth2Auth.getOAuth2Request() == null) { return false; } return clientId.equals(oauth2Auth.getOAuth2Request().getClientId()); } @Autowired  BoschIoTSuiteOAuthProviderAuthCode(
      @Value("${suite.oauth2.client.clientId}") String clientId,
      @Value("${oauth2.verification.hydra.publicKeyUri: #{null}}") String hydraPublicKeyUri,
      @Autowired BoschIoTSuiteOAuthProviderConfiguration suiteOAuthProviderConfiguration,
      @Autowired DefaultUserAccountService userAccountService,
      @Autowired UserNamespaceRoleService userNamespaceRoleService
  );  BoschIoTSuiteOAuthProviderAuthCode(
      String clientId,
      Supplier<Map<String, PublicKey>> publicKeySupplier,
      BoschIoTSuiteOAuthProviderConfiguration suiteOAuthProviderConfiguration,
      DefaultUserAccountService userAccountService,
      UserNamespaceRoleService userNamespaceRoleService
  ); @Override String getId(); @Override boolean canHandle(Authentication auth); @Override boolean canHandle(String jwtToken); @Override Authentication authenticate(HttpServletRequest request, String jwtToken); @Override boolean verify(HttpServletRequest httpRequest, JwtToken jwtToken); @SuppressWarnings("rawtypes") @Override OAuthUser createUser(Authentication authentication); @Override boolean supportsWebflow(); @Override Optional<IOAuthFlowConfiguration> getWebflowConfiguration(); @Override String getLabel(); static final String FAMILY_NAME; static final String GIVEN_NAME; static final String EMAIL; }
@Test public void canHandleSuccessTest() { assertTrue(sut.canHandle(TOKEN)); }
@Test public void canHandleFailureTest() { assertFalse(sut.canHandle("invalid-token")); }
@Test public void canHandleAuthenticationSuccessTest() { OAuth2Request request = new OAuth2Request(null, CLIENT_ID, null, true, null, null, null, null,null); OAuth2Authentication authentication = new OAuth2Authentication(request, null); assertTrue(sut.canHandle(authentication)); }
@Test public void canHandleAuthenticationFailureTest() { OAuth2Request request = new OAuth2Request(null, "invalid-client", null, true, null, null, null, null,null); OAuth2Authentication authentication = new OAuth2Authentication(request, null); assertFalse(sut.canHandle(authentication)); }