List of usage examples for org.apache.shiro SecurityUtils getSecurityManager
public static SecurityManager getSecurityManager() throws UnavailableSecurityManagerException
From source file:info.novatec.inspectit.cmr.security.SessionAwarePermissionsAuthorizationFilter.java
License:Apache License
/** * Is the subject who created the request permitted? * //from w w w. j av a 2 s . c om * @param request * Servlet request * @param response * Servlet response * @param mappedValue * Permissions * @throws IOException * IOException * @return Returns whether request has permission to proceed * */ @Override public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException { // This is the most relevant modified part, where the sessionid is extracted from the header and the subject is build manually. if (!(request instanceof HttpServletRequest)) { throw new IOException("Invalid http request."); } String sessionid = ((HttpServletRequest) request).getHeader("sessionid"); Subject subject = new Subject.Builder(SecurityUtils.getSecurityManager()) .sessionId((Serializable) sessionid).buildSubject(); String[] perms = (String[]) mappedValue; boolean isPermitted = true; if (perms != null && perms.length > 0) { if (perms.length == 1) { if (!subject.isPermitted(perms[0])) { isPermitted = false; } } else { if (!subject.isPermittedAll(perms)) { isPermitted = false; } } } return isPermitted; }
From source file:juzu.plugin.shiro.impl.SecurityManagerProvider.java
License:Open Source License
public SecurityManager get() { SecurityManager manager = null; try {/*from www .j a v a 2s. c om*/ manager = SecurityUtils.getSecurityManager(); } catch (UnavailableSecurityManagerException e1) { manager = new DefaultSecurityManager(); } boolean rememberMeSupported = config.get("rememberMe") != null ? true : false; if (rememberMeSupported && manager instanceof DefaultSecurityManager) { ((DefaultSecurityManager) manager).setRememberMeManager(new JuzuRememberMe()); } if (config.get("realms") != null) { try { injectRealms(config, manager, Request.getCurrent().getApplication().getInjectionContext()); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } return manager; }
From source file:lib.security.LocalAdminUserRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { final AuthenticationInfo authenticationInfo = super.doGetAuthenticationInfo(token); // if we could authenticate the user with this realm, it is the local admin user. // set the request's current user to be the shared instance, so we don't blow everything up trying to retrieve it from the server. if (authenticationInfo != null) { if (!(token instanceof UsernamePasswordToken)) { throw new IllegalStateException("Only supports UsernamePasswordToken"); }// w w w . ja va 2 s .c om UsernamePasswordToken userPass = (UsernamePasswordToken) token; UserService.setCurrent(LocalAdminUser.getInstance()); final String sessionid = Crypto .encryptAES(userPass.getUsername() + "\t" + new String(userPass.getPassword())); Http.Context.current().session().put("sessionid", sessionid); new Subject.Builder(SecurityUtils.getSecurityManager()).authenticated(true).buildSubject(); } return authenticationInfo; }
From source file:lib.security.ServerRestInterfaceRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authToken) throws AuthenticationException { final UserResponse response; // we don't handle any other type, see constructor @SuppressWarnings("CastToConcreteClass") SessionIdAuthenticationToken token = (SessionIdAuthenticationToken) authToken; try {/* w ww.ja va2 s . c o m*/ final String sessionId = token.getPrincipal().toString(); response = api.get(UserResponse.class).path("/users/{0}", token.getUsername()).session(sessionId) .execute(); final User user = userFactory.fromResponse(response, sessionId); UserService.setCurrent(user); user.setSubject(new Subject.Builder(SecurityUtils.getSecurityManager()) .principals(new SimplePrincipalCollection(user.getName(), "REST realm")).authenticated(true) .buildSubject()); } catch (IOException e) { throw new Graylog2ServerUnavailableException("Could not connect to Graylog Server.", e); } catch (APIException e) { if (e.getCause() != null && e.getCause() instanceof ConnectException) { throw new Graylog2ServerUnavailableException("Could not connect to Graylog Server.", e); } else { throw new AuthenticationException("Unable to communicate with graylog2-server backend", e); } } catch (PlayException e) { log.error( "Misconfigured play application. Please make sure your application.secret is longer than 16 characters!", e); throw new RuntimeException(e); } return new SimpleAuthenticationInfo(response.username, null, "rest-interface"); }
From source file:net.felsing.client_cert.Login.java
License:Open Source License
private void cleanUp(Session sessionId) { DefaultSecurityManager securityManager = (DefaultSecurityManager) SecurityUtils.getSecurityManager(); DefaultSessionManager sessionManager = (DefaultSessionManager) securityManager.getSessionManager(); Collection<Session> activeSessions = sessionManager.getSessionDAO().getActiveSessions(); for (Session session : activeSessions) { if (sessionId.equals(session.getId())) { session.stop();//from w w w.j a va 2 s .c o m } } }
From source file:org.apache.geode.internal.security.IntegratedSecurityService.java
License:Apache License
/** * check if Shiro's security manager is configured * /*from w w w . jav a2s. c om*/ * @return true if configured, false if not */ public boolean isIntegratedSecurity() { if (isIntegratedSecurity != null) { return isIntegratedSecurity; } try { isIntegratedSecurity = (SecurityUtils.getSecurityManager() != null); } catch (UnavailableSecurityManagerException e) { isIntegratedSecurity = false; } return isIntegratedSecurity; }
From source file:org.apache.geode.internal.security.SecurityServiceFactory.java
License:Apache License
private static boolean isShiroInUse() { try {//from w w w .j av a 2 s . c o m return SecurityUtils.getSecurityManager() != null; } catch (UnavailableSecurityManagerException ignore) { return false; } }
From source file:org.apache.geode.internal.security.shiro.SecurityManagerProvider.java
License:Apache License
public SecurityManagerProvider() { shiroManager = SecurityUtils.getSecurityManager(); }
From source file:org.apache.isis.security.shiro.ShiroAuthenticatorOrAuthorizor.java
License:Apache License
/** * The {@link SecurityManager} is shared between both the {@link Authenticator} and the {@link Authorizor} * (if shiro is configured for both components). *///from w w w . j ava 2 s . co m private static synchronized RealmSecurityManager getSecurityManager() { SecurityManager securityManager; try { securityManager = SecurityUtils.getSecurityManager(); } catch (UnavailableSecurityManagerException ex) { return null; } if (!(securityManager instanceof RealmSecurityManager)) { return null; } return (RealmSecurityManager) securityManager; }
From source file:org.apache.usergrid.security.CustomResolverTest.java
License:Apache License
@AfterClass public static void tearDownShiro() { doClearSubject();//from ww w. j a va 2 s . com try { org.apache.shiro.mgt.SecurityManager securityManager = SecurityUtils.getSecurityManager(); LifecycleUtils.destroy(securityManager); } catch (UnavailableSecurityManagerException e) { // we don't care about this when cleaning up the test environment // (for example, maybe the subclass is a unit test and it didn't // need a SecurityManager instance because it was using only // mock Subject instances) } SecurityUtils.setSecurityManager(null); }