List of usage examples for org.apache.shiro.util StringUtils hasText
public static boolean hasText(String str)
From source file:org.springframework.data.gemfire.config.annotation.support.AutoConfiguredAuthenticationInitializer.java
License:Apache License
@Override protected Properties doGetCredentials(Properties properties) { getEnvironment()/*from ww w . j av a 2 s .c o m*/ .filter(environment -> StringUtils.hasText(environment.getProperty(SDG_SECURITY_USERNAME_PROPERTY))) .ifPresent(environment -> { String securityUsername = environment.getProperty(SDG_SECURITY_USERNAME_PROPERTY); String securityPassword = environment.getProperty(SDG_SECURITY_PASSWORD_PROPERTY); properties.setProperty(SECURITY_USERNAME_PROPERTY, securityUsername); properties.setProperty(SECURITY_PASSWORD_PROPERTY, securityPassword); }); return properties; }
From source file:org.springframework.data.gemfire.listener.ContinuousQueryDefinition.java
License:Apache License
/** * Determines whether the CQ was named./*from ww w .j a v a 2 s. co m*/ * * @return a boolean value indicating whether the CQ is named. * @see #getName() */ public boolean isNamed() { return StringUtils.hasText(getName()); }
From source file:org.springframework.geode.boot.autoconfigure.condition.OnMissingPropertyCondition.java
License:Apache License
private String getPrefix(AnnotationAttributes annotationAttributes) { String prefix = annotationAttributes.getString("prefix"); return StringUtils.hasText(prefix) ? prefix.trim().endsWith(".") ? prefix.trim() : prefix.trim() + "." : ""; }
From source file:org.tolven.shiro.web.filter.mgt.TolvenFilterChainResolver.java
License:Open Source License
@Override public FilterChain getChain(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain originalChain) {/*from w w w. java 2s .c om*/ String requestURI = getPathWithinApplication(servletRequest); HttpServletRequest request = (HttpServletRequest) servletRequest; String urlMethod = request.getMethod(); if (logger.isDebugEnabled()) { logger.debug("requestURI=" + urlMethod + " " + requestURI); } TolvenAuthorization authz = getAuthBean().getAuthorization(urlMethod, request.getContextPath(), requestURI); if (authz == null) { throw new RuntimeException( "authorization url cannot be found for request: " + urlMethod + " " + requestURI); } if (logger.isDebugEnabled()) { logger.debug("Matched TolvenAuthorization=" + authz); } String authorizationURI = authz.getUrl(); if (!StringUtils.hasText(authorizationURI)) { throw new RuntimeException( "authorization url cannot be null or empty for request: " + urlMethod + " " + requestURI); } String filterString = authz.getFilters(); if (filterString == null || filterString.trim().length() == 0) { return originalChain; } else { DefaultFilterChainManager temporaryManager = new DefaultFilterChainManager(getFilterConfig()); boolean init = getFilterConfig() != null; //only call filter.init if there is a FilterConfig available if (logger.isDebugEnabled()) { logger.debug("Adding filters to temporary manager"); } Map<String, Filter> filters = null; try { filters = getFilters(filterString); } catch (Exception ex) { throw new RuntimeException("Failed to get chain filters for: " + request.getContextPath(), ex); } for (Entry<String, Filter> entry : filters.entrySet()) { temporaryManager.addFilter(entry.getKey(), entry.getValue(), init); } if (logger.isDebugEnabled()) { logger.debug("Added filters to temporary manager"); } try { temporaryManager.createChain(authorizationURI, filterString); } catch (Exception ex) { throw new RuntimeException("Could not create chain: " + authorizationURI + " for filters: " + filterString + " in context: " + getFilterConfig().getServletContext().getContextPath(), ex); } if (logger.isDebugEnabled()) { logger.debug("Created filter chain: " + authorizationURI + " with " + filterString); } NamedFilterList chain = temporaryManager.getChain(authorizationURI); return chain.proxy(originalChain); } }
From source file:org.tolven.web.security.AccountFilter.java
License:Open Source License
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException { String redirect = (String) request.getAttribute(GeneralSecurityFilter.TOLVEN_REDIRECT); if (StringUtils.hasText(redirect)) { WebUtils.issueRedirect(request, response, redirect); } else {/* w ww.j av a 2s.c o m*/ WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED); } return false; }
From source file:org.tynamo.security.components.LoginForm.java
License:Apache License
@OnEvent(value = EventConstants.SUCCESS, component = LOGIN_FORM_ID) public Object onSuccessfulLogin() throws IOException { if (StringUtils.hasText(successURL)) { if ("^".equals(successURL)) return pageRenderLinkSource.createPageRenderLink(componentResources.getPage().getClass()); return new URL(successURL); }/*ww w . jav a 2 s. c o m*/ if (redirectToSavedUrl) { String requestUri = loginContextService.getSuccessPage(); if (!requestUri.startsWith("/") && !requestUri.startsWith("http")) { requestUri = "/" + requestUri; } loginContextService.redirectToSavedRequest(requestUri); return null; } return loginContextService.getSuccessPage(); }
From source file:org.tynamo.security.shiro.authz.AuthorizationFilter.java
License:Apache License
/** * Handles the response when access has been denied. It behaves as follows: * <ul>// w w w.ja v a 2s . co m * <li>If the {@code Subject} is unknown<sup><a href="#known">[1]</a></sup>: * <ol><li>The incoming request will be saved and they will be redirected to the login page for authentication * (via the {@link #saveRequestAndRedirectToLogin(javax.servlet.ServletRequest, javax.servlet.ServletResponse)} * method).</li> * <li>Once successfully authenticated, they will be redirected back to the originally attempted page.</li></ol> * </li> * <li>If the Subject is known:</li> * <ol> * <li>The HTTP {@link HttpServletResponse#SC_UNAUTHORIZED} header will be set (401 Unauthorized)</li> * <li>If the {@link #getUnauthorizedUrl() unauthorizedUrl} has been configured, a redirect will be issued to that * URL. Otherwise the 401 response is rendered normally</li> * </ul> * <code><a name="known">[1]</a></code>: A {@code Subject} is 'known' when * <code>subject.{@link org.apache.shiro.subject.Subject#getPrincipal() getPrincipal()}</code> is not {@code null}, * which implicitly means that the subject is either currently authenticated or they have been remembered via * 'remember me' services. * * @param request the incoming <code>ServletRequest</code> * @param response the outgoing <code>ServletResponse</code> * @return {@code false} always for this implementation. * @throws IOException if there is any servlet error. */ protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException { Subject subject = getSubject(request, response); // If the subject isn't identified, redirect to login URL if (subject.getPrincipal() == null) { saveRequestAndRedirectToLogin(request, response); } else { // If subject is known but not authorized, redirect to the unauthorized URL if there is one // If no unauthorized URL is specified, just return an unauthorized HTTP status code String unauthorizedUrl = getUnauthorizedUrl(); //SHIRO-142 - ensure that redirect _or_ error code occurs - both cannot happen due to response commit: if (StringUtils.hasText(unauthorizedUrl)) { WebUtils.issueRedirect(request, response, unauthorizedUrl); } else { WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED); } } return false; }
From source file:org.tynamo.security.ShiroExceptionHandler.java
License:Apache License
/** * TODO: Make configurable strategies objects for ShiroException *//*from w w w . jav a 2 s.c o m*/ public void handle(ShiroException exception) throws IOException { if (securityService.isAuthenticated()) { String unauthorizedPage = pageService.getUnauthorizedPage(); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); if (!StringUtils.hasText(unauthorizedPage)) { return; } Component page = componentSource.getPage(unauthorizedPage); reportExceptionIfPossible(exception, page); renderer.renderPageMarkupResponse(unauthorizedPage); } else { Subject subject = securityService.getSubject(); if (subject != null) { Session session = subject.getSession(); if (session != null) { WebUtils.saveRequest(requestGlobals.getHTTPServletRequest()); } } Component page = componentSource.getPage(pageService.getLoginPage()); reportExceptionIfPossible(exception, page); renderer.renderPageMarkupResponse(pageService.getLoginPage()); } }
From source file:org.xinta.eazycode.components.shiro.web.validator.EditUserValidator.java
License:Apache License
public void validate(Object o, Errors errors) { EditUserVO command = (EditUserVO) o; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginName", "error.loginName.empty", "Please specify a loginName."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "error.email.empty", "Please specify an email address."); if (StringUtils.hasText(command.getEmail()) && !Pattern.matches(SIMPLE_EMAIL_REGEX, command.getEmail().toUpperCase())) { errors.rejectValue("email", "error.email.invalid", "Please enter a valid email address."); }//from ww w . j av a2 s .c o m }
From source file:org.xinta.eazycode.components.shiro.web.validator.SignupValidator.java
License:Apache License
public void validate(Object o, Errors errors) { SignupVO command = (SignupVO) o;//w w w . j ava 2s. com ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginName", "error.username.empty", "Please specify a loginName."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.username.empty", "Please specify a loginName."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "error.email.empty", "Please specify an email address."); if (StringUtils.hasText(command.getEmail()) && !Pattern.matches(SIMPLE_EMAIL_REGEX, command.getEmail().toUpperCase())) { errors.rejectValue("email", "error.email.invalid", "Please enter a valid email address."); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password.empty", "Please specify a password."); }