List of usage examples for org.apache.shiro.util StringUtils clean
public static String clean(String in)
From source file:com.leshazlewood.samples.shiromt.web.tenant.SubdomainTenantResolver.java
License:Apache License
public void setBaseDomain(String baseDomain) { //performance optimization - add the '.' prefix here in case there isn't one //this way, we don't need to do the checking during the resolveTenant invocations //This is a minor adjustment, but if servicing thousands of requests, this will help over over time String base = StringUtils.clean(baseDomain); if (base != null) { base = base.toLowerCase();//from w w w . j av a2s .c o m } if (base != null && !base.startsWith(".")) { base = "." + base; } this.baseDomain = base; }
From source file:com.rekoe.shiro.web.SimpleCookie.java
License:Apache License
/** * Returns the Cookie's calculated path setting. If the * {@link javax.servlet.http.Cookie#getPath() path} is {@code null}, then * the {@code request}'s/* w w w . ja va2s. c o m*/ * {@link javax.servlet.http.HttpServletRequest#getContextPath() context * path} will be returned. If getContextPath() is the empty string or null * then the ROOT_PATH constant is returned. * * @param request * the incoming HttpServletRequest * @return the path to be used as the path when the cookie is created or * removed */ private String calculatePath(HttpServletRequest request) { String path = StringUtils.clean(getPath()); if (!StringUtils.hasText(path)) { if (Lang.isEmpty(request)) { return ROOT_PATH; } path = StringUtils.clean(request.getContextPath()); } // fix for http://issues.apache.org/jira/browse/SHIRO-9: if (path == null) { path = ROOT_PATH; } log.trace("calculated path: {}", path); return path; }
From source file:com.stormpath.sample.impl.converters.DefaultMapValueRetriever.java
License:Apache License
private <T> T tryStringToInstanceConversion(String propertyName, String propertyValue, Class<T> targetClass) { Converter<String, ?> converter = converterMap.get(targetClass); Assert.notNull(converter, "There is not converter for class: " + targetClass); try {//www. j ava 2 s.c o m String cleanValue = StringUtils.clean(propertyValue); return (T) converter.convert(cleanValue); } catch (RuntimeException re) { throw new ClientValidationException(Error.INVALID_VALUE, propertyName); } }
From source file:com.stormpath.sample.security.SampleApplicationRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { if (authcToken instanceof UsernamePasswordToken) { return super.doGetAuthenticationInfo(authcToken); }/*from w w w.j a v a2s . c o m*/ HttpRequestAuthenticationToken token = (HttpRequestAuthenticationToken) authcToken; Application application = ensureApplicationReference(); AccountResult accountResult; try { accountResult = application.newIdSiteCallbackHandler(token.getHttpServletRequest()).getAccountResult(); } catch (ResourceException | InvalidJwtException | IllegalArgumentException e) { String msg = StringUtils.clean(e.getMessage()); if (msg == null) { msg = "Invalid SSO Request"; } throw new AuthenticationException(msg, e); } PrincipalCollection principals; try { principals = createPrincipals(accountResult.getAccount()); } catch (Exception e) { throw new AuthenticationException("Unable to obtain authenticated account properties.", e); } return new SimpleAuthenticationInfo(principals, null); }
From source file:com.stormpath.shiro.realm.ApplicationRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { assertState();//from w w w. ja va2 s .c o m UsernamePasswordToken token = (UsernamePasswordToken) authcToken; AuthenticationRequest request = createAuthenticationRequest(token); Application application = ensureApplicationReference(); Account account; try { account = application.authenticateAccount(request).getAccount(); } catch (ResourceException e) { //todo error code translation to throw more detailed exceptions String msg = StringUtils.clean(e.getMessage()); if (msg == null) { msg = StringUtils.clean(e.getDeveloperMessage()); } if (msg == null) { msg = "Invalid login or password."; } throw new AuthenticationException(msg, e); } PrincipalCollection principals; try { principals = createPrincipals(account); } catch (Exception e) { throw new AuthenticationException("Unable to obtain authenticated account properties.", e); } return new SimpleAuthenticationInfo(principals, null); }
From source file:com.stormpath.shiro.realm.ApplicationRealm.java
License:Apache License
private void nullSafePut(Map<String, String> props, String propName, String value) { value = StringUtils.clean(value); if (value != null) { props.put(propName, value);//from ww w . j a va2s. co m } }
From source file:com.stormpath.shiro.realm.JWTApplicationRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { assertState();/*from w ww . ja v a 2 s .co m*/ JwtAuthenticationToken token = (JwtAuthenticationToken) authcToken; OAuthBearerRequestAuthentication request = createAuthenticationRequest(token); Application application = ensureApplicationReference(); Account account; try { OAuthBearerRequestAuthenticationResult res = Authenticators.OAUTH_BEARER_REQUEST_AUTHENTICATOR .forApplication(application).authenticate(request); //account = application.authenticateAccount(request).getAccount(); account = res.getAccount(); } catch (ResourceException e) { //todo error code translation to throw more detailed exceptions String msg = StringUtils.clean(e.getMessage()); if (msg == null) { msg = StringUtils.clean(e.getDeveloperMessage()); } if (msg == null) { msg = "Invalid login or password."; } throw new AuthenticationException(msg, e); } PrincipalCollection principals; try { principals = createPrincipals(account); } catch (Exception e) { throw new AuthenticationException("Unable to obtain authenticated account properties.", e); } return new SimpleAuthenticationInfo(principals, null); }
From source file:org.seedstack.seed.web.internal.security.SecurityWebModule.java
License:Open Source License
/** * This method is copied from the same method in Shiro in class DefaultFilterChainManager. *//*w ww.ja v a 2s.com*/ private String[] toNameConfigPair(String token) throws ConfigurationException { String[] pair = token.split("\\[", 2); String name = StringUtils.clean(pair[0]); if (name == null) { throw new IllegalArgumentException("Filter name not found for filter chain definition token: " + token); } String config = null; if (pair.length == 2) { config = StringUtils.clean(pair[1]); //if there was an open bracket, it assumed there is a closing bracket, so strip it too: config = config.substring(0, config.length() - 1); config = StringUtils.clean(config); //backwards compatibility prior to implementing SHIRO-205: //prior to SHIRO-205 being implemented, it was common for end-users to quote the config inside brackets //if that config required commas. We need to strip those quotes to get to the interior quoted definition //to ensure any existing quoted definitions still function for end users: if (config != null && config.startsWith("\"") && config.endsWith("\"")) { String stripped = config.substring(1, config.length() - 1); stripped = StringUtils.clean(stripped); //if the stripped value does not have any internal quotes, we can assume that the entire config was //quoted and we can use the stripped value. if (stripped != null && stripped.indexOf('"') == -1) { config = stripped; } //else: //the remaining config does have internal quotes, so we need to assume that each comma delimited //pair might be quoted, in which case we need the leading and trailing quotes that we stripped //So we ignore the stripped value. } } return new String[] { name, config }; }
From source file:StormpathShiro.src.main.java.com.stormpath.shiro.realm.ApplicationRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { assertState();//from w ww. j a v a 2 s. c o m //UsernamePasswordToken token = (UsernamePasswordToken) authcToken; JwtAuthenticationToken token = (JwtAuthenticationToken) authcToken; OAuthBearerRequestAuthentication request = createAuthenticationRequest(token); Application application = ensureApplicationReference(); Account account; try { OAuthBearerRequestAuthenticationResult res = Authenticators.OAUTH_BEARER_REQUEST_AUTHENTICATOR .forApplication(application).authenticate(request); //account = application.authenticateAccount(request).getAccount(); account = res.getAccount(); //System.out.println("ACC: " + account); /*account.getCustomData().put("user", "edit"); System.out.println(account.getCustomData().get("user")); System.out.println("ACC2: " + account); account.getCustomData().save(); System.out.println("ACC3: " + account); //System.out.println(account.getCustomData().get("user"));*/ /*Iterator i = application.getGroups(Groups.where(Groups.name().eqIgnoreCase("Admin"))).iterator(); Group g = null; while (i.hasNext()) { g = (Group)i.next(); } g.getCustomData().put("admin", "create"); g.getCustomData().save();*/ } catch (ResourceException e) { //todo error code translation to throw more detailed exceptions String msg = StringUtils.clean(e.getMessage()); if (msg == null) { msg = StringUtils.clean(e.getDeveloperMessage()); } if (msg == null) { msg = "Invalid login or password."; } throw new AuthenticationException(msg, e); } PrincipalCollection principals; try { principals = createPrincipals(account); } catch (Exception e) { throw new AuthenticationException("Unable to obtain authenticated account properties.", e); } return new SimpleAuthenticationInfo(principals, null); }