@Test public void testFailure() { Config config = Config.create( ConfigSources.create(Map.of("atn-object.size", String.valueOf(SIZE))) ); SecurityContext context = mock(SecurityContext.class); when(context.user()).thenReturn(Optional.empty()); when(context.service()).thenReturn(Optional.empty()); SecurityEnvironment se = SecurityEnvironment.create(); EndpointConfig ep = EndpointConfig.builder() .config("atn-object", config) .build(); ProviderRequest request = mock(ProviderRequest.class); when(request.securityContext()).thenReturn(context); when(request.env()).thenReturn(se); when(request.endpointConfig()).thenReturn(ep); AtnProviderSync provider = new AtnProviderSync(); AuthenticationResponse response = provider.syncAuthenticate(request); assertThat(response.status(), is(SecurityResponse.SecurityStatus.FAILURE)); }
@Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { AtnObject myObject = getCustomObject(providerRequest.endpointConfig()); if (null == myObject) { return AuthenticationResponse.abstain(); } if (myObject.isValid()) { return AuthenticationResponse.success(Subject.builder() .addPrincipal(Principal.create(myObject.getValue())) .addGrant(Role.create("role_" + myObject.getSize())) .build()); } else { return AuthenticationResponse.failed("Invalid request"); } }
AtnProviderSync extends SynchronousProvider implements AuthenticationProvider { @Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { AtnObject myObject = getCustomObject(providerRequest.endpointConfig()); if (null == myObject) { return AuthenticationResponse.abstain(); } if (myObject.isValid()) { return AuthenticationResponse.success(Subject.builder() .addPrincipal(Principal.create(myObject.getValue())) .addGrant(Role.create("role_" + myObject.getSize())) .build()); } else { return AuthenticationResponse.failed("Invalid request"); } } }
AtnProviderSync extends SynchronousProvider implements AuthenticationProvider { @Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { AtnObject myObject = getCustomObject(providerRequest.endpointConfig()); if (null == myObject) { return AuthenticationResponse.abstain(); } if (myObject.isValid()) { return AuthenticationResponse.success(Subject.builder() .addPrincipal(Principal.create(myObject.getValue())) .addGrant(Role.create("role_" + myObject.getSize())) .build()); } else { return AuthenticationResponse.failed("Invalid request"); } }  }
AtnProviderSync extends SynchronousProvider implements AuthenticationProvider { @Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { AtnObject myObject = getCustomObject(providerRequest.endpointConfig()); if (null == myObject) { return AuthenticationResponse.abstain(); } if (myObject.isValid()) { return AuthenticationResponse.success(Subject.builder() .addPrincipal(Principal.create(myObject.getValue())) .addGrant(Role.create("role_" + myObject.getSize())) .build()); } else { return AuthenticationResponse.failed("Invalid request"); } }  @Override Collection<Class<? extends Annotation>> supportedAnnotations(); }
AtnProviderSync extends SynchronousProvider implements AuthenticationProvider { @Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { AtnObject myObject = getCustomObject(providerRequest.endpointConfig()); if (null == myObject) { return AuthenticationResponse.abstain(); } if (myObject.isValid()) { return AuthenticationResponse.success(Subject.builder() .addPrincipal(Principal.create(myObject.getValue())) .addGrant(Role.create("role_" + myObject.getSize())) .build()); } else { return AuthenticationResponse.failed("Invalid request"); } }  @Override Collection<Class<? extends Annotation>> supportedAnnotations();  }