@Override public FeatureUser getCurrentFeatureUser() { boolean featureAdmin = true; return new SimpleFeatureUser("p13n-testing-user", featureAdmin); }
@Override public FeatureUser getCurrentFeatureUser() { boolean featureAdmin = true; return new SimpleFeatureUser("p13n-testing-user", featureAdmin); }
@Bean @Profile("test") public UserProvider userProvider() { return () -> new SimpleFeatureUser("someName", false); }
@Bean @ConditionalOnMissingBean(UserProvider.class) public UserProvider getUserProvider() { return () -> { HttpServletRequest request = HttpServletRequestHolder.get(); String username = (String) request.getAttribute("username"); boolean isAdmin = true; // "admin".equals(username); return new SimpleFeatureUser(username, isAdmin); }; }
@Bean @ConditionalOnMissingBean(UserProvider.class) public UserProvider userProvider() { return () -> { HttpServletRequest request = HttpServletRequestHolder.get(); Optional<Credentials> credentials = Credentials.readFrom(request); boolean isAdmin = true; // "admin".equals(username); return new SimpleFeatureUser((credentials.isPresent() ? credentials.get().getUsername() : null), isAdmin); }; }
@Bean @ConditionalOnMissingBean(UserProvider.class) public UserProvider userProvider() { return () -> { final HttpServletRequest request = HttpServletRequestHolder.get(); final Optional<Credentials> credentials = Credentials.readFrom(request); final boolean isAdmin = true; // "admin".equals(username); return new SimpleFeatureUser((credentials.isPresent() ? credentials.get().getUsername() : null), isAdmin); }; }
@Override public FeatureUser getCurrentUser() { boolean isAdmin = false; String userOrcid = null; SecurityContext context = SecurityContextHolder.getContext(); if (context != null && context.getAuthentication() != null) { Authentication authentication = context.getAuthentication(); if (authentication != null) { Object principal = authentication.getDetails(); if (principal instanceof OrcidProfileUserDetails) { OrcidProfileUserDetails userDetails = (OrcidProfileUserDetails) principal; isAdmin = userDetails.getAuthorities().contains(OrcidWebRole.ROLE_ADMIN); userOrcid = userDetails.getOrcid(); } } } return new SimpleFeatureUser(userOrcid, isAdmin); } };
@Override public FeatureUser getCurrentUser() { SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = context.getAuthentication(); // null if no authentication data is available for the current thread if (authentication != null) { // try to obtain the name of this user String name = getUserName(authentication); // check for the authority for feature admins Set<String> authorities = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); boolean featureAdmin = isFeatureAdmin(authentication, authorities); SimpleFeatureUser user = new SimpleFeatureUser(name, featureAdmin); user.setAttribute(USER_ATTRIBUTE_ROLES, authorities); return user; } return null; }
@Override public FeatureUser getCurrentUser() { if (identity != null && identity.getUser() != null) { return new SimpleFeatureUser(identity.getUser().getId(), isFeatureAdmin()); } return null; }
@BeforeEach public void setUp() { final MongoDatabase mongoDatabase = EmbeddedMongoHelper.getMongoClient().getDatabase("features-" + UUID.randomUUID()); final FeatureClassProvider featureClassProvider = new TestFeatureClassProvider(); final UserProvider userProvider = mock(UserProvider.class); when(userProvider.getCurrentUser()).thenReturn(new SimpleFeatureUser("someUser")); testee = new MongoTogglzRepository(mongoDatabase, featureClassProvider, userProvider, new MongoProperties()); }