List of usage examples for org.apache.shiro.cache Cache remove
public V remove(K key) throws CacheException;
From source file:apm.modules.sys.security.SystemAuthorizingRealm.java
License:Open Source License
/** * ??/*from w ww.j a va 2s . com*/ */ public void clearAllCachedAuthorizationInfo() { Cache<Object, AuthorizationInfo> cache = getAuthorizationCache(); if (cache != null) { for (Object key : cache.keys()) { cache.remove(key); } } }
From source file:br.com.criativasoft.opendevice.wsrest.resource.OAuthRest.java
License:Open Source License
@POST @Path("/token") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON)// ww w .j a v a 2 s . com public Response tokenPost(@Context HttpServletRequest request, MultivaluedMap<String, String> formParams) throws OAuthSystemException { OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator()); Long userAccountID; try { OAuthTokenRequest oauthRequest = new OAuthTokenRequest( new ParameterizedHttpRequest(request, formParams)); DefaultSecurityManager securityManager = (DefaultSecurityManager) SecurityUtils.getSecurityManager(); Cache<Object, Object> cache = securityManager.getCacheManager() .getCache(AuthenticationFilter.TOKEN_CACHE); String clientID = oauthRequest.getParam(OAuth.OAUTH_CLIENT_ID); // do checking for different grant types if (GrantType.AUTHORIZATION_CODE.toString().equals(oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE))) { String codeParam = oauthRequest.getParam(OAuth.OAUTH_CODE); userAccountID = (Long) cache.get(codeParam); if (userAccountID == null) { OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST) .setError(OAuthError.TokenResponse.INVALID_GRANT) .setErrorDescription("invalid authorization code").buildJSONMessage(); return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); } else { cache.remove(codeParam); // not required anymore } } // else if ( // oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.PASSWORD.toString())) // { // if (!Common.PASSWORD.equals(oauthRequest.getPassword()) // ||!Common.USERNAME.equals(oauthRequest.getUsername())) // { // OAuthResponse response = // OAuthASResponse.errorResponse( // HttpServletResponse.SC_BAD_REQUEST).setError( // OAuthError.TokenResponse.INVALID_GRANT).setErrorDescription( // "invalid username or password").buildJSONMessage(); // // return Response.status(response.getResponseStatus()).entity( // response.getBody()).build(); // } else if (GrantType.REFRESH_TOKEN.toString().equals(oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE))) { String key = oauthRequest.getParam(OAuth.OAUTH_REFRESH_TOKEN); UserAccount account = accountDao.getUserAccountByApiKey(key); if (account == null) { OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST) .setError(OAuthError.TokenResponse.INVALID_GRANT) .setErrorDescription("Invalid REFRESH_TOKEN").buildJSONMessage(); return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); } else { userAccountID = account.getId(); } } else { throw OAuthProblemException.error("Invalid Rrequest"); } String accessToken = oauthIssuerImpl.accessToken(); // This token will be handled by AuthenticationFilter UserAccount userAccount = accountDao.getUserAccountByID(userAccountID); ApiKey apiKeyUser = userAccount.getKeys().iterator().next(); cache.put(accessToken, apiKeyUser.getKey()); OAuthResponse response = OAuthASResponse.tokenResponse(HttpServletResponse.SC_OK) .setAccessToken(accessToken).setRefreshToken(apiKeyUser.getKey()).setExpiresIn("3600") .buildJSONMessage(); return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); } catch (OAuthProblemException e) { OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e) .buildJSONMessage(); return Response.status(res.getResponseStatus()).entity(res.getBody()).build(); } }
From source file:com.aistor.modules.sys.security.SystemRealm.java
License:Open Source License
/** * ??//from w w w .jav a2s . c o m */ public void clearAllCachedAuthorizationInfo() { Cache<Object, AuthorizationInfo> cache = getAuthorizationCache(); if (cache != null) { for (Object key : cache.keys()) { cache.remove(key); } } UserUtils.removeCache("menuList"); UserUtils.removeCache("categoryList"); }
From source file:com.baguaz.module.user.realm.AdminAuthorizingRealm.java
License:Apache License
public void clearCachedAuthenInfo(PrincipalCollection principals) { UserPrincipal pp = (UserPrincipal) getAvailablePrincipal(principals); UsernamePasswordToken token = new UsernamePasswordToken(pp.getUserName(), pp.getUser().getStr("password")); Cache<Object, AuthenticationInfo> cache = this.getAuthenticationCache(); if (cache != null) { Object key = this.getAuthenticationCacheKey(token); cache.remove(key); }//from w w w.j ava 2s. co m }
From source file:com.funtl.framework.core.utils.CacheUtils.java
License:Apache License
/** * //from w ww .j a va 2s . c om * * @param cacheName */ public static void removeAll(String cacheName) { Cache<String, Object> cache = getCache(cacheName); Set<String> keys = cache.keys(); for (Iterator<String> it = keys.iterator(); it.hasNext();) { cache.remove(it.next()); } logger.info("? {} => {}", cacheName, keys); }
From source file:com.zht.common.shiro.realm.ShiroDbRealm.java
License:Apache License
/** * ??.//from www. j av a 2s .c o m */ public void clearAllCachedAuthorizationInfo() { Cache<Object, AuthorizationInfo> cache = getAuthorizationCache(); if (cache != null && cache.size() > 0) { Set<?> keys = cache.keys(); for (Object key : keys) { cache.remove(key); } } }
From source file:org.smartloli.kafka.eagle.web.sso.filter.SSORealm.java
License:Apache License
public void clearAllCached() { Cache<Object, AuthorizationInfo> cache = this.getAuthorizationCache(); if (cache != null) { for (Object key : cache.keys()) { cache.remove(key); }/*from ww w .j a v a 2 s .c om*/ } LOG.info("SSOReaml - Clear all cached principal."); }