List of usage examples for org.apache.shiro SecurityUtils getSecurityManager
public static SecurityManager getSecurityManager() throws UnavailableSecurityManagerException
From source file:com.attendance.manage.controller.LoginController.java
License:Open Source License
/** * ??//from ww w .j av a 2 s . c o m */ @RequestMapping(value = "/submit", method = RequestMethod.POST) public String submit(String username, String password, HttpServletRequest request, HttpServletResponse response, Model model, HttpSession session) { System.out.println("in con"); if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { model.addAttribute("massage", "????"); return ""; } Stuff stuff; stuff = stuffService.findByUsername(username); if (stuff == null) { model.addAttribute("message", "????"); return ""; } if (!password.equals(stuff.getPassword())) { model.addAttribute("message", "??"); return ""; } if (session.getAttribute("username") != null && session.getAttribute("username").equals(username)) { model.addAttribute("message", "???"); return ""; } SecurityUtils.getSecurityManager().logout(SecurityUtils.getSubject()); // ?shiro token UsernamePasswordToken token = new UsernamePasswordToken(stuff.getUsername(), stuff.getPassword()); Subject subject = SecurityUtils.getSubject(); subject.login(token); WebUtils.addCookie(request, response, Stuff.USERNAME_COOKIE_NAME, username); session = request.getSession(); session.setAttribute("username", username); model.addAttribute("massage", "success"); return ""; }
From source file:com.authlete.sample.server.security.Authenticator.java
License:Apache License
/** * Authenticate the resource owner.//from w w w. java 2 s .c o m * * @param username * The resource owner's user name. * * @param password * The resource owner's password. * * @return * The subject (unique identifier) of the user when he/she * was authenticated successfully. {@code null} when the * user was not authenticated. */ public static String authenticate(String username, String password) { // Pack the username and password into AuthenticationToken // which Apache Shiro's SecurityManager can accept. AuthenticationToken credentials = new UsernamePasswordToken(username, password); try { // Authenticate the resource owner using Apache Shiro. AuthenticationInfo info = SecurityUtils.getSecurityManager().authenticate(credentials); // Get the subject of the authenticated user. String subject = info.getPrincipals().getPrimaryPrincipal().toString(); // Successfully authenticated. return subject; } catch (AuthenticationException e) { // Authentication failed. String message = String.format("Authentication failed: username=%s, error=%s (%s)", username, e.getMessage(), e.getClass().getSimpleName()); // Emit a debug log message. Logger.getLogger(Authenticator.class.getName()).fine(message); // Not authenticated. return null; } }
From source file:com.baguaz.CacheFunc.java
License:Apache License
public static void clearMyCachedAuth() { DefaultWebSecurityManager dwsm = (DefaultWebSecurityManager) SecurityUtils.getSecurityManager(); AdminAuthorizingRealm aar = (AdminAuthorizingRealm) dwsm.getRealms().iterator().next(); PrincipalCollection pc = SecurityUtils.getSubject().getPrincipals(); aar.clearCachedAuthenInfo(pc);// w w w.j a v a2s .c om aar.clearCachedAuthorInfo(pc); }
From source file:com.baguaz.CacheFunc.java
License:Apache License
public static void clearMyCachedAuthenInfo() { DefaultWebSecurityManager dwsm = (DefaultWebSecurityManager) SecurityUtils.getSecurityManager(); AdminAuthorizingRealm aar = (AdminAuthorizingRealm) dwsm.getRealms().iterator().next(); aar.clearCachedAuthenInfo(SecurityUtils.getSubject().getPrincipals()); }
From source file:com.baguaz.CacheFunc.java
License:Apache License
public static void clearMyCachedAuthorInfo() { DefaultWebSecurityManager dwsm = (DefaultWebSecurityManager) SecurityUtils.getSecurityManager(); AdminAuthorizingRealm aar = (AdminAuthorizingRealm) dwsm.getRealms().iterator().next(); aar.clearCachedAuthorInfo(SecurityUtils.getSubject().getPrincipals()); }
From source file:com.blazarquant.bfp.web.util.ShiroUtils.java
License:Apache License
public void clearCachedAuthorizationInfo() { Collection<Realm> realms = ((DefaultWebSecurityManager) SecurityUtils.getSecurityManager()).getRealms(); for (Realm realm : realms) { if (realm instanceof DatabaseUserRealm) { ((DatabaseUserRealm) realm)// w ww . j a v a2s. c om .clearCachedAuthorizationInfo(SecurityUtils.getSubject().getPrincipals()); } } }
From source file:com.caricah.iotracah.core.modules.Datastore.java
License:Apache License
public Observable<IOTClient> getSession(IotClientKey sessionId) { return Observable.create(observer -> { try {/* w ww. jav a 2s. c o m*/ DefaultSessionKey sessionKey = new DefaultSessionKey(sessionId); IOTClient session = (IOTClient) SecurityUtils.getSecurityManager().getSession(sessionKey); if (Objects.isNull(session)) { observer.onError(new DoesNotExistException("No session with the id exists.")); } else { observer.onNext(session); observer.onCompleted(); } } catch (Exception e) { observer.onError(e); } }); }
From source file:com.company.sdn.impl.ConnectorRpcProvider.java
License:Open Source License
public ConnectorRpcProvider(DataBroker dataBroker, NotificationPublishService notificationPublishService, RpcProviderRegistry rpcRegistry) { this.dataBroker = dataBroker; this.notificationPublishService = notificationPublishService; this.rpcRegistry = rpcRegistry; this.rpcRegistry.addRpcImplementation(SystemConnectorXyzRpcService.class, this); /**//from w w w .ja v a2 s .c o m * This block never worked as it needs static security manager which needs staticSecurityManagerEnabled to be set. */ try { AuthenticatingSecurityManager securityMgr = (AuthenticatingSecurityManager) SecurityUtils .getSecurityManager(); LOG.info("security mgr {}", securityMgr); AbstractAuthenticator authentication = (AbstractAuthenticator) securityMgr.getAuthenticator(); authentication.getAuthenticationListeners().add(new CustomAuthenticationListener()); } catch (Exception e) { LOG.error("error {}", e); } }
From source file:com.company.sdn.impl.ConnectorRpcProvider.java
License:Open Source License
@Override public Future<RpcResult<AddConnectorOutput>> addConnector(AddConnectorInput input) { /**/*from ww w . j a v a 2 s . co m*/ * Temporary code here. * */ try { AuthenticatingSecurityManager securityMgr = (AuthenticatingSecurityManager) SecurityUtils .getSecurityManager(); LOG.info("security mgr {}", securityMgr); AbstractAuthenticator authentication = (AbstractAuthenticator) securityMgr.getAuthenticator(); authentication.getAuthenticationListeners().add(new CustomAuthenticationListener()); } catch (Exception e) { LOG.error("error {}", e); } RpcResultBuilder<AddConnectorOutput> rpcResultBuilder = RpcResultBuilder.success(); String connectorIdString = CONNECTOR_PREFIX + Long.toString(Calendar.getInstance().getTimeInMillis()); ConnectorId connectorId = new ConnectorId(connectorIdString); ConnectorKey connectorKey = new ConnectorKey(connectorId); InstanceIdentifier<Connector> connectorIID = InstanceIdentifier.builder(System.class) .augmentation(SystemConnectors.class).child(Connectors.class).child(Connector.class, connectorKey) .build(); input.getConfig(); Connector connector = new ConnectorBuilder().setConfig(input.getConfig()).setId(connectorId) .setKey(connectorKey).build(); ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction(); transaction.merge(LogicalDatastoreType.CONFIGURATION, connectorIID, connector, true); transaction.submit(); ConnectorLifecycleEventBuilder connectorEventBuilder = new ConnectorLifecycleEventBuilder(connector) .setEventType(SystemEventType.Add).setId(connectorId); try { notificationPublishService.putNotification(connectorEventBuilder.build()); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return rpcResultBuilder.withResult(new AddConnectorOutputBuilder().setId(connectorId).build()) .buildFuture(); }
From source file:com.flowlogix.security.cdi.ShiroSessionScopeContext.java
License:Apache License
private boolean isWebContainerSessions() { if (SecurityUtils.getSecurityManager() instanceof WebSecurityManager) { WebSecurityManager wsm = (WebSecurityManager) SecurityUtils.getSecurityManager(); return wsm.isHttpSessionMode(); }/*from w w w .j a v a2s . c o m*/ return false; }