use of org.apereo.portal.security.IPerson in project uPortal by Jasig.
the class PersonService method getPerson.
/**
* Obtain the fully-constructed {@link IPerson} associated witth the specified username.
*/
public IPerson getPerson(String username) {
final IPerson rslt = new PersonImpl();
rslt.setAttribute(IPerson.USERNAME, username);
rslt.setID(userIdentityStore.getPortalUserId(username));
rslt.setAttributes(personAttributeDao.getPerson(username).getAttributes());
return rslt;
}
use of org.apereo.portal.security.IPerson in project uPortal by Jasig.
the class LogoutController method doLogout.
/**
* Process the incoming request and response.
*
* @param request HttpServletRequest object
* @param response HttpServletResponse object
*/
@RequestMapping
public void doLogout(HttpServletRequest request, HttpServletResponse response) throws IOException {
String redirect = this.selectRedirectionUrl(request);
final HttpSession session = request.getSession(false);
if (session != null) {
// Record that an authenticated user is requesting to log out
try {
final IPerson person = personManager.getPerson(request);
if (person != null && person.getSecurityContext().isAuthenticated()) {
this.portalEventFactory.publishLogoutEvent(request, this, person);
}
} catch (final Exception e) {
logger.error("Exception recording logout " + "associated with request " + request, e);
}
final String originalUid = this.identitySwapperManager.getOriginalUsername(session);
// Logging out from a swapped user, just redirect to the Login servlet
if (originalUid != null) {
redirect = request.getContextPath() + "/Login";
} else {
// Clear out the existing session for the user
try {
session.invalidate();
} catch (final IllegalStateException ise) {
// it need not insist that it be the one to perform the invalidating.
if (logger.isTraceEnabled()) {
logger.trace("LogoutController encountered IllegalStateException invalidating a presumably already-invalidated session.", ise);
}
}
}
}
if (logger.isTraceEnabled()) {
logger.trace("Redirecting to " + redirect + " to send the user back to the guest page.");
}
final String encodedRedirectURL = response.encodeRedirectURL(redirect);
response.sendRedirect(encodedRedirectURL);
}
use of org.apereo.portal.security.IPerson in project uPortal by Jasig.
the class LoginController method service.
/**
* Process the incoming HttpServletRequest. Note that this processing occurs after
* PortalPreAuthenticatedProcessingFilter has run and performed pre-processing.
*
* @param request
* @param response
* @exception ServletException
* @exception IOException
*/
@RequestMapping
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// create the redirect URL, adding fname and args parameters if necessary
String redirectTarget = null;
// check for custom redirect strategies
if (loginRedirect != null) {
redirectTarget = loginRedirect.redirectTarget(request);
}
if (redirectTarget == null) {
final String refUrl = request.getParameter(REFERER_URL_PARAM);
final URL redirectLocation = parseLocalRefUrl(request, refUrl);
if (redirectLocation != null) {
redirectTarget = redirectLocation.toString();
}
if (redirectTarget == null) {
/* Grab the target functional name, if any, off the login request.
* Also any arguments for the target. We will pass them along after authentication.
*/
String targetFname = request.getParameter("uP_fname");
if (targetFname == null) {
final IPortalUrlBuilder defaultUrl = this.portalUrlProvider.getDefaultUrl(request);
redirectTarget = defaultUrl.getUrlString();
} else {
try {
final IPortalUrlBuilder urlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletFName(request, targetFname, UrlType.RENDER);
Enumeration<String> e = request.getParameterNames();
while (e.hasMoreElements()) {
String paramName = e.nextElement();
if (!paramName.equals("uP_fname")) {
urlBuilder.addParameter(paramName, request.getParameterValues(paramName));
}
}
redirectTarget = urlBuilder.getUrlString();
} catch (IllegalArgumentException e) {
final IPortalUrlBuilder defaultUrl = this.portalUrlProvider.getDefaultUrl(request);
redirectTarget = defaultUrl.getUrlString();
}
}
}
IPerson person = null;
final Object authError = request.getSession(false).getAttribute(LoginController.AUTH_ERROR_KEY);
if (authError == null || !((Boolean) authError)) {
person = this.personManager.getPerson(request);
}
if (person == null || !person.getSecurityContext().isAuthenticated()) {
if (request.getMethod().equals("POST"))
request.getSession(false).setAttribute(AUTH_ATTEMPTED_KEY, "true");
// Preserve the attempted username so it can be redisplayed to the user
String attemptedUserName = request.getParameter("userName");
if (attemptedUserName != null)
request.getSession(false).setAttribute(ATTEMPTED_USERNAME_KEY, request.getParameter("userName"));
}
}
final String encodedRedirectURL = response.encodeRedirectURL(redirectTarget);
if (log.isDebugEnabled()) {
log.debug("Redirecting to " + redirectTarget);
}
response.sendRedirect(encodedRedirectURL);
}
use of org.apereo.portal.security.IPerson in project uPortal by Jasig.
the class MaxInactiveFilterTest method noTimeSetWorkflow.
@Test
public void noTimeSetWorkflow() throws IOException, ServletException {
final HttpSession session = mock(HttpSession.class);
final HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getSession(false)).thenReturn(session);
// no calls, used in doFilter()
final ServletResponse resp = mock(ServletResponse.class);
final FilterChain chain = mock(FilterChain.class);
final ISecurityContext securityContext = mock(ISecurityContext.class);
when(securityContext.isAuthenticated()).thenReturn(true);
final IPerson person = mock(IPerson.class);
when(person.getSecurityContext()).thenReturn(securityContext);
when(person.getAttribute(SESSION_MAX_INACTIVE_SET_ATTR)).thenReturn(null);
when(person.getAttribute(IPerson.USERNAME)).thenReturn("jsmith");
final IPersonManager personManager = mock(IPersonManager.class);
when(personManager.getPerson(req)).thenReturn(person);
final IMaxInactiveStrategy maxInactiveStrategy = mock(IMaxInactiveStrategy.class);
final Integer interval = 5;
when(maxInactiveStrategy.calcMaxInactive(person)).thenReturn(interval);
final MaxInactiveFilter filter = new MaxInactiveFilter();
ReflectionTestUtils.setField(filter, "personManager", personManager);
ReflectionTestUtils.setField(filter, "maxInactiveStrategy", maxInactiveStrategy);
filter.doFilter(req, resp, chain);
verify(person, times(1)).setAttribute(eq(SESSION_MAX_INACTIVE_SET_ATTR), any(LocalDateTime.class));
verify(session, times(1)).setMaxInactiveInterval(interval);
verify(maxInactiveStrategy, times(1)).calcMaxInactive(person);
verify(securityContext, times(1)).isAuthenticated();
verify(person, times(1)).getSecurityContext();
verify(person, times(1)).getAttribute(SESSION_MAX_INACTIVE_SET_ATTR);
verify(person, times(2)).getAttribute(IPerson.USERNAME);
verify(personManager, times(1)).getPerson(req);
verifyNoMoreInteractions(resp);
verify(chain, only()).doFilter(req, resp);
}
use of org.apereo.portal.security.IPerson in project uPortal by Jasig.
the class MaxInactiveFilterTest method timeSetInsideRefreshDurationWorkflow.
@Test
public void timeSetInsideRefreshDurationWorkflow() throws IOException, ServletException {
final HttpSession session = mock(HttpSession.class);
final HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getSession(false)).thenReturn(session);
// no calls, used in doFilter()
final ServletResponse resp = mock(ServletResponse.class);
final FilterChain chain = mock(FilterChain.class);
final ISecurityContext securityContext = mock(ISecurityContext.class);
when(securityContext.isAuthenticated()).thenReturn(true);
final IPerson person = mock(IPerson.class);
when(person.getSecurityContext()).thenReturn(securityContext);
final LocalDateTime lastTime = LocalDateTime.now(tz).minusMinutes(1);
when(person.getAttribute(SESSION_MAX_INACTIVE_SET_ATTR)).thenReturn(lastTime);
when(person.getAttribute(IPerson.USERNAME)).thenReturn("jsmith");
final IPersonManager personManager = mock(IPersonManager.class);
when(personManager.getPerson(req)).thenReturn(person);
final IMaxInactiveStrategy maxInactiveStrategy = mock(IMaxInactiveStrategy.class);
final MaxInactiveFilter filter = new MaxInactiveFilter();
ReflectionTestUtils.setField(filter, "personManager", personManager);
ReflectionTestUtils.setField(filter, "maxInactiveStrategy", maxInactiveStrategy);
filter.doFilter(req, resp, chain);
verify(securityContext, times(1)).isAuthenticated();
verify(person, times(1)).getSecurityContext();
verify(person, times(1)).getAttribute(SESSION_MAX_INACTIVE_SET_ATTR);
verify(person, times(1)).getAttribute(IPerson.USERNAME);
verify(personManager, times(1)).getPerson(req);
verifyNoMoreInteractions(maxInactiveStrategy);
verifyNoMoreInteractions(resp);
verifyNoMoreInteractions(session);
verify(chain, only()).doFilter(req, resp);
}
Aggregations