List of usage examples for org.apache.shiro.subject Subject isRemembered
boolean isRemembered();
From source file:cn.dreampie.common.plugin.shiro.plugin.ShiroInterceptor.java
License:Apache License
/** * ??// w w w . ja va 2 s . co m * * @param ai * @param ahs * @return */ private boolean assertNoAuthorized(ActionInvocation ai, List<AuthzHandler> ahs) { // ? if (ahs != null && ahs.size() > 0) { // ?? if (!SubjectUtils.me().wasLogin()) { WebUtils.saveRequest(ai.getController().getRequest()); } //rememberMe Subject subject = SubjectUtils.me().getSubject(); if (!subject.isAuthenticated() && subject.isRemembered()) { Object principal = subject.getPrincipal(); Session session = SubjectUtils.me().getSession(); if (null != principal) { if (session.getAttribute(AppConstants.CURRENT_USER) == null) { session.setAttribute(AppConstants.CURRENT_USER, (User) principal); } } else { SubjectUtils.me().getSubject().logout(); } } try { // ?? for (AuthzHandler ah : ahs) { ah.assertAuthorized(); } } catch (UnauthenticatedException lae) { // RequiresGuestRequiresAuthenticationRequiresUser?? // ?HTTP401?? ai.getController().renderError(401); return true; } catch (AuthorizationException ae) { // RequiresRolesRequiresPermissions? // ???HTTP??403 ai.getController().renderError(403); return true; } catch (Exception e) { // ai.getController().renderError(401); return true; } } return false; }
From source file:cn.dreampie.shiro.core.ShiroInterceptor.java
License:Apache License
/** * ??//from w ww . java2 s.co m * * @param ai * @param ahs * @return */ private boolean assertNoAuthorized(ActionInvocation ai, List<AuthzHandler> ahs) { // ? if (ahs != null && ahs.size() > 0) { // ?? if (!SubjectKit.isAuthed()) { WebUtils.saveRequest(ai.getController().getRequest()); } //rememberMe Subject subject = SubjectKit.getSubject(); if (!subject.isAuthenticated() && subject.isRemembered()) { Object principal = subject.getPrincipal(); if (principal == null) { SubjectKit.getSubject().logout(); } } try { // ?? for (AuthzHandler ah : ahs) { ah.assertAuthorized(); } } catch (UnauthenticatedException lae) { // RequiresGuestRequiresAuthenticationRequiresUser?? // ?HTTP401?? ai.getController().renderError(401); return true; } catch (AuthorizationException ae) { // RequiresRolesRequiresPermissions? // ???HTTP??403 ai.getController().renderError(403); return true; } catch (Exception e) { // ai.getController().renderError(401); return true; } } return false; }
From source file:com.comp.pruebaconshiro.ShiroAuthService.java
public void testAuth() { // simulate a username/password (plaintext) token created in response to // a login attempt: UsernamePasswordToken token = new UsernamePasswordToken("usuario", "cristian"); token.setRememberMe(true);/* w ww .j a v a2 s . c o m*/ boolean loggedIn; Session session = null; Subject currentUser = SecurityUtils.getSubject(); try { currentUser.login(token); session = currentUser.getSession(); System.out.println("Session Id: " + session.getId()); loggedIn = true; } catch (Exception ex) { loggedIn = false; } Serializable sessionId = session.getId(); if (loggedIn) { Subject requestSubject = new Subject.Builder().sessionId(sessionId).buildSubject(); System.out.println("Es admin = " + requestSubject.hasRole("admin"));//Should return true System.out.println("Is Authenticated = " + requestSubject.isAuthenticated());//Should return true System.out.println("Is Remembered = " + requestSubject.isRemembered()); } else { System.out.println("Not logged in."); } System.exit(0); }
From source file:com.dbumama.market.web.core.plugin.shiro.ShiroInterceptor.java
License:Apache License
/** * ??/*from w w w. j a v a 2 s. c o m*/ * * @param ai * @param ahs * @return */ private boolean assertNoAuthorized(Invocation ai, List<AuthzHandler> ahs) { // ? if (ahs != null && ahs.size() > 0) { // ?? if (!SubjectKit.isAuthed()) { WebUtils.saveRequest(ai.getController().getRequest()); } // rememberMe Subject subject = SubjectKit.getSubject(); if (!subject.isAuthenticated() && subject.isRemembered()) { Object principal = subject.getPrincipal(); if (principal == null) { SubjectKit.getSubject().logout(); } } try { // ?? for (AuthzHandler ah : ahs) { ah.assertAuthorized(); } } catch (UnauthenticatedException lae) { // RequiresGuestRequiresAuthenticationRequiresUser?? // ?HTTP401?? ai.getController().renderError(401); return true; } catch (AuthorizationException ae) { // RequiresRolesRequiresPermissions? // ???HTTP??403 ai.getController().renderError(403); return true; } catch (Exception e) { // ai.getController().renderError(401); return true; } } return false; }
From source file:com.flowlogix.security.PassThruAuthenticationFilter.java
License:Apache License
@Override protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) { Subject subject = getSubject(request, response); return subject.isAuthenticated() || (useRemembered && subject.isRemembered()); }
From source file:com.ftww.basic.plugin.shiro.core.ShiroInterceptor.java
License:Apache License
/** * ??/* w w w. j ava2 s .c om*/ * * @param ai * @param ahs * @return */ private boolean assertNoAuthorized(ActionInvocation ai, List<AuthzHandler> ahs) { // ? if (ahs != null && ahs.size() > 0) { // ?? if (!SubjectKit.isAuthed()) { WebUtils.saveRequest(ai.getController().getRequest()); } // rememberMe Subject subject = SubjectKit.getSubject(); if (!subject.isAuthenticated() && subject.isRemembered()) { Object principal = subject.getPrincipal(); if (principal == null) { SubjectKit.getSubject().logout(); } } try { // ?? for (AuthzHandler ah : ahs) { ah.assertAuthorized(); } } catch (UnauthenticatedException lae) { // RequiresGuestRequiresAuthenticationRequiresUser?? // ?HTTP401?? ai.getController().renderError(401); return true; } catch (AuthorizationException ae) { // RequiresRolesRequiresPermissions? // ???HTTP??403 ai.getController().renderError(403); return true; } catch (Exception e) { // ai.getController().renderError(401); return true; } } return false; }
From source file:com.github.dactiv.fear.commons.service.auth.Subjects.java
License:Apache License
/** * ??/*from w ww . j a v a2 s .c o m*/ * * @return Map */ public static Map<String, Object> getRememberedPrincipal() { Subject subject = SecurityUtils.getSubject(); if (subject.isRemembered()) { Object principal = subject.getPrincipal(); return Casts.cast(principal == null ? null : principal); } return null; }
From source file:com.h57.sample.controller.HomeController.java
License:BSD License
/** * Does some simple work to find the current shiro subject gets a list of * services, and the date./* ww w . j ava 2 s. c o m*/ */ @RequestMapping(method = RequestMethod.GET, value = { "/", "/index" }) public String home(Locale locale, Model model, HttpServletRequest request) { logger.info("Welcome home! the client locale is " + locale.toString()); // This gets the current subject from shiro Subject currentUser = SecurityUtils.getSubject(); // I was going to have more services, who knows .. maybe we will add // more. List<String> services = new ArrayList<String>(); // My SQL class org.apache.commons.dbcp.BasicDataSource if (dataSource instanceof BasicDataSource) { services.add("Data Source: " + ((BasicDataSource) dataSource).getUrl()); } else if (dataSource instanceof SimpleDriverDataSource) { services.add("Data Source: " + ((SimpleDriverDataSource) dataSource).getUrl()); } services.add("My SQL: " + dataSource.getClass()); // Just to prove we can do it. Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate); // Lets get an identity object Identity thisIdentity = null; // Remembered (from cookie) is different from authenticated in Shiro if (currentUser.isRemembered()) { logger.info("Remembered PRINCIPAL: " + currentUser.getPrincipal()); thisIdentity = identityService.getIdentity(currentUser.getPrincipal().toString()); // Authenticated, we really do believe they are who they claim to // be! } else if (currentUser.isAuthenticated()) { logger.info("Authenticated PRINCIPAL: " + currentUser.getPrincipal()); thisIdentity = identityService.getIdentity(currentUser.getPrincipal().toString()); } // Pass this to the jsp. model.addAttribute("currentUser", currentUser); model.addAttribute("identity", thisIdentity); model.addAttribute("serverTime", formattedDate); model.addAttribute("services", services); return "home"; }
From source file:com.hgcode.shiro.ShiroJetTags.java
License:Open Source License
/** * Displays body content only if the current user has remembered. *//*from www.ja v a 2 s. c o m*/ public static void remembered(JetTagContext ctx) throws IOException { final Subject subject = getSubject(); boolean show = subject.isRemembered(); if (show) { printTagBody(ctx); } }
From source file:com.hgcode.shiro.ShiroJetTags.java
License:Open Source License
/** * Displays body content only if the current user has remembered. */// w w w . ja va 2s.co m public static void not_remembered(JetTagContext ctx) throws IOException { final Subject subject = getSubject(); boolean show = !subject.isRemembered(); if (show) { printTagBody(ctx); } }