本文整理汇总了Java中org.pac4j.core.util.CommonHelper.isBlank方法的典型用法代码示例。如果您正苦于以下问题:Java CommonHelper.isBlank方法的具体用法?Java CommonHelper.isBlank怎么用?Java CommonHelper.isBlank使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pac4j.core.util.CommonHelper
的用法示例。
在下文中一共展示了CommonHelper.isBlank方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.pac4j.core.util.CommonHelper; //导入方法依赖的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: restoreOrBuildProfile
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
/**
* Restore or build a profile.
*
* @param profileDefinition the profile definition
* @param typedId the typed identifier
* @param attributes the attributes
* @param parameters additional parameters for the profile definition
* @return the restored or built profile
*/
public static CommonProfile restoreOrBuildProfile(final ProfileDefinition<? extends CommonProfile> profileDefinition,
final String typedId, final Map<String, Object> attributes, final Object... parameters) {
if (CommonHelper.isBlank(typedId)) {
return null;
}
logger.info("Building user profile based on typedId: {}", typedId);
final CommonProfile profile;
if (typedId.contains(CommonProfile.SEPARATOR)) {
final String className = CommonHelper.substringBefore(typedId, CommonProfile.SEPARATOR);
try {
profile = buildUserProfileByClassCompleteName(className);
} catch (final TechnicalException e) {
logger.error("Cannot build instance for class name: {}", className, e);
return null;
}
profile.addAttributes(attributes);
} else {
profile = profileDefinition.newProfile(parameters);
profileDefinition.convertAndAdd(profile, attributes);
}
profile.setId(typedId);
return profile;
}
示例3: check
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
@Override
protected boolean check(final WebContext context, final U profile, final String element) throws HttpAction {
if (!profile.containsAttribute(element)) {
return false;
}
if (CommonHelper.isBlank(this.valueToMatch)) {
return true;
}
final Object attributeValues = profile.getAttribute(element);
if (attributeValues instanceof Collection) {
return Collection.class.cast(attributeValues)
.stream()
.filter(v -> v.toString().matches(this.valueToMatch))
.findAny()
.isPresent();
}
return attributeValues.toString().matches(this.valueToMatch);
}
示例4: validate
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
@Override
public void validate(final TokenCredentials credentials, final WebContext context) throws HttpAction {
if (credentials == null) {
throw new CredentialsException("No credential");
}
if (!(credentials instanceof DigestCredentials)) {
throw new CredentialsException ("Unsupported credentials type " + credentials.getClass());
}
DigestCredentials digestCredentials = (DigestCredentials) credentials;
String username = digestCredentials.getUsername();
if (CommonHelper.isBlank(username)) {
throw new CredentialsException("Username cannot be blank");
}
String token = credentials.getToken();
if (CommonHelper.isBlank(token)) {
throw new CredentialsException("Token cannot be blank");
}
CommonProfile profile = new CommonProfile();
profile.setId(username);
credentials.setUserProfile(profile);
}
示例5: 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();
}
}
示例6: buildProfile
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
/**
* Build a profile from a typed id and a map of attributes.
*
* @param typedId typed identifier
* @param attributes user attributes
* @return the user profile built
*/
public static CommonProfile buildProfile(final String typedId, final Map<String, Object> attributes) {
if (CommonHelper.isBlank(typedId)) {
return null;
}
logger.info("Building user profile based on typedId {}", typedId);
try {
final String[] values = typedId.split(CommonProfile.SEPARATOR);
if (values != null && values.length >= 1) {
final String className = values[0];
if (CommonHelper.isNotBlank(className)) {
final String completeName;
if (className.indexOf(".") >=0 ) {
completeName = className;
} else {
logger.warn("Typed identifier starting with only a simple class name (without package name) are deprecated and will be removed in future versions. See profile#getOldTypedId() versus profile#getTypedId()");
completeName = determineProfileClassByName(className);
}
final CommonProfile profile = buildUserProfileByClassCompleteName(completeName);
profile.build(typedId, attributes);
logger.debug("userProfile built: {}", profile);
return profile;
}
}
} catch (final TechnicalException e) {
logger.error("Cannot build instance", e);
}
return null;
}
示例7: getName
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
@Override
public String getName() {
if (CommonHelper.isBlank(this.name)) {
return this.getClass().getSimpleName();
}
return this.name;
}
示例8: extract
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
/**
* Extracts digest Authorization header components.
* As per RFC 2617 :
* username is the user's name in the specified realm
* qop is quality of protection
* uri is the request uri
* response is the client response
* nonce is a server-specified data string which should be uniquely generated
* each time a 401 response is made
* cnonce is the client nonce
* nc is the nonce count
* If in the Authorization header it is not specified a username and response, we throw CredentialsException because
* the client uses an username and a password to authenticate. response is just a MD5 encoded value
* based on user provided password and RFC 2617 digest authentication encoding rules
* @param context the current web context
* @return the Digest credentials
*/
@Override
public DigestCredentials extract(WebContext context) throws HttpAction {
final TokenCredentials credentials = this.extractor.extract(context);
if (credentials == null) {
return null;
}
String token = credentials.getToken();
Map<String, String> valueMap = parseTokenValue(token);
String username = valueMap.get("username");
String response = valueMap.get("response");
if (CommonHelper.isBlank(username) || CommonHelper.isBlank(response)) {
throw new CredentialsException("Bad format of the digest auth header");
}
String realm = valueMap.get("realm");
String nonce = valueMap.get("nonce");
String uri = valueMap.get("uri");
String cnonce = valueMap.get("cnonce");
String nc = valueMap.get("nc");
String qop = valueMap.get("qop");
String method = context.getRequestMethod();
return new DigestCredentials(response, method, clientName, username, realm, nonce, uri, cnonce, nc, qop);
}
示例9: validate
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
@Override
public void validate(final TokenCredentials credentials, final WebContext context) throws HttpAction {
if (credentials == null) {
throw new CredentialsException("credentials must not be null");
}
if (CommonHelper.isBlank(credentials.getToken())) {
throw new CredentialsException("token must not be blank");
}
final String token = credentials.getToken();
final CommonProfile profile = new CommonProfile();
profile.setId(token);
credentials.setUserProfile(profile);
}
示例10: initializeClientConfiguration
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
protected void initializeClientConfiguration(final WebContext context) {
if (this.prefixUrl != null && !this.prefixUrl.endsWith("/")) {
this.prefixUrl += "/";
}
if (CommonHelper.isBlank(this.prefixUrl)) {
this.prefixUrl = this.loginUrl.replaceFirst("/login$", "/");
} else if (CommonHelper.isBlank(this.loginUrl)) {
this.loginUrl = this.prefixUrl + "login";
}
if (callbackUrlResolver != null) {
this.prefixUrl = callbackUrlResolver.compute(this.prefixUrl, context);
this.loginUrl = callbackUrlResolver.compute(this.loginUrl, context);
}
}
示例11: internalInit
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
@Override
protected void internalInit(final WebContext context) {
CommonHelper.assertNotBlank("casServerPrefixUrl", this.casServerPrefixUrl);
if (CommonHelper.isBlank(casRestUrl)) {
casRestUrl = casServerPrefixUrl;
if (!casRestUrl.endsWith("/")) {
casRestUrl += "/";
}
casRestUrl += "v1/tickets";
}
if (this.ticketValidator == null) {
this.ticketValidator = new Cas30ServiceTicketValidator(this.casServerPrefixUrl);
}
}
示例12: SAML2ServiceProviderMetadataResolver
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
private SAML2ServiceProviderMetadataResolver(final String spMetadataPath,
final WritableResource spMetadataResource,
final String callbackUrl,
@Nullable final String spEntityId,
final boolean forceSpMetadataGeneration,
final CredentialProvider credentialProvider,
boolean authnRequestSigned, boolean wantsAssertionsSigned) {
this.authnRequestSigned = authnRequestSigned;
this.wantsAssertionsSigned = wantsAssertionsSigned;
if (spMetadataResource != null) {
this.spMetadataResource = spMetadataResource;
} else {
this.spMetadataResource = (WritableResource) CommonHelper.getResource(spMetadataPath);
}
this.spEntityId = spEntityId;
this.credentialProvider = credentialProvider;
this.callbackUrl = callbackUrl;
this.forceSpMetadataGeneration = forceSpMetadataGeneration;
// If the spEntityId is blank, use the callback url
try {
if (CommonHelper.isBlank(this.spEntityId)) {
final URL url = new URL(callbackUrl);
if (url.getQuery() != null) {
this.spEntityId = url.toString().replace("?" + url.getQuery(), "");
} else {
this.spEntityId = url.toString();
}
}
logger.info("Using SP entity ID {}", this.spEntityId);
} catch (final Exception e) {
throw new SAMLException(e);
}
}
示例13: 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;
}
示例14: getName
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
public String getName() {
if (CommonHelper.isBlank(this.name)) {
return this.getClass().getSimpleName();
}
return this.name;
}
示例15: createKeystore
import org.pac4j.core.util.CommonHelper; //导入方法依赖的package包/类
private void createKeystore() {
try {
Security.addProvider(new BouncyCastleProvider());
if (CommonHelper.isBlank(this.keyStoreAlias)) {
this.keyStoreAlias = getClass().getSimpleName();
LOGGER.warn("Using keystore alias {}", this.keyStoreAlias);
}
if (CommonHelper.isBlank(this.keyStoreType)) {
this.keyStoreType = KeyStore.getDefaultType();
LOGGER.warn("Using keystore type {}", this.keyStoreType);
}
final KeyStore ks = KeyStore.getInstance(this.keyStoreType);
final char[] password = this.keystorePassword.toCharArray();
ks.load(null, password);
final KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
final KeyPair kp = kpg.genKeyPair();
final X509V3CertificateGenerator cert = new X509V3CertificateGenerator();
cert.setSerialNumber(BigInteger.valueOf(1));
final String dn = InetAddress.getLocalHost().getHostName();
cert.setSubjectDN(new X509Principal("CN=" + dn));
cert.setIssuerDN(new X509Principal("CN=" + dn));
cert.setPublicKey(kp.getPublic());
cert.setNotBefore(new Date());
final Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.YEAR, 1);
cert.setNotAfter(c.getTime());
cert.setSignatureAlgorithm("SHA1WithRSA");
final PrivateKey signingKey = kp.getPrivate();
final X509Certificate certificate = cert.generate(signingKey, "BC");
ks.setKeyEntry(this.keyStoreAlias, signingKey, password, new Certificate[]{certificate});
try (FileOutputStream fos = new FileOutputStream(this.keystoreResource.getFile().getCanonicalPath())) {
ks.store(fos, password);
fos.flush();
}
LOGGER.info("Created keystore {} with key alias {} ",
keystoreResource.getFile().getCanonicalPath(),
ks.aliases().nextElement());
this.keyStore = ks;
} catch (final Exception e) {
throw new SAMLException("Could not create keystore", e);
}
}