use of org.apache.shiro.subject.Subject in project ddf by codice.
the class ActivityController method deletePersistentActivity.
@Listener("/service/action")
public void deletePersistentActivity(ServerSession serverSession, ServerMessage serverMessage) {
LOGGER.debug("\nServerSession: {}\nServerMessage: {}", serverSession, serverMessage);
if (null == serverSession) {
throw new IllegalArgumentException("ServerSession is null");
}
if (null == serverMessage) {
throw new IllegalArgumentException("ServerMessage is null");
}
Subject subject = null;
try {
subject = SecurityUtils.getSubject();
} catch (Exception e) {
LOGGER.debug("Couldn't grab user subject from Shiro.", e);
}
String userId = getUserId(serverSession, subject);
Map<String, Object> dataAsMap = serverMessage.getDataAsMap();
if (dataAsMap != null) {
Object activitiesPreCast = dataAsMap.get("data");
Object[] activities = activitiesPreCast instanceof List ? ((List) activitiesPreCast).toArray() : (Object[]) activitiesPreCast;
for (Object activityObject : activities) {
Map activity = (Map) activityObject;
String id = (String) activity.get("id");
String action = (String) activity.get("action");
if (action != null) {
if (REMOVE_ACTION.equals(action)) {
//You can have a blank id for guest
if (id != null) {
try {
this.persistentStore.delete(PersistentStore.ACTIVITY_TYPE, "id = '" + id + "'");
} catch (PersistenceException e) {
throw new IllegalArgumentException("Unable to delete activity with id = " + id);
}
} else {
throw new IllegalArgumentException("Message id is null");
}
} else if (CANCEL_ACTION.equals(action)) {
if (null == userId) {
throw new IllegalArgumentException("User ID is null");
}
if (null == id) {
throw new IllegalArgumentException("Metadata ID is null");
}
Map<String, Object> jsonPropMap = new HashMap<>();
jsonPropMap.put(ActivityEvent.DOWNLOAD_ID_KEY, id);
Event event = new Event(ActivityEvent.EVENT_TOPIC_DOWNLOAD_CANCEL, jsonPropMap);
eventAdmin.postEvent(event);
}
} else {
throw new IllegalArgumentException("Message action is null.");
}
}
} else {
throw new IllegalArgumentException("Server Message is null.");
}
}
use of org.apache.shiro.subject.Subject in project ddf by codice.
the class ActivityController method getPersistedActivities.
@Listener('/' + ActivityEvent.EVENT_TOPIC)
public void getPersistedActivities(final ServerSession remote, Message message) {
Map<String, Object> data = message.getDataAsMap();
if (MapUtils.isEmpty(data)) {
Subject subject = null;
try {
subject = SecurityUtils.getSubject();
} catch (Exception e) {
LOGGER.debug("Couldn't grab user subject from Shiro.", e);
}
String userId = getUserId(remote, subject);
if (null == userId) {
throw new IllegalArgumentException("User ID is null");
}
List<Map<String, Object>> activities = getActivitiesForUser(userId);
if (CollectionUtils.isNotEmpty(activities)) {
queuePersistedMessages(remote, activities, ACTIVITY_TOPIC_COMETD_BROADCAST);
}
}
}
use of org.apache.shiro.subject.Subject in project ddf by codice.
the class IdpLogoutActionProviderTest method testGetAction.
@Test
public void testGetAction() throws Exception {
Subject subject = mock(Subject.class);
HashMap map = new HashMap();
map.put("idp", subject);
Action action = idpLogoutActionProvider.getAction(map);
Assert.assertTrue("Expected the encrypted nameId and time", action.getUrl().getQuery().contains(nameIdTime));
}
Aggregations