本文整理汇总了Java中org.pac4j.core.profile.CommonProfile类的典型用法代码示例。如果您正苦于以下问题:Java CommonProfile类的具体用法?Java CommonProfile怎么用?Java CommonProfile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommonProfile类属于org.pac4j.core.profile包,在下文中一共展示了CommonProfile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Override
public void validate(final UsernamePasswordCredentials credentials, final WebContext context) throws HttpAction {
if (credentials == null) {
throwsException("No credential");
}
String username = credentials.getUsername();
String password = credentials.getPassword();
if (CommonHelper.isBlank(username)) {
throwsException("Username cannot be blank");
}
if (CommonHelper.isBlank(password)) {
throwsException("Password cannot be blank");
}
if (CommonHelper.areNotEquals(username, password)) {
throwsException("Username : '" + username + "' does not match password");
}
final CommonProfile profile = new CommonProfile();
profile.setId(username);
profile.addAttribute(Pac4jConstants.USERNAME, username);
credentials.setUserProfile(profile);
}
示例2: verifyProfile
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Override
protected void verifyProfile(final CommonProfile userProfile) {
final OidcProfile profile = (OidcProfile) userProfile;
assertEquals("90342.ASDFJWFA", profile.getId());
assertEquals(OidcProfile.class.getName() + CommonProfile.SEPARATOR + "90342.ASDFJWFA",
profile.getTypedId());
assertNotNull(profile.getAccessToken());
assertNotNull(profile.getIdToken());
assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), OidcProfile.class));
assertNotNull(profile.getIdTokenString());
assertCommonProfile(profile, "[email protected]", null, null, "Demo Admin", "admin",
Gender.UNSPECIFIED, null, null, null, null);
assertTrue((Boolean) profile.getAttribute("email_verified"));
assertEquals("https://mitreid.org/", profile.getIssuer());
assertEquals("acdf79d7-0129-4ba3-bc61-a52486cf82ff", profile.getAudience().get(0));
assertNotNull(profile.getAuthTime());
assertNotNull(profile.getExpirationDate());
assertNotNull(profile.getIssuedAt());
assertNotNull(profile.getAttribute("jti"));
assertEquals(13, profile.getAttributes().size());
}
示例3: testDoubleDirectClientSupportingMultiProfile
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Test
public void testDoubleDirectClientSupportingMultiProfile() throws Exception {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final CommonProfile profile2 = new CommonProfile();
profile2.setId(VALUE);
final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
clients = NAME + "," + VALUE;
multiProfile = true;
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) context.getRequestAttribute(Pac4jConstants.USER_PROFILES);
assertEquals(2, profiles.size());
assertTrue(profiles.containsValue(profile));
assertTrue(profiles.containsValue(profile2));
}
示例4: generateAuthorizationForLdapEntry
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Override
protected CommonProfile generateAuthorizationForLdapEntry(final CommonProfile profile, final LdapEntry userEntry) {
try {
LOGGER.debug("Attempting to get roles for user [{}].", userEntry.getDn());
final Response<SearchResult> response = this.groupSearchExecutor.search(
this.connectionFactory,
Beans.newLdaptiveSearchFilter(this.groupSearchExecutor.getSearchFilter().getFilter(),
Beans.LDAP_SEARCH_FILTER_DEFAULT_PARAM_NAME, Arrays.asList(userEntry.getDn())));
LOGGER.debug("LDAP role search response: [{}]", response);
final SearchResult groupResult = response.getResult();
for (final LdapEntry entry : groupResult.getEntries()) {
final LdapAttribute groupAttribute = entry.getAttribute(this.groupAttributeName);
if (groupAttribute == null) {
LOGGER.warn("Role attribute not found on entry [{}]", entry);
continue;
}
addProfileRolesFromAttributes(profile, groupAttribute, this.groupPrefix);
}
} catch (final LdapException e) {
throw new RuntimeException("LDAP error fetching roles for user.", e);
}
return profile;
}
示例5: testCallbackNoRenew
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Test
public void testCallbackNoRenew() throws Exception {
final String originalSessionId = request.getSession().getId();
request.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
final CommonProfile profile = new CommonProfile();
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), profile);
config.setClients(new Clients(CALLBACK_URL, indirectClient));
renewSession = false;
call();
final HttpSession session = request.getSession();
final String newSessionId = session.getId();
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) session.getAttribute(Pac4jConstants.USER_PROFILES);
assertTrue(profiles.containsValue(profile));
assertEquals(1, profiles.size());
assertEquals(newSessionId, originalSessionId);
assertEquals(302, response.getStatus());
assertEquals(Pac4jConstants.DEFAULT_URL_VALUE, response.getRedirectedUrl());
}
示例6: testRolePermissionChangeSplit
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Test
public void testRolePermissionChangeSplit() {
final String[] roleAttributes = new String[] {
ATTRIB1
};
final String[] permissionAttributes = new String[] {
ATTRIB2
};
final FromAttributesAuthorizationGenerator<CommonProfile> generator = new FromAttributesAuthorizationGenerator<CommonProfile>(
roleAttributes,
permissionAttributes);
generator.setSplitChar("|");
generator.generate(this.profile);
final Set<String> roles = this.profile.getRoles();
assertEquals(1, roles.size());
assertTrue(roles.contains(VALUE1));
final Set<String> permissions = this.profile.getPermissions();
assertEquals(1, permissions.size());
assertTrue(permissions.contains(VALUE2));
}
示例7: testAuthentication
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Test
public void testAuthentication() throws HttpAction {
final DirectDigestAuthClient client = new DirectDigestAuthClient(new SimpleTestDigestAuthenticator());
client.setRealm(REALM);
final MockWebContext context = MockWebContext.create();
context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER,
DIGEST_AUTHORIZATION_HEADER_VALUE);
context.setRequestMethod("GET");
final DigestCredentials credentials = client.getCredentials(context);
final CommonProfile profile = client.getUserProfile(credentials, context);
String ha1 = CredentialUtil.encryptMD5(USERNAME + ":" + REALM + ":" +PASSWORD);
String serverDigest1 = credentials.calculateServerDigest(true, ha1);
String serverDigest2 = credentials.calculateServerDigest(false, PASSWORD);
assertEquals(DIGEST_RESPONSE, serverDigest1);
assertEquals(DIGEST_RESPONSE, serverDigest2);
assertEquals(USERNAME, profile.getId());
}
示例8: getSafe
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
/**
* Gets template from TemplateEngine that is at least instance of BaseTemplate.
* Sets parameters to template that are available to all subclasses of BaseTemplate.
*
* @param ctx to use
* @param fileName to load
* @param type of template to load
* @return template of specified type
*/
private <S extends BaseTemplate> S getSafe(RoutingContext ctx, String fileName, Class<S> type) {
S base = engine.getSafeTemplate(ctx.getDelegate(), fileName, type);
base.setLang(ctx.getCookie(LANGUAGE) != null ? ctx.getCookie(LANGUAGE).getValue() :
ENGLISH.getLocale().getLanguage());
base.setLogoutUrl(addParameter(AUTH_LOGOUT, URL, UI_LOGIN));
base.setLoginPage(UI_LOGIN);
base.setHomePage(UI_HOME);
base.setMoviesPage(UI_MOVIES);
base.setSeriesPage(UI_SERIES);
base.setHistoryPage(UI_HISTORY);
base.setStatisticsPage(UI_STATISTICS);
base.setDiscoverPage(UI_DISCOVER);
base.setListsPage(UI_LISTS);
CommonProfile profile = getProfile(ctx, securityConfig);
if (profile != null) {
base.setUserName(profile.getFirstName() + " " + profile.getFamilyName());
base.setUserFirstName(profile.getFirstName());
}
return base;
}
示例9: testDoubleDirectClient
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Test
public void testDoubleDirectClient() throws Exception {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final CommonProfile profile2 = new CommonProfile();
profile2.setId(VALUE);
final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
clients = NAME + "," + VALUE;
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) context.getRequestAttribute(Pac4jConstants.USER_PROFILES);
assertEquals(1, profiles.size());
assertTrue(profiles.containsValue(profile));
}
示例10: VertxAsyncLogoutHandler
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
public VertxAsyncLogoutHandler(final Vertx vertx,
final Context context,
final AsyncConfig<Void, CommonProfile, VertxAsyncWebContext> config,
final LogoutHandlerOptions options) {
DefaultAsyncLogoutLogic<Void, CommonProfile, VertxAsyncWebContext> defaultApplicationLogoutLogic = new DefaultAsyncLogoutLogic<>(config,
httpActionAdapter,
options.getDefaultUrl(),
options.getLogoutUrlPattern(),
options.isLocalLogout(),
options.isDestroySession(),
options.isCentralLogout());
defaultApplicationLogoutLogic.setProfileManagerFactory(c -> new VertxAsyncProfileManager(c));
this.logoutLogic = defaultApplicationLogoutLogic;
this.config = config;
this.asynchronousComputationAdapter = new VertxAsynchronousComputationAdapter(vertx, context);
}
示例11: testDoubleDirectClientChooseBadDirectClient
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Test
public void testDoubleDirectClientChooseBadDirectClient(final TestContext testContext) throws Exception {
final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = doubleDirectClients();
when(config.getClients()).thenReturn(clients);
final String clientNames = NAME;
when(webContext.getRequestParameter(eq(Clients.DEFAULT_CLIENT_NAME_PARAMETER))).thenReturn(VALUE);
asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, true, config, httpActionAdapter);
final Async async = testContext.async();
exception.expect(CompletionException.class);
exception.expectCause(allOf(IsInstanceOf.instanceOf(TechnicalException.class),
hasProperty("message", is("Client not allowed: " + VALUE))));
final CompletableFuture<Object> result = asyncSecurityLogic.perform(webContext, accessGrantedAdapter, clientNames, null, null);
assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
assertThat(o, is(nullValue()));
verify(accessGrantedAdapter, times(0)).adapt(webContext);
}), async);
}
示例12: verifyProfile
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Override
protected void verifyProfile(CommonProfile userProfile) {
final Google2Profile profile = (Google2Profile) userProfile;
assertEquals("113675986756217860428", profile.getId());
assertEquals(Google2Profile.class.getName() + CommonProfile.SEPARATOR + "113675986756217860428",
profile.getTypedId());
assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), Google2Profile.class));
assertTrue(CommonHelper.isNotBlank(profile.getAccessToken()));
assertCommonProfile(userProfile, "[email protected]", "Jérôme", "ScribeUP", "Jérôme ScribeUP", null,
Gender.MALE, Locale.ENGLISH,
"https://lh4.googleusercontent.com/-fFUNeYqT6bk/AAAAAAAAAAI/AAAAAAAAAAA/5gBL6csVWio/photo.jpg",
"https://plus.google.com/113675986756217860428", null);
assertNull(profile.getBirthday());
assertTrue(profile.getEmails() != null && profile.getEmails().size() == 1);
assertEquals(9, profile.getAttributes().size());
}
示例13: testDoubleDirectClientChooseDirectClient
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Test
public void testDoubleDirectClientChooseDirectClient() throws Exception {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final CommonProfile profile2 = new CommonProfile();
profile2.setId(VALUE);
final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
clients = NAME + "," + VALUE;
context.addRequestParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, VALUE);
multiProfile = true;
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) context.getRequestAttribute(Pac4jConstants.USER_PROFILES);
assertEquals(1, profiles.size());
assertTrue(profiles.containsValue(profile2));
}
示例14: validate
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Override
public void validate(final T credentials, final WebContext context) throws HttpAction {
init(context);
try {
final CommonProfile profile = this.cache.get(credentials, () -> {
logger.debug("Delegating authentication to {}...", delegate);
delegate.validate(credentials, context);
return credentials.getUserProfile();
});
credentials.setUserProfile(profile);
logger.debug("Found cached credential. Using cached profile {}...", profile);
} catch (Exception e) {
throw new CredentialsException(e);
}
}
示例15: verifyProfile
import org.pac4j.core.profile.CommonProfile; //导入依赖的package包/类
@Override
protected void verifyProfile(final CommonProfile userProfile) {
final OidcProfile profile = (OidcProfile) userProfile;
assertEquals("00u5h0czw1aIjTQtM0h7", profile.getId());
assertEquals(OidcProfile.class.getName() + CommonProfile.SEPARATOR + "00u5h0czw1aIjTQtM0h7",
profile.getTypedId());
assertNotNull(profile.getAccessToken());
assertNotNull(profile.getIdToken());
assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), OidcProfile.class));
assertNotNull(profile.getIdTokenString());
assertCommonProfile(profile, getLogin(), "Test", "pac4j", "Test pac4j", "[email protected]",
Gender.UNSPECIFIED, new Locale("en", "US"), null, null, "America/Los_Angeles");
assertTrue((Boolean) profile.getAttribute("email_verified"));
assertNotNull(profile.getAttribute("at_hash"));
assertEquals("1", profile.getAttribute("ver").toString());
assertNotNull(profile.getAmr());
assertEquals("https://dev-425954.oktapreview.com", profile.getIssuer());
assertEquals("ZuxDX1Gw2Kvx4gFyDNWC", profile.getAudience().get(0));
assertEquals("00o5gxpohzF1JWEXZ0h7", profile.getAttribute("idp"));
assertNotNull(profile.getAuthTime());
assertNotNull(profile.getExpirationDate());
assertNotNull(profile.getIssuedAt());
assertNotNull(profile.getAttribute("jti"));
assertEquals(22, profile.getAttributes().size());
}