/** * Construct a Pac4jPrincipal and specify which attribute in the CommonProfile * should be used for the principal name. * * @param profiles A list containing all of the CommonProfiles created by Pac4j * authorization. * @param principalNameAttribute The attribute name in the CommonProfile that * holds the principal name. A null or blank value means * that CommonProfile.getId() should be used as the principal name. */ public Pac4jPrincipal(final List<CommonProfile> profiles, String principalNameAttribute) { this.profiles = profiles; this.principalNameAttribute = CommonHelper.isBlank(principalNameAttribute) ? null : principalNameAttribute.trim(); }
protected boolean mustApply(final J2EContext context) { final String path = context.getPath(); logger.debug("path: {} | suffix: {}", path, suffix); if (isBlank(suffix)) { return true; } else { return path != null && path.endsWith(suffix); } }
private void determineServiceProviderEntityId(final String callbackUrl) { try { if (CommonHelper.isBlank(configuration.getServiceProviderEntityId())) { final URL url = new URL(callbackUrl); if (url.getQuery() != null) { configuration.setServiceProviderEntityId(url.toString().replace("?" + url.getQuery(), "")); } else { configuration.setServiceProviderEntityId(url.toString()); } } logger.info("Using SP entity ID {}", configuration.getServiceProviderEntityId()); } catch (final Exception e) { throw new SAMLException(e); } }
@Override public void validate(final UsernamePasswordCredentials credentials, final WebContext context) { init(); final String username = credentials.getUsername(); final String password = credentials.getPassword(); if (CommonHelper.isBlank(username) || CommonHelper.isBlank(password)) { logger.info("Empty username or password"); return; } final String body = callRestApi(username, password); logger.debug("body: {}", body); if (body != null) { buildProfile(credentials, body); } }
private void createKeystore() { try { 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);
@Override public void validate(final TokenCredentials credentials, final WebContext context) { 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); } }
throw new ServletException("At least one pac4j client must be defined."); if (CommonHelper.isBlank(clientNameParameter)) { clientName = clients.get(0).getName(); } else {
throw new ServletException("At least one pac4j client must be defined."); if (CommonHelper.isBlank(clientNameParameter)) { clientName = clients.get(0).getName(); } else {
@Override public void validate(final UsernamePasswordCredentials credentials, final WebContext context) { if (credentials == null) { throw new CredentialsException("No credential"); } String username = credentials.getUsername(); String password = credentials.getPassword(); if (CommonHelper.isBlank(username)) { throw new CredentialsException("Username cannot be blank"); } if (CommonHelper.isBlank(password)) { throw new CredentialsException("Password cannot be blank"); } if (CommonHelper.areNotEquals(username, password)) { throw new CredentialsException("Username : '" + username + "' does not match password"); } final CommonProfile profile = new CommonProfile(); profile.setId(username); profile.addAttribute(Pac4jConstants.USERNAME, username); credentials.setUserProfile(profile); } }
@Override public void validate(final TokenCredentials credentials, final WebContext context) { 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); } }
@Override protected YahooProfile retrieveUserProfileFromToken(final WebContext context, final OAuth1AccessToken accessToken) { // get the guid: https://developer.yahoo.com/social/rest_api_guide/introspective-guid-resource.html final OAuth10ProfileDefinition<YahooProfile> profileDefinition = (OAuth10ProfileDefinition<YahooProfile>) configuration.getProfileDefinition(); final String profileUrl = profileDefinition.getProfileUrl(accessToken, this.configuration); final OAuth10aService service = configuration.buildService(context, client, null); String body = sendRequestForData(service, accessToken, profileUrl, profileDefinition.getProfileVerb()); final String guid = CommonHelper.substringBetween(body, "<value>", "</value>"); logger.debug("guid : {}", guid); if (CommonHelper.isBlank(guid)) { throw new HttpCommunicationException("Cannot find guid from body : " + body); } body = sendRequestForData(service, accessToken, "https://social.yahooapis.com/v1/user/" + guid + "/profile?format=json", Verb.GET); final YahooProfile profile = (YahooProfile) configuration.getProfileDefinition().extractUserProfile(body); addAccessTokenToProfile(profile, accessToken); return profile; } }