List of usage examples for org.apache.shiro SecurityUtils getSecurityManager
public static SecurityManager getSecurityManager() throws UnavailableSecurityManagerException
From source file:org.openiot.security.client.AccessControlUtil.java
License:Open Source License
protected ClientRealm getCasOAuthClientRealm() { if (clientRealm == null) { SecurityManager securityManager = SecurityUtils.getSecurityManager(); logger.debug("Security manager class :{} ", securityManager.getClass()); RealmSecurityManager realmSecurityManager = (RealmSecurityManager) securityManager; Collection<Realm> realms = realmSecurityManager.getRealms(); for (Realm realm : realms) if (realm instanceof ClientRealm) { logger.debug("A realm of type {} was found", realm.getClass().getName()); clientRealm = (ClientRealm) realm; break; }/*from w ww. j a v a 2 s .c o m*/ } return clientRealm; }
From source file:org.ow2.proactive.workflowcatalog.SchedulerAuthentication.java
License:Open Source License
private static Subject createSubject(String token, ISchedulerProxy scheduler) { SessionContext sessionContext = new DefaultSessionContext(); sessionContext.setSessionId(token);/*from w ww .j a v a 2 s. co m*/ sessionContext.put(HttpHeaderTokenSessionManager.TOKEN_KEY, token); sessionContext.put(SchedulerRestSession.SCHEDULER_SESSION_KEY, scheduler); Session session = SecurityUtils.getSecurityManager().start(sessionContext); return new Subject.Builder().session(session).buildSubject(); }
From source file:org.pepstock.jem.gwt.server.RolesManagerServiceImpl.java
License:Open Source License
/** * This method clears all authorizations cache when a role is changed.<br> * That's necessary to invalidate the cache and then to have the updates * soon available./*w ww.jav a 2 s . c om*/ */ private void clearAuthorizationCache() { RealmSecurityManager mgr = (RealmSecurityManager) SecurityUtils.getSecurityManager(); Collection<Realm> realmCollection = mgr.getRealms(); for (Realm realm : realmCollection) { if (realm instanceof AuthorizingRealm) { AuthorizingRealm authz = (AuthorizingRealm) realm; if (authz.isAuthorizationCachingEnabled()) { authz.getAuthorizationCache().clear(); } } } }
From source file:org.sonatype.nexus.coreui.internal.wonderland.AuthenticateResource.java
License:Open Source License
/** * Authenticate a specific user and generate a one-time-use authentication token. * * @param token User authentication details. * @return Authentication ticket.//from w w w . j a va2 s. c o m */ @POST @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public AuthTicketXO post(final AuthTokenXO token) { checkNotNull(token); final String username = Strings2.decodeBase64(token.getU()); final String password = Strings2.decodeBase64(token.getP()); // Require current user to be the requested user to authenticate final Subject subject = SecurityUtils.getSubject(); final Object principal = subject.getPrincipal(); final String principalName = principal == null ? "" : principal.toString(); if (log.isDebugEnabled()) { log.debug("payload username: {}, payload password: {}, principal: {}", username, Strings2.mask(password), principalName); } if (!principalName.equals(username)) { log.warn("auth token request denied - authenticated user {} does not match payload user {}", principalName, username); throw new WebApplicationException("Username mismatch", Status.BAD_REQUEST); } // Ask the sec-manager to authenticate, this won't alter the current subject try { SecurityUtils.getSecurityManager().authenticate(new UsernamePasswordToken(username, password)); } catch (AuthenticationException e) { log.trace("Authentication failed", e); throw new WebApplicationException("Authentication failed", Status.FORBIDDEN); } // At this point we should be authenticated, return a new ticket return new AuthTicketXO().withT(authTickets.createTicket()); }
From source file:org.sonatype.nexus.security.SecurityHelper.java
License:Open Source License
/** * Returns current security manager. */ public SecurityManager getSecurityManager() { return SecurityUtils.getSecurityManager(); }
From source file:pe.gob.sunat.tecnologia3.arquitectura.framework.desktop.seguridad.Autenticador.java
public void logout() { SecurityUtils.getSecurityManager().logout(currentUser); }
From source file:plugin.shiro.require.controller2.A.java
License:Open Source License
@View @Route("/")//from w w w. ja v a2 s .c o m public Response index(AuthorizationException e) { AuthcWithRequireAtCtrlTestCase.manager = (DefaultSecurityManager) SecurityUtils.getSecurityManager(); AuthcWithRequireAtCtrlTestCase.exception = e; return Response.ok("<a href='" + A_.login("foo", "foo") + "' id='failed'>failed</a>" + "<a href='" + A_.login("root", "secret") + "' id='login'>login</a>" + "<a href='" + A_.logout() + "' id='logout'>logout</a>"); }
From source file:ru.ppsrk.gwt.server.AuthServiceImpl.java
License:Open Source License
public static GwtUtilRealm getRealm() throws LogicException { Iterator<Realm> realms = ((RealmSecurityManager) SecurityUtils.getSecurityManager()).getRealms().iterator(); Realm realm = realms.next();//from w ww. j a v a2 s .c o m if (!(realm instanceof GwtUtilRealm)) { throw new LogicException("Realm " + realm.getName() + " isn't compatible to GwtUtilRealm, its type is: " + realm.getClass().getSimpleName()); } return (GwtUtilRealm) realm; }
From source file:uk.ac.ox.it.ords.security.AbstractShiroTest.java
License:Apache License
/** * Get the security manager for testing with * @return a security manager instance// ww w .ja v a2 s . c o m */ protected static SecurityManager getSecurityManager() { return SecurityUtils.getSecurityManager(); }
From source file:uk.co.q3c.v7.base.guice.GuiceServletInjectorTest.java
License:Apache License
@Test public void configure() { // given/*from ww w . j a va 2s .c o m*/ when(thread_local_servletContext.get()).thenReturn(servletContext); when(servletContextEvent.getServletContext()).thenReturn(servletContext); out.contextInitialized(servletContextEvent); // when Injector injector = out.getInjector(); // then assertThat(SecurityUtils.getSecurityManager()).isInstanceOf(V7SecurityManager.class); }