Java Code Examples for org.acegisecurity.context.SecurityContext#getAuthentication()
The following examples show how to use
org.acegisecurity.context.SecurityContext#getAuthentication() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestImpl.java From ramus with GNU General Public License v3.0 | 5 votes |
@Override public void test() { SecurityContext sc = SecurityContextHolder.getContext(); if (sc.getAuthentication() != null) System.out.println(sc.getAuthentication().getName() + " logged by test"); }
Example 2
Source File: UserProviderImpl.java From ramus with GNU General Public License v3.0 | 4 votes |
protected String getLogin() { SecurityContext sc = SecurityContextHolder.getContext(); if (sc.getAuthentication() == null) return null; return sc.getAuthentication().getName(); }
Example 3
Source File: AcegiLogoutListener.java From webcurator with Apache License 2.0 | 4 votes |
public void sessionDestroyed(HttpSessionEvent event) { // Log the logout to the console. log.info("Detected Logout Event"); // Get the Spring Application Context. WebApplicationContext ctx = ApplicationContextFactory.getWebApplicationContext(); // We need to get the authentication context out of the // event, as it doesn't necessarily exist through the // standard Acegi tools. String remoteUser = null; Authentication auth = null; SecurityContext acegiCtx = (SecurityContext) event.getSession().getAttribute("ACEGI_SECURITY_CONTEXT"); if( acegiCtx != null) { auth = acegiCtx.getAuthentication(); if (auth != null) { remoteUser = auth.getName(); } } if (remoteUser == null) { remoteUser = "[UNKNOWN]"; } // Actions to perform on logout. lockManager = (LockManager) ctx.getBean("lockManager"); lockManager.releaseLocksForOwner(remoteUser); if (auth != null) { Object blob = auth.getDetails(); if (blob instanceof User) { User user = (User) auth.getDetails(); Auditor auditor = (Auditor) ctx.getBean(Constants.BEAN_AUDITOR); auditor.audit(user, User.class.getName(), user.getOid(), Auditor.ACTION_LOGOUT, "User " + remoteUser + " has logged out."); } SecurityContextHolder.clearContext(); // logout for duration String sessionId = event.getSession().getId(); LogonDurationDAO logonDurationDAO = (LogonDurationDAO) ctx.getBean(Constants.BEAN_LOGON_DURATION_DAO); logonDurationDAO.setLoggedOut(sessionId, new Date()); } // Log the logout to the console. log.info("Detected Logout Event for: " + remoteUser); }
Example 4
Source File: ReportEmailController.java From webcurator with Apache License 2.0 | 4 votes |
@Override protected ModelAndView processFormSubmission(HttpServletRequest req, HttpServletResponse resp, Object comm, BindException exc) throws Exception { ReportEmailCommand com = (ReportEmailCommand) comm; ModelAndView mav = new ModelAndView(); if(com.getActionCmd().equals(ACTION_EMAIL)){ OperationalReport operationalReport = (OperationalReport) req.getSession().getAttribute("operationalReport"); // Get user's email address // ...user String remoteUser = null; Authentication auth = null; SecurityContext acegiCtx = (SecurityContext) req.getSession().getAttribute("ACEGI_SECURITY_CONTEXT"); if( acegiCtx != null) { auth = acegiCtx.getAuthentication(); if (auth != null) { remoteUser = auth.getName(); } } // ...email address User user = (User) auth.getDetails(); String userEmailAddress = user.getEmail(); // Build attachment content String dataAttachment = operationalReport.getRendering(com.getFormat()); // E-mail Mailable email = new Mailable(); email.setRecipients(com.getRecipient()); email.setSender(userEmailAddress); email.setSubject(com.getSubject()); email.setMessage(com.getMessage()); mailServer.send(email, "report" + FileFactory.getFileExtension(com.getFormat()), FileFactory.getMIMEType(com.getFormat()), dataAttachment ); log.debug("email sent:"); log.debug(" from:" + userEmailAddress); log.debug(" format=" + com.getFormat()); log.debug(" to=" + com.getRecipient()); log.debug(" subject=" + com.getSubject()); log.debug(" msg=" + com.getMessage()); mav.setViewName("reporting-preview"); } else { log.error("Did not get send request: " + com.getActionCmd()); mav.setViewName("reporting-preview"); } return mav; }