use of org.apache.shiro.session.Session in project ddf by codice.
the class OAuthPluginTest method getSubject.
private Subject getSubject() {
Session session = mock(Session.class);
when(session.getId()).thenReturn(SESSION);
Subject subject = mock(Subject.class);
when(subject.getSession(false)).thenReturn(session);
return subject;
}
use of org.apache.shiro.session.Session in project ddf by codice.
the class OAuthSecurityImpl method setUserTokenOnClient.
/**
* Gets the user's access token from the token storage to set it to the OAUTH header. Used when a
* source is configured to use Authentication Code flow/grant.
*
* @param client Non-null client to set the access token on.
* @param subject subject used to get the session ID
* @param sourceId the id of the source using OAuth needed to get the correct tokens
*/
@Override
public void setUserTokenOnClient(Client client, Subject subject, String sourceId) {
if (client == null || subject == null || Strings.isBlank(sourceId)) {
return;
}
Session session = subject.getSession(false);
if (session == null) {
LOGGER.warn("The user's session is not available.");
return;
}
String sessionId = (String) session.getId();
if (sessionId == null) {
LOGGER.warn("The user's session ID is not available.");
return;
}
TokenInformation.TokenEntry tokenEntry = tokenStorage.read(sessionId, sourceId);
if (tokenEntry == null) {
return;
}
LOGGER.debug(ADDING_TOKEN);
client.header(OAUTH, BEARER + tokenEntry.getAccessToken());
}
use of org.apache.shiro.session.Session in project ddf by codice.
the class OAuthSecurityImplTest method getSubject.
private Subject getSubject() {
Session session = mock(Session.class);
when(session.getId()).thenReturn(SESSION_ID);
Subject subject = mock(Subject.class);
when(subject.getSession(false)).thenReturn(session);
return subject;
}
use of org.apache.shiro.session.Session in project mica2 by obiba.
the class AuthenticationInterceptor method filter.
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
// Set the cookie if the user is still authenticated
String path = micaConfigService.getContextPath() + "/";
if (isUserAuthenticated()) {
Session session = SecurityUtils.getSubject().getSession();
session.touch();
int timeout = (int) (session.getTimeout() / 1000);
NewCookie sidCookie = new NewCookie(MICA_SESSION_ID_COOKIE_NAME, session.getId().toString(), path, null, null, timeout, true, true);
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
List<Object> cookies = headers.get(HttpHeaders.SET_COOKIE);
if (cookies == null)
headers.putSingle(HttpHeaders.SET_COOKIE, sidCookie);
else
headers.add(HttpHeaders.SET_COOKIE, sidCookie);
Object cookieValue = session.getAttribute(HttpHeaders.SET_COOKIE);
if (cookieValue != null) {
headers.add(HttpHeaders.SET_COOKIE, NewCookie.valueOf(cookieValue.toString()));
}
} else {
if (responseContext.getHeaders().get(HttpHeaders.SET_COOKIE) == null) {
responseContext.getHeaders().putSingle(HttpHeaders.SET_COOKIE, new NewCookie(MICA_SESSION_ID_COOKIE_NAME, null, path, null, "Mica session deleted", 0, true, true));
}
}
}
use of org.apache.shiro.session.Session in project mica2 by obiba.
the class CurrentSessionResource method deleteSession.
@DELETE
public Response deleteSession() {
// Delete the Shiro session
try {
Session session = SecurityUtils.getSubject().getSession();
Object cookieValue = session.getAttribute(HttpHeaders.SET_COOKIE);
SecurityUtils.getSubject().logout();
if (cookieValue != null) {
NewCookie cookie = NewCookie.valueOf(cookieValue.toString());
if (OBIBA_ID_COOKIE_NAME.equals(cookie.getName())) {
return Response.ok().header(HttpHeaders.SET_COOKIE, new NewCookie(OBIBA_ID_COOKIE_NAME, null, micaConfigService.getContextPath() + "/", cookie.getDomain(), "Obiba session deleted", 0, true, true)).build();
}
}
} catch (InvalidSessionException e) {
// Ignore
}
return Response.ok().build();
}
Aggregations