@Override public boolean isProfileAuthorized(final WebContext context, final CommonProfile profile) { if (profile == null) { return false; } return StringUtils.startsWith(profile.getUsername(), "jle"); } }
@Override public boolean isProfileAuthorized(final WebContext context, final CommonProfile profile) { if (profile == null) { return false; } return StringUtils.startsWith(profile.getUsername(), "jle"); } }
@Test public void testGetUserProfile() { final DirectFormClient formClient = getFormClient(); formClient.setProfileCreator((credentials, context) -> { String username = credentials.getUsername(); final CommonProfile profile = new CommonProfile(); profile.setId(username); profile.addAttribute(Pac4jConstants.USERNAME, username); return profile; }); final MockWebContext context = MockWebContext.create(); final CommonProfile profile = formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME), context); assertEquals(USERNAME, profile.getId()); assertEquals(CommonProfile.class.getName() + CommonProfile.SEPARATOR + USERNAME, profile.getTypedId()); assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), CommonProfile.class)); assertEquals(USERNAME, profile.getUsername()); assertEquals(1, profile.getAttributes().size()); } }
@Test public void testGetUserProfile() { final FormClient formClient = getFormClient(); formClient.setProfileCreator((credentials, context) -> { String username = credentials.getUsername(); final CommonProfile profile = new CommonProfile(); profile.setId(username); profile.addAttribute(Pac4jConstants.USERNAME, username); return profile; }); final MockWebContext context = MockWebContext.create(); final CommonProfile profile = formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME), context); assertEquals(USERNAME, profile.getId()); assertEquals(CommonProfile.class.getName() + CommonProfile.SEPARATOR + USERNAME, profile.getTypedId()); assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), CommonProfile.class)); assertEquals(USERNAME, profile.getUsername()); assertEquals(1, profile.getAttributes().size()); } }