@Test public void testTransform() { final ConsumerDetails details = context.mock(ConsumerDetails.class); final String key = "This is the key."; context.checking(new Expectations() { { oneOf(securityContext).getAuthentication(); will(returnValue(authentication)); oneOf(authentication).getPrincipal(); will(returnValue(details)); allowing(details).getConsumerKey(); will(returnValue(key)); } }); assertEquals(key, sut.transform(null)); context.assertIsSatisfied(); }
@Override public String transform(final Object inTransformType) { try { SecurityContext securityCtx = SecurityContextHolder.getContext(); Authentication auth = securityCtx.getAuthentication(); if (auth != null) { Object obj = auth.getPrincipal(); if (obj instanceof ConsumerDetails) { return ((ConsumerDetails) obj).getConsumerKey(); } } } catch (Exception ex) { logger.info("Unable to populate principal from SecurityContext.", ex); } return null; }
SpringSecurityContextOAuthClientExtractor implements Transformer<Object, String> { @Override public String transform(final Object inTransformType) { try { SecurityContext securityCtx = SecurityContextHolder.getContext(); Authentication auth = securityCtx.getAuthentication(); if (auth != null) { Object obj = auth.getPrincipal(); if (obj instanceof ConsumerDetails) { return ((ConsumerDetails) obj).getConsumerKey(); } } } catch (Exception ex) { logger.info("Unable to populate principal from SecurityContext.", ex); } return null; } }
SpringSecurityContextOAuthClientExtractor implements Transformer<Object, String> { @Override public String transform(final Object inTransformType) { try { SecurityContext securityCtx = SecurityContextHolder.getContext(); Authentication auth = securityCtx.getAuthentication(); if (auth != null) { Object obj = auth.getPrincipal(); if (obj instanceof ConsumerDetails) { return ((ConsumerDetails) obj).getConsumerKey(); } } } catch (Exception ex) { logger.info("Unable to populate principal from SecurityContext.", ex); } return null; }  }
SpringSecurityContextOAuthClientExtractor implements Transformer<Object, String> { @Override public String transform(final Object inTransformType) { try { SecurityContext securityCtx = SecurityContextHolder.getContext(); Authentication auth = securityCtx.getAuthentication(); if (auth != null) { Object obj = auth.getPrincipal(); if (obj instanceof ConsumerDetails) { return ((ConsumerDetails) obj).getConsumerKey(); } } } catch (Exception ex) { logger.info("Unable to populate principal from SecurityContext.", ex); } return null; }  @Override String transform(final Object inTransformType); }
SpringSecurityContextOAuthClientExtractor implements Transformer<Object, String> { @Override public String transform(final Object inTransformType) { try { SecurityContext securityCtx = SecurityContextHolder.getContext(); Authentication auth = securityCtx.getAuthentication(); if (auth != null) { Object obj = auth.getPrincipal(); if (obj instanceof ConsumerDetails) { return ((ConsumerDetails) obj).getConsumerKey(); } } } catch (Exception ex) { logger.info("Unable to populate principal from SecurityContext.", ex); } return null; }  @Override String transform(final Object inTransformType);  }