Search in sources :

Example 76 with Subject

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.");
    }
}
Also used : PersistenceException(org.codice.ddf.persistence.PersistenceException) ActivityEvent(org.codice.ddf.activities.ActivityEvent) Event(org.osgi.service.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Subject(org.apache.shiro.subject.Subject) PersistenceException(org.codice.ddf.persistence.PersistenceException) Listener(org.cometd.annotation.Listener)

Example 77 with Subject

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) Subject(org.apache.shiro.subject.Subject) PersistenceException(org.codice.ddf.persistence.PersistenceException) Listener(org.cometd.annotation.Listener)

Example 78 with Subject

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));
}
Also used : Action(ddf.action.Action) HashMap(java.util.HashMap) Subject(org.apache.shiro.subject.Subject) Test(org.junit.Test)

Aggregations

Subject (org.apache.shiro.subject.Subject)78 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)11 Test (org.junit.Test)9 IOException (java.io.IOException)8 Map (java.util.Map)8 Path (javax.ws.rs.Path)8 StopProcessingException (ddf.catalog.plugin.StopProcessingException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 AccountVO (com.netsteadfast.greenstep.vo.AccountVO)5 Attribute (ddf.catalog.data.Attribute)5 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 GET (javax.ws.rs.GET)5 AuthenticationException (org.apache.shiro.authc.AuthenticationException)5 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)4 Metacard (ddf.catalog.data.Metacard)4 ApiOperation (io.swagger.annotations.ApiOperation)4 POST (javax.ws.rs.POST)4 PersistenceException (org.codice.ddf.persistence.PersistenceException)4