本文整理汇总了Java中org.pac4j.core.util.CommonHelper类的典型用法代码示例。如果您正苦于以下问题:Java CommonHelper类的具体用法?Java CommonHelper怎么用?Java CommonHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommonHelper类属于org.pac4j.core.util包,在下文中一共展示了CommonHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: internalInit
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
@Override
protected void internalInit(final WebContext context) {
CommonHelper.assertNotBlank("accessId", accessId);
CommonHelper.assertNotBlank("secretKey", secretKey);
CommonHelper.assertNotBlank("applicationId", applicationId);
try {
final Client client = new Client(new DefaultApiKey(accessId, secretKey));
this.application = client.getDataStore().getResource(
String.format("/applications/%s", applicationId), Application.class);
} catch (final Exception e) {
throw new BadCredentialsException("An exception is caught trying to access Stormpath cloud. " +
"Please verify that your provided Stormpath <accessId>, " +
"<secretKey>, and <applicationId> are correct. Original Stormpath error: " + e.getMessage());
}
}
示例2: updateCallbackUrlOfIndirectClient
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
/**
* Sets a client's Callback URL, if not already set. If requested, the "client_name" parameter will also be a part of the URL.
*
* @param indirectClient A client.
*/
protected void updateCallbackUrlOfIndirectClient(final IndirectClient indirectClient) {
String indirectClientCallbackUrl = indirectClient.getCallbackUrl();
// no callback url defined for the client but a group callback one -> set it with the group callback url
if (CommonHelper.isNotBlank(this.callbackUrl) && indirectClientCallbackUrl == null) {
indirectClient.setCallbackUrl(this.callbackUrl);
indirectClientCallbackUrl = this.callbackUrl;
}
// if the "client_name" parameter is not already part of the client callback url, add it unless the client has indicated to not include it.
if (indirectClient.isIncludeClientNameInCallbackUrl() && indirectClientCallbackUrl != null && !indirectClientCallbackUrl.contains(this.clientNameParameter + "=")) {
indirectClient.setCallbackUrl(CommonHelper.addParameter(indirectClientCallbackUrl, this.clientNameParameter, indirectClient.getName()));
}
final AjaxRequestResolver clientAjaxRequestResolver = indirectClient.getAjaxRequestResolver();
if (ajaxRequestResolver != null && (clientAjaxRequestResolver == null || clientAjaxRequestResolver instanceof DefaultAjaxRequestResolver)) {
indirectClient.setAjaxRequestResolver(ajaxRequestResolver);
}
final CallbackUrlResolver clientCallbackUrlResolver = indirectClient.getCallbackUrlResolver();
if (callbackUrlResolver != null && (clientCallbackUrlResolver == null || clientCallbackUrlResolver instanceof DefaultCallbackUrlResolver)) {
indirectClient.setCallbackUrlResolver(this.callbackUrlResolver);
}
}
示例3: verifyProfile
import org.pac4j.core.util.CommonHelper; //导入依赖的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());
}
示例4: internalInit
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
/**
* Initialize all clients by computing callback urls if necessary.
*/
@Override
protected void internalInit() {
CommonHelper.assertNotNull("clients", getClients());
final HashSet<String> names = new HashSet<>();
for (final T client : getClients()) {
final String name = client.getName();
final String lowerName = name.toLowerCase();
if (names.contains(lowerName)) {
throw new TechnicalException("Duplicate name in clients: " + name);
}
names.add(lowerName);
// Instead of using brittle client type checking, make it the responsibility of the client to know how
// to configure itself from the Clients object
client.configureFromClientsObject(this);
// if (client instanceof IndirectClient) {
// updateCallbackUrlOfIndirectClient((IndirectClient) client);
// }
// final BaseClient baseClient = (BaseClient) client;
// if (!authorizationGenerators.isEmpty()) {
// baseClient.addAuthorizationGenerators(this.authorizationGenerators);
// }
}
}
示例5: matches
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
@Override
public CompletableFuture<Boolean> matches(AsyncWebContext context, String matcherNames, Map<String, AsyncMatcher> matchersMap) {
// if we have a matcher name (which may be a list of matchers names)
if (CommonHelper.isNotBlank(matcherNames)) {
// we must have matchers
CommonHelper.assertNotNull("matchersMap", matchersMap);
final String[] names = matcherNames.split(Pac4jConstants.ELEMENT_SEPRATOR);
final List<AsyncMatcher> matchers = Arrays.stream(names)
.map(n -> matchersMap.entrySet().stream()
.filter(e -> CommonHelper.areEqualsIgnoreCaseAndTrim(e.getKey(), n))
.peek(e -> CommonHelper.assertNotNull("matchersMap['" + n + "']", e))
.findFirst().map(e -> e.getValue()).orElse(null))
.collect(Collectors.toList());
return shortCircuitedFuture(matchers.stream()
.map(m -> () -> m.matches(context)), false);
}
return CompletableFuture.completedFuture(true);
}
示例6: verifyProfile
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
@Override
protected void verifyProfile(CommonProfile userProfile) {
final OkProfile profile = (OkProfile) userProfile;
assertEquals(TEST_PROFILE_ID, profile.getId());
assertEquals(OkProfile.class.getName() + CommonProfile.SEPARATOR + TEST_PROFILE_ID,
profile.getTypedId());
assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), OkProfile.class));
assertTrue(CommonHelper.isNotBlank(profile.getAccessToken()));
assertCommonProfile(
userProfile,
null,
TEST_FIRST_NAME,
TEST_LAST_NAME,
TEST_FIRST_NAME + " " + TEST_LAST_NAME,
TEST_PROFILE_ID,
Gender.MALE,
new Locale(TEST_LOCALE),
TEST_PROFILE_PICTURE_URL,
OkProfile.BASE_PROFILE_URL + TEST_PROFILE_ID,
TEST_LOCATION);
}
示例7: updateCallback
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
private void updateCallback(Clients<AsyncClient<C, U>, AsyncAuthorizationGenerator<U>> toConfigureFrom) {
String callbackUrl = getCallbackUrl();
Clients clients = null;
if (toConfigureFrom instanceof Clients) {
clients = toConfigureFrom;
}
// no callback url defined for the client but a group callback one -> set it with the group callback url
if (CommonHelper.isNotBlank(clients.getCallbackUrl()) && callbackUrl == null) {
setCallbackUrl(clients.getCallbackUrl());
callbackUrl = this.callbackUrl;
}
// if the "client_name" parameter is not already part of the client callback url, add it unless the client has indicated to not include it.
if (isIncludeClientNameInCallbackUrl() && callbackUrl != null && !callbackUrl.contains(clients.getClientNameParameter() + "=")) {
setCallbackUrl(CommonHelper.addParameter(callbackUrl, clients.getClientNameParameter(), getName()));
}
final AjaxRequestResolver clientAjaxRequestResolver = getAjaxRequestResolver();
if (ajaxRequestResolver != null && (clientAjaxRequestResolver == null || clientAjaxRequestResolver instanceof DefaultAjaxRequestResolver)) {
setAjaxRequestResolver(ajaxRequestResolver);
}
final UrlResolver clientUrlResolver = getUrlResolver();
if (urlResolver != null && (clientUrlResolver == null || clientUrlResolver instanceof DefaultUrlResolver)) {
setUrlResolver(this.urlResolver);
}
}
示例8: internalInit
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
@Override
protected void internalInit(AsyncWebContext context) {
CommonHelper.assertNotBlank("callbackUrl", this.callbackUrl,
"set it up either on this client or the global Config");
CommonHelper.assertNotNull("urlResolver", this.urlResolver);
CommonHelper.assertNotNull("ajaxRequestResolver", this.ajaxRequestResolver);
clientInit(context);
// ensures components have been properly initialized
CommonHelper.assertNotNull("redirectActionBuilder", this.redirectActionBuilder);
CommonHelper.assertNotNull("credentialsExtractor", getCredentialsExtractor());
CommonHelper.assertNotNull("authenticator", getAuthenticator());
CommonHelper.assertNotNull("profileCreator", getProfileCreator());
CommonHelper.assertNotNull("logoutActionBuilder", this.logoutActionBuilder);
}
示例9: clientInit
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
@Override
protected void clientInit(final AsyncWebContext context) {
CommonHelper.assertNotBlank("fields", this.fields);
configuration.setApi(FacebookApi.instance());
configuration.setProfileDefinition(new FacebookProfileDefinition());
configuration.setScope(scope);
configuration.setHasBeenCancelledFactory(ctx -> {
final String error = ctx.getRequestParameter(OAuthCredentialsException.ERROR);
final String errorReason = ctx.getRequestParameter(OAuthCredentialsException.ERROR_REASON);
// user has denied permissions
if ("access_denied".equals(error) && "user_denied".equals(errorReason)) {
return true;
} else {
return false;
}
});
configuration.setWithState(true);
setConfiguration(configuration);
defaultProfileCreator(new AsyncFacebookProfileCreator(configuration));
super.clientInit(context);
}
示例10: tryCreateFacebookClient
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
private void tryCreateFacebookClient(final List<Client> clients) {
final String id = getProperty(FACEBOOK_ID);
final String secret = getProperty(FACEBOOK_SECRET);
final String scope = getProperty(FACEBOOK_SCOPE);
final String fields = getProperty(FACEBOOK_FIELDS);
if (CommonHelper.isNotBlank(id) && CommonHelper.isNotBlank(secret)) {
final FacebookClient facebookClient = new FacebookClient(id, secret);
if (CommonHelper.isNotBlank(scope)) {
facebookClient.setScope(scope);
}
if (CommonHelper.isNotBlank(fields)) {
facebookClient.setFields(fields);
}
clients.add(facebookClient);
}
}
示例11: internalInit
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
@Override
protected void internalInit(final WebContext context) {
if (CommonHelper.isBlank(this.loginUrl) && CommonHelper.isBlank(this.prefixUrl)) {
throw new TechnicalException("loginUrl and prefixUrl cannot be both blank");
}
initializeClientConfiguration(context);
initializeLogoutHandler(context);
if (this.protocol == CasProtocol.CAS10) {
initializeCas10Protocol();
} else if (this.protocol == CasProtocol.CAS20) {
initializeCas20Protocol(context);
} else if (this.protocol == CasProtocol.CAS20_PROXY) {
initializeCas20ProxyProtocol(context);
} else if (this.protocol == CasProtocol.CAS30) {
initializeCas30Protocol(context);
} else if (this.protocol == CasProtocol.CAS30_PROXY) {
initializeCas30ProxyProtocol(context);
} else if (this.protocol == CasProtocol.SAML) {
initializeSAMLProtocol();
}
}
示例12: retrieveCredentials
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
@Override
protected C retrieveCredentials(final WebContext context) throws HttpAction {
CommonHelper.assertNotNull("credentialsExtractor", this.credentialsExtractor);
CommonHelper.assertNotNull("authenticator", this.authenticator);
try {
final C credentials = this.credentialsExtractor.extract(context);
if (credentials == null) {
return null;
}
this.authenticator.validate(credentials, context);
return credentials;
} catch (CredentialsException e) {
logger.info("Failed to retrieve or validate credentials: {}", e.getMessage());
logger.debug("Failed to retrieve or validate credentials", e);
return null;
}
}
示例13: redirectToApproveView
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
/**
* Redirect to approve view model and view.
*
* @param ctx the ctx
* @param svc the svc
* @return the model and view
*/
protected ModelAndView redirectToApproveView(final J2EContext ctx, final OAuthRegisteredService svc) {
String callbackUrl = ctx.getFullRequestURL();
callbackUrl = CommonHelper.addParameter(callbackUrl, OAuth20Constants.BYPASS_APPROVAL_PROMPT, "true");
LOGGER.debug("callbackUrl: [{}]", callbackUrl);
final Map<String, Object> model = new HashMap<>();
model.put("service", svc);
model.put("callbackUrl", callbackUrl);
model.put("serviceName", svc.getName());
model.put("deniedApprovalUrl", svc.getAccessStrategy().getUnauthorizedRedirectUrl());
prepareApprovalViewModel(model, ctx, svc);
return getApprovalModelAndView(model);
}
示例14: retrieveUserProfileFromToken
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
@Override
protected YahooProfile retrieveUserProfileFromToken(final OAuth1Token accessToken) throws HttpAction {
// get the guid: https://developer.yahoo.com/social/rest_api_guide/introspective-guid-resource.html
String body = sendRequestForData(accessToken, getProfileUrl(accessToken));
final String guid = CommonHelper.substringBetween(body, "<value>", "</value>");
logger.debug("guid : {}", guid);
if (CommonHelper.isBlank(guid)) {
final String message = "Cannot find guid from body : " + body;
throw new HttpCommunicationException(message);
}
body = sendRequestForData(accessToken, "https://social.yahooapis.com/v1/user/" + guid + "/profile?format=json");
final YahooProfile profile = extractUserProfile(body);
addAccessTokenToProfile(profile, accessToken);
return profile;
}
示例15: toString
import org.pac4j.core.util.CommonHelper; //导入依赖的package包/类
@Override
public String toString() {
return CommonHelper.toString(getClass(),
"callbackUrl", callbackUrl,
"name", getName(),
"loginUrl", loginUrl,
"redirectActionBuilder", getRedirectActionBuilder(),
"extractor", getCredentialsExtractor(),
"authenticator", getAuthenticator(),
"profileCreator", getProfileCreator());
}