/** * Determines if a string is not blank. A string is not blank if it contains * at least one non-whitespace character. * * @param string the string to check. * @return true if its not blank, false otherwise. */ public static boolean isNotBlank(final String string) { return !isBlank(string); }
/** * Determines if a string is not blank. A string is not blank if it contains * at least one non-whitespace character. * * @param string the string to check. * @return true if its not blank, false otherwise. */ public static boolean isNotBlank(final String string) { return !isBlank(string); }
public static void readAndRespondToProxyReceptorRequest(final HttpServletRequest request, final HttpServletResponse response, final ProxyGrantingTicketStorage proxyGrantingTicketStorage) throws IOException { final String proxyGrantingTicketIou = request.getParameter(PARAM_PROXY_GRANTING_TICKET_IOU); final String proxyGrantingTicket = request.getParameter(PARAM_PROXY_GRANTING_TICKET); if (CommonUtils.isBlank(proxyGrantingTicket) || CommonUtils.isBlank(proxyGrantingTicketIou)) { response.getWriter().write(""); return; } LOGGER.debug("Received proxyGrantingTicketId [{}] for proxyGrantingTicketIou [{}]", proxyGrantingTicket, proxyGrantingTicketIou); proxyGrantingTicketStorage.save(proxyGrantingTicketIou, proxyGrantingTicket); LOGGER.debug("Successfully saved proxyGrantingTicketId [{}] for proxyGrantingTicketIou [{}]", proxyGrantingTicket, proxyGrantingTicketIou); response.getWriter().write("<?xml version=\"1.0\"?>"); response.getWriter().write("<casClient:proxySuccess xmlns:casClient=\"http://www.yale.edu/tp/casClient\" />"); }
public static void readAndRespondToProxyReceptorRequest(final HttpServletRequest request, final HttpServletResponse response, final ProxyGrantingTicketStorage proxyGrantingTicketStorage) throws IOException { final String proxyGrantingTicketIou = request.getParameter(PARAM_PROXY_GRANTING_TICKET_IOU); final String proxyGrantingTicket = request.getParameter(PARAM_PROXY_GRANTING_TICKET); if (CommonUtils.isBlank(proxyGrantingTicket) || CommonUtils.isBlank(proxyGrantingTicketIou)) { response.getWriter().write(""); return; } if (LOG.isDebugEnabled()) { LOG.debug("Received proxyGrantingTicketId [" + proxyGrantingTicket + "] for proxyGrantingTicketIou [" + proxyGrantingTicketIou + "]"); } proxyGrantingTicketStorage.save(proxyGrantingTicketIou, proxyGrantingTicket); if (LOG.isDebugEnabled()) { LOG.debug("Successfully saved proxyGrantingTicketId [" + proxyGrantingTicket + "] for proxyGrantingTicketIou [" + proxyGrantingTicketIou + "]"); } response.getWriter().write("<?xml version=\"1.0\"?>"); response.getWriter().write("<casClient:proxySuccess xmlns:casClient=\"http://www.yale.edu/tp/casClient\" />"); }
/** * NOTE: you can only retrieve a ProxyGrantingTicket once with this method. * Its removed after retrieval. */ public String retrieve(final String proxyGrantingTicketIou) { if (CommonUtils.isBlank(proxyGrantingTicketIou)) { return null; } final ProxyGrantingTicketHolder holder = this.cache.get(proxyGrantingTicketIou); if (holder == null) { logger.info("No Proxy Ticket found for [{}].", proxyGrantingTicketIou); return null; } this.cache.remove(proxyGrantingTicketIou); logger.debug("Returned ProxyGrantingTicket of [{}]", holder.getProxyGrantingTicket()); return holder.getProxyGrantingTicket(); }
/** * Initialization method. Called by Filter's init method or by Spring. Similar in concept to the InitializingBean interface's * afterPropertiesSet(); */ public void init() { CommonUtils.assertTrue(CommonUtils.isNotEmpty(this.serverName) || CommonUtils.isNotEmpty(this.service), "serverName or service must be set."); CommonUtils.assertTrue(CommonUtils.isBlank(this.serverName) || CommonUtils.isBlank(this.service), "serverName and service cannot both be set. You MUST ONLY set one."); }
/** * Static helper method that will resolve a simple string to either an enum value or a {@link org.jasig.cas.client.configuration.ConfigurationStrategy} class. * * @param value the value to attempt to resolve. * @return the underlying class that this maps to (either via simple name or fully qualified class name). */ public static Class<? extends ConfigurationStrategy> resolveToConfigurationStrategy(final String value) { if (CommonUtils.isBlank(value)) { return DEFAULT.configurationStrategyClass; } for (final ConfigurationStrategyName csn : values()) { if (csn.name().equalsIgnoreCase(value)) { return csn.configurationStrategyClass; } } try { final Class<?> clazz = Class.forName(value); if (ConfigurationStrategy.class.isAssignableFrom(clazz)) { return (Class<? extends ConfigurationStrategy>) clazz; } } catch (final ClassNotFoundException e) { LOGGER.error("Unable to locate strategy {} by name or class name. Using default strategy instead.", value, e); } return DEFAULT.configurationStrategyClass; } }
public boolean isUserInRole(final String role) { if (CommonUtils.isBlank(role)) { log.debug("No valid role provided. Returning false."); return false; } if (this.principal == null) { log.debug("No Principal in Request. Returning false."); return false; } if (CommonUtils.isBlank(roleAttribute)) { log.debug("No Role Attribute Configured. Returning false."); return false; } final Object value = this.principal.getAttributes().get(roleAttribute); if (value instanceof Collection) { for (final Iterator iter = ((Collection) value).iterator(); iter.hasNext();) { if (rolesEqual(role, iter.next())) { log.debug("User [" + getRemoteUser() + "] is in role [" + role + "]: " + true); return true; } } } final boolean isMember = rolesEqual(role, value); log.debug("User [" + getRemoteUser() + "] is in role [" + role + "]: " + isMember); return isMember; }
public boolean isUserInRole(final String role) { if (CommonUtils.isBlank(role)) { logger.debug("No valid role provided. Returning false."); return false; } if (this.principal == null) { logger.debug("No Principal in Request. Returning false."); return false; } if (CommonUtils.isBlank(roleAttribute)) { logger.debug("No Role Attribute Configured. Returning false."); return false; } final Object value = this.principal.getAttributes().get(roleAttribute); if (value instanceof Collection<?>) { for (final Object o : (Collection<?>) value) { if (rolesEqual(role, o)) { logger.debug("User [{}] is in role [{}]: true", getRemoteUser(), role); return true; } } } final boolean isMember = rolesEqual(role, value); logger.debug("User [{}] is in role [{}]: {}", getRemoteUser(), role, isMember); return isMember; }
if (CommonUtils.isBlank(service)) { log.info("Login failed because required CAS service parameter not provided."); throw new LoginException("Neither login module nor callback handler provided required service parameter.");
/** * Initializes the component for use. */ public synchronized void init() { if (this.safeParameters == null) { CommonUtils.assertNotNull(this.artifactParameterName, "artifactParameterName cannot be null."); CommonUtils.assertNotNull(this.logoutParameterName, "logoutParameterName cannot be null."); CommonUtils.assertNotNull(this.sessionMappingStorage, "sessionMappingStorage cannot be null."); CommonUtils.assertNotNull(this.relayStateParameterName, "relayStateParameterName cannot be null."); CommonUtils.assertNotNull(this.casServerUrlPrefix, "casServerUrlPrefix cannot be null."); if (CommonUtils.isBlank(this.casServerUrlPrefix)) { logger.warn("Front Channel single sign out redirects are disabled when the 'casServerUrlPrefix' value is not set."); } if (this.artifactParameterOverPost) { this.safeParameters = Arrays.asList(this.logoutParameterName, this.artifactParameterName); } else { this.safeParameters = Collections.singletonList(this.logoutParameterName); } } }
if (CommonUtils.isBlank(logoutMessage)) { logger.error("Could not locate logout message of the request from {}", this.logoutParameterName); return;
public static ProxyList createProxyList(final String proxies) { if (CommonUtils.isBlank(proxies)) { return new ProxyList(); } final ProxyListEditor editor = new ProxyListEditor(); editor.setAsText(proxies); return (ProxyList) editor.getValue(); }
private <T> T getValue(final ConfigurationKey<T> configurationKey, final Parser<T> parser) { final String value = getWithCheck(configurationKey); if (CommonUtils.isBlank(value)) { logger.trace("No value found for property {}, returning default {}", configurationKey.getName(), configurationKey.getDefaultValue()); return configurationKey.getDefaultValue(); } else { logger.trace("Loaded property {} with value {}", configurationKey.getName(), configurationKey.getDefaultValue()); } return parser.parse(value); }
public static ProxyList createProxyList(final String proxies) { if (CommonUtils.isBlank(proxies)) { return new ProxyList(); } final ProxyListEditor editor = new ProxyListEditor(); editor.setAsText(proxies); return (ProxyList) editor.getValue(); }
final String service = CommonUtils.constructServiceUrl(request, response, this.serviceUrl, this.serverName, this.serviceParameterName, this.artifactParameterName, true); if (CommonUtils.isBlank(token)) { final String redirectUrl = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, this.serviceParameterName, service, false, false);
public TicketValidationJsonResponse parse(final String response) throws TicketValidationException, IOException { if (CommonUtils.isBlank(response)) { throw new TicketValidationException("Invalid JSON response; The response is empty"); } final TicketValidationJsonResponse json = this.objectMapper.readValue(response, TicketValidationJsonResponse.class); final TicketValidationJsonResponse.CasServiceResponseAuthentication serviceResponse = json.getServiceResponse(); if (serviceResponse.getAuthenticationFailure() != null && serviceResponse.getAuthenticationSuccess() != null) { throw new TicketValidationException("Invalid JSON response; It indicates both a success " + "and a failure event, which is indicative of a server error. The actual response is " + response); } if (serviceResponse.getAuthenticationFailure() != null) { final String error = json.getServiceResponse().getAuthenticationFailure().getCode() + " - " + serviceResponse.getAuthenticationFailure().getDescription(); throw new TicketValidationException(error); } final String principal = json.getServiceResponse().getAuthenticationSuccess().getUser(); if (CommonUtils.isEmpty(principal)) { throw new TicketValidationException("No principal was found in the response from the CAS server."); } return json; } }
Assertion getAssertion(final ProxyGrantingTicketStorage proxyGrantingTicketStorage, final ProxyRetriever proxyRetriever) { final String proxyGrantingTicketIou = getServiceResponse().getAuthenticationSuccess().getProxyGrantingTicket(); final String proxyGrantingTicket; if (CommonUtils.isBlank(proxyGrantingTicketIou) || proxyGrantingTicketStorage == null) { proxyGrantingTicket = null; } else { proxyGrantingTicket = proxyGrantingTicketStorage.retrieve(proxyGrantingTicketIou); } final Assertion assertion; final Map<String, Object> attributes = getServiceResponse().getAuthenticationSuccess().getAttributes(); final String principal = getServiceResponse().getAuthenticationSuccess().getUser(); if (CommonUtils.isNotBlank(proxyGrantingTicket)) { final AttributePrincipal attributePrincipal = new AttributePrincipalImpl(principal, attributes, proxyGrantingTicket, proxyRetriever); assertion = new AssertionImpl(attributePrincipal); } else { assertion = new AssertionImpl(new AttributePrincipalImpl(principal, attributes)); } return assertion; }
protected Assertion parseResponseFromServer(final String response) throws TicketValidationException { final String error = parseAuthenticationFailureFromResponse(response); if (CommonUtils.isNotBlank(error)) { throw new TicketValidationException(error); } final String principal = parsePrincipalFromResponse(response); final String proxyGrantingTicketIou = parseProxyGrantingTicketFromResponse(response); final String proxyGrantingTicket; if (CommonUtils.isBlank(proxyGrantingTicketIou) || this.proxyGrantingTicketStorage == null) { proxyGrantingTicket = null; } else { proxyGrantingTicket = this.proxyGrantingTicketStorage.retrieve(proxyGrantingTicketIou); } if (CommonUtils.isEmpty(principal)) { throw new TicketValidationException("No principal was found in the response from the CAS server."); } final Assertion assertion; final Map<String, Object> attributes = extractCustomAttributes(response); if (CommonUtils.isNotBlank(proxyGrantingTicket)) { final AttributePrincipal attributePrincipal = new AttributePrincipalImpl(principal, attributes, proxyGrantingTicket, this.proxyRetriever); assertion = new AssertionImpl(attributePrincipal); } else { assertion = new AssertionImpl(new AttributePrincipalImpl(principal, attributes)); } customParseResponse(response, assertion); return assertion; }