@Test public void testConvertNoAuth() { ILoggingEvent event = mock(ILoggingEvent.class); String res = converter.convert(event); assertEquals("NO ROLE", res); }
@Override public String convert(ILoggingEvent event) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth == null) { return NO_ROLE; } Object principal = auth.getPrincipal(); if (principal instanceof WebCertUser) { WebCertUser user = (WebCertUser) auth.getPrincipal(); Set<String> keys = user.getRoles().keySet(); if (keys.size() == 1) { return keys.toArray(new String[0])[0]; } } return NO_ROLE; }
RoleConverter extends ClassicConverter { @Override public String convert(ILoggingEvent event) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth == null) { return NO_ROLE; } Object principal = auth.getPrincipal(); if (principal instanceof WebCertUser) { WebCertUser user = (WebCertUser) auth.getPrincipal(); Set<String> keys = user.getRoles().keySet(); if (keys.size() == 1) { return keys.toArray(new String[0])[0]; } } return NO_ROLE; } }
RoleConverter extends ClassicConverter { @Override public String convert(ILoggingEvent event) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth == null) { return NO_ROLE; } Object principal = auth.getPrincipal(); if (principal instanceof WebCertUser) { WebCertUser user = (WebCertUser) auth.getPrincipal(); Set<String> keys = user.getRoles().keySet(); if (keys.size() == 1) { return keys.toArray(new String[0])[0]; } } return NO_ROLE; }  }
RoleConverter extends ClassicConverter { @Override public String convert(ILoggingEvent event) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth == null) { return NO_ROLE; } Object principal = auth.getPrincipal(); if (principal instanceof WebCertUser) { WebCertUser user = (WebCertUser) auth.getPrincipal(); Set<String> keys = user.getRoles().keySet(); if (keys.size() == 1) { return keys.toArray(new String[0])[0]; } } return NO_ROLE; }  @Override String convert(ILoggingEvent event); }
RoleConverter extends ClassicConverter { @Override public String convert(ILoggingEvent event) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth == null) { return NO_ROLE; } Object principal = auth.getPrincipal(); if (principal instanceof WebCertUser) { WebCertUser user = (WebCertUser) auth.getPrincipal(); Set<String> keys = user.getRoles().keySet(); if (keys.size() == 1) { return keys.toArray(new String[0])[0]; } } return NO_ROLE; }  @Override String convert(ILoggingEvent event);  }