/** * Sets the name of the CAS principal attribute that contains role data. * * @param roleAttribute Role attribute name. MUST NOT be blank. */ public void setRoleAttribute(final String roleAttribute) { CommonUtils.isNotBlank(roleAttribute); this.roleAttribute = roleAttribute; }
/** * Sets the names of the server host running Jetty. * * @param nameList Space-delimited list of one or more server names, e.g. "www1.example.com www2.example.com". * MUST NOT be blank. */ public void setServerNames(final String nameList) { CommonUtils.isNotBlank(nameList); this.serverNames = nameList; }
public void redirect(final HttpServletRequest request, final HttpServletResponse response, final String potentialRedirectUrl) throws IOException { if (CommonUtils.isNotBlank(request.getParameter(FACES_PARTIAL_AJAX_PARAMETER))) { // this is an ajax request - redirect ajaxly response.setContentType("text/xml"); response.setStatus(200); final PrintWriter writer = response.getWriter(); writer.write("<?xml version='1.0' encoding='UTF-8'?>"); writer.write(String.format("<partial-response><redirect url=\"%s\"></redirect></partial-response>", potentialRedirectUrl)); } else { response.sendRedirect(potentialRedirectUrl); } } }
/** * Determines whether the given request contains an authentication token. * * @param request HTTP reqest. * * @return True if request contains authentication token, false otherwise. */ private boolean isTokenRequest(final HttpServletRequest request) { return CommonUtils.isNotBlank(CommonUtils.safeGetParameter(request, this.artifactParameterName, this.safeParameters)); }
public ISecurityContext getSecurityContext() { if (CommonUtils.isNotBlank(this.clearPassUrl)) { return new PasswordCachingCasAssertionSecurityContext(this.clearPassUrl); } throw new IllegalStateException(String.format("clearPassUrl not configured. Cannot create an instance of [%s] without it.", getClass().getSimpleName())); } }
/** * Determines whether the given request is a CAS logout request. * * @param request HTTP request. * * @return True if request is logout request, false otherwise. */ public boolean isLogoutRequest(final HttpServletRequest request) { return "POST".equals(request.getMethod()) && CommonUtils.isNotBlank(CommonUtils.safeGetParameter(request, this.logoutParameterName)); }
/** * Determines whether the given request contains an authentication token. * * @param request HTTP reqest. * * @return True if request contains authentication token, false otherwise. */ public boolean isTokenRequest(final HttpServletRequest request) { return CommonUtils.isNotBlank(CommonUtils.safeGetParameter(request, this.artifactParameterName)); }
@Override public ISecurityContext getSecurityContext() { if (CommonUtils.isNotBlank(this.clearPassCasUrl)) { return new PasswordCachingCasAssertionSecurityContext(this.clearPassCasUrl); } throw new IllegalStateException( String.format( "clearPassUrl not configured. Cannot create an instance of [%s] without it.", getClass().getSimpleName())); } }
protected String get(final ConfigurationKey configurationKey) { final String value = this.filterConfig.getInitParameter(configurationKey.getName()); if (CommonUtils.isNotBlank(value)) { CommonUtils.assertFalse(ConfigurationKeys.RENEW.equals(configurationKey), "Renew MUST be specified via context parameter or JNDI environment to avoid misconfiguration."); logger.info("Property [{}] loaded from FilterConfig.getInitParameter with value [{}]", configurationKey, value); return value; } final String value2 = filterConfig.getServletContext().getInitParameter(configurationKey.getName()); if (CommonUtils.isNotBlank(value2)) { logger.info("Property [{}] loaded from ServletContext.getInitParameter with value [{}]", configurationKey, value2); return value2; } return null; }
protected final String retrievePasswordFromResponse(final String proxyTicket) { final String url = this.clearPassUrl + (this.clearPassUrl.contains("?") ? "&" : "?") + "ticket=" + proxyTicket; final String response = retrieveResponseFromServer(url, "UTF-8"); final String password = XmlUtils.getTextForElement(response, "credentials"); if (log.isTraceEnabled()) { log.trace(String.format("ClearPass Response was:\n %s", response)); } if (CommonUtils.isNotBlank(password)) { return password; } log.error("Unable to Retrieve Password. If you see a [403] HTTP response code returned from the CommonUtils then it most likely means the proxy configuration on the CAS server is not correct.\n\n" + "Full Response from ClearPass was [" + response + "]."); return null; }
/** * Determines whether the given request is a CAS logout request. * * @param request HTTP request. * @return True if request is logout request, false otherwise. */ public boolean isLogoutRequest(final HttpServletRequest request) { return "POST".equals(request.getMethod()) && CommonUtils.isNotBlank( CommonUtils.safeGetParameter( request, ConfigurationKeys.LOGOUT_PARAMETER_NAME.getDefaultValue())); }
@Override protected final String get(final ConfigurationKey configurationKey) { if (context == null) { return null; } final String propertyName = configurationKey.getName(); final String filterValue = loadFromContext(context, this.environmentPrefix + this.simpleFilterName + "/" + propertyName); if (CommonUtils.isNotBlank(filterValue)) { logger.info("Property [{}] loaded from JNDI Filter Specific Property with value [{}]", propertyName, filterValue); return filterValue; } final String rootValue = loadFromContext(context, this.environmentPrefix + propertyName); if (CommonUtils.isNotBlank(rootValue)) { logger.info("Property [{}] loaded from JNDI with value [{}]", propertyName, rootValue); return rootValue; } return null; }
public void setAsText(final String text) throws IllegalArgumentException { final BufferedReader reader = new BufferedReader(new StringReader(text)); final List<String[]> proxyChains = new ArrayList<String[]>(); try { String line; while ((line = reader.readLine()) != null) { if (CommonUtils.isNotBlank(line)) { proxyChains.add(line.trim().split(" ")); } } } catch (final IOException e) { // ignore this } finally { try { reader.close(); } catch (final IOException e) { // nothing to do } } setValue(new ProxyList(proxyChains)); } }
public void setAsText(final String text) throws IllegalArgumentException { final BufferedReader reader = new BufferedReader(new StringReader(text)); final List proxyChains = new ArrayList(); try { String line; while ((line = reader.readLine()) != null) { if (CommonUtils.isNotBlank(line)) { proxyChains.add(line.trim().split(" ")); } } } catch (final IOException e) { // ignore this } finally { try { reader.close(); } catch (final IOException e) { // nothing to do } } setValue(new ProxyList(proxyChains)); } }
protected String get(final ConfigurationKey key) { final String value1 = this.webXmlConfigurationStrategy.get(key); if (CommonUtils.isNotBlank(value1)) { return value1; } return this.jndiConfigurationStrategy.get(key); } }
/** * Determines whether the given request is a CAS logout request. * * @param request HTTP request. * * @return True if request is logout request, false otherwise. */ private boolean isLogoutRequest(final HttpServletRequest request) { if ("POST".equalsIgnoreCase(request.getMethod())) { return !isMultipartRequest(request) && pathEligibleForLogout(request) && CommonUtils.isNotBlank(CommonUtils.safeGetParameter(request, this.logoutParameterName, this.safeParameters)); } if ("GET".equalsIgnoreCase(request.getMethod())) { return CommonUtils.isNotBlank(CommonUtils.safeGetParameter(request, this.logoutParameterName, this.safeParameters)); } return false; }
protected String retrieveResponseFromServer(final URL validationUrl, final String ticket) { final String request = String.format( SAML_REQUEST_TEMPLATE, generateId(), SamlUtils.formatForUtcTime(new Date()), ticket); HttpURLConnection conn = null; try { conn = this.getURLConnectionFactory().buildHttpURLConnection(validationUrl.openConnection()); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "text/xml"); conn.setRequestProperty("SOAPAction", "http://www.oasis-open.org/committees/security"); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); final Charset charset = CommonUtils.isNotBlank(getEncoding()) ? Charset.forName(getEncoding()) : IOUtils.UTF8; conn.getOutputStream().write(request.getBytes(charset)); return IOUtils.readString(conn.getInputStream(), charset); } catch (final IOException e) { throw new RuntimeException("IO error sending HTTP request to /samlValidate", e); } finally { if (conn != null) { conn.disconnect(); } } }
public void testIsNotBlank() { assertTrue(CommonUtils.isNotBlank("test")); assertTrue(CommonUtils.isNotBlank(" test")); assertFalse(CommonUtils.isNotBlank("")); assertFalse(CommonUtils.isNotBlank(null)); assertFalse(CommonUtils.isNotBlank(" ")); }
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; }
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; }