• Chris Toews 9
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I'm looking for a way to monitor whether SAML logins are being used

background:
I'm supporting multiple orgs, each org having its own people administering Salesforce.
I'm looking for a way to monitor that SAML logins are being used in these orgs. I want to make sure that the admins don't turn off the SSO, and that the users don't bypass SSO by going to login.salesforce.com (which i can shutoff, but the admins can uncheck), or by going to https://mydomain.my.salesforce.com/?login (which bypasses SSO restrictions)

I know there are reports that can be run to look at logins, but it will be impractical for me to log into each org to run reports to look at logins. I need a method to automatically look at multiple orgs and notify me of offending logins.

What I currently have setup:
I have Heroku setup with Heroku Connect pulling Salesforce data into a postgres database. 
I am syncing two tables for this purpose: authsession, and user.

After some testing, I found that when a user logs in with SSO, the logintype ="SAML Sfdc Initiated SSO".
If the user was using Salesforce1, the logintype = "Remote Access 2.0" and the sessiontype = "Oauth2"
If the user logged in with login.salesforce.com (what i want to monitor) logintype = "Application" and sessiontype = "UI"

So to find the offending logins, where SSO was not used I ran the following query:
select 
	usr.username,
	usr.federationidentifier,
	auth.logintype,
	auth.sessiontype,
	auth.createddate,
	auth.lastmodifieddate
from myschema.authsession auth
left join myschema.user usr
	on auth.usersid = usr.sfid
where 
	auth.parentid is null 
	and auth.logintype = 'Application'
	and auth.sessiontype = 'UI'
order by auth.createddate desc
I'm wondering i this is going to catch all logins that don't use SSO, and if there is an easier way to do what I'm trying to do.

Thanks,
Chris Toews

 
I am new to writing Apex Triggers. I eventually want to count notes and attachments and update Event object. I am able to get the list of Event objects from the trigger attachment objects. I am able to get the count of attachments for each event. I can iterate through the Event items, and then the update doesn't seem to work.

I have a feeling this is something stupid.
I get this back when I run the test:
FATAL_ERROR System.AssertException: Assertion Failed: Expected: 1, Actual: null

Here is my trigger:
trigger Update_events_for_attachments on Attachment (after insert, after update) {

    List<Id> parentIDs = new List<Id>();
    
    for(Attachment att:Trigger.New){
		if(att.Parentid.getSObjectType().getDescribe().getName() == 'Event'){
            parentIDs.add(att.Parentid);
            System.debug('parent ID:' + att.Parentid);
        }
    }
    
    List<Event> evs = new List<Event>([select id, Note_Count__c from Event where id in :parentIDs]);
    System.debug('evs size:' + evs.size() + '    parentidsize:' + parentIDs.size());
    
    if(parentIDs.isEmpty()){
        System.debug('we didn\'t find any events');
        //if empty, we have no events to update
        return;
    }
    
    Map<ID, Integer> mymap = new Map<ID, Integer>();
    AggregateResult[] ARs = [select count(id) mycount, parentid  from attachment where parentid in :parentIDs group by parentID];
        
    for (AggregateResult ar : ARs){
        Integer thisCount = (Integer) ar.get('mycount');
        ID thidID = (ID) ar.get('parentid');
        mymap.put(thidID, thisCount);
    }
    
    
    for (Event thisEvent : evs){
        System.debug('looping thorugh evs');
        ThisEvent.Note_Count__c = mymap.get(thisEvent.ID);
        System.debug('ThisEvent.id:' + thisEvent.Id + '    ThisEvent.Note_Count__c: '+ ThisEvent.Note_Count__c);
    }
    
    update evs;
    
}

and here is the test class I'm trying to use:
@isTest
private class test_Update_events_for_attachments {

    @isTest static void TestAddingSingleAttachment(){
        Event newEvent = new Event();
        newEvent.Subject ='Test';
        newEvent.DurationInMinutes =1440;
        newEvent.ActivityDate = System.today();
        newEvent.ActivityDateTime = System.today();
        insert newEvent;
        
        Test.startTest();
        Attachment attach=new Attachment();   	
    	attach.Name='Unit Test Attachment';
    	Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
    	attach.body=bodyBlob;
        attach.parentId=newEvent.id;
        insert attach;
 
        System.debug('newEvent.Id:' + newEvent.Id + '    attach.parentID: ' + attach.parentID + '       newEvent.Note_Count__c: ' + newEvent.Note_Count__c);
        System.assertEquals(newEvent.Id, attach.parentID);
        System.assertEquals(1, newEvent.Note_Count__c);
        Test.stopTest();
    }
    
    
}


 
I am new to writing Apex Triggers. I eventually want to count notes and attachments and update Event object. I am able to get the list of Event objects from the trigger attachment objects. I am able to get the count of attachments for each event. I can iterate through the Event items, and then the update doesn't seem to work.

I have a feeling this is something stupid.
I get this back when I run the test:
FATAL_ERROR System.AssertException: Assertion Failed: Expected: 1, Actual: null

Here is my trigger:
trigger Update_events_for_attachments on Attachment (after insert, after update) {

    List<Id> parentIDs = new List<Id>();
    
    for(Attachment att:Trigger.New){
		if(att.Parentid.getSObjectType().getDescribe().getName() == 'Event'){
            parentIDs.add(att.Parentid);
            System.debug('parent ID:' + att.Parentid);
        }
    }
    
    List<Event> evs = new List<Event>([select id, Note_Count__c from Event where id in :parentIDs]);
    System.debug('evs size:' + evs.size() + '    parentidsize:' + parentIDs.size());
    
    if(parentIDs.isEmpty()){
        System.debug('we didn\'t find any events');
        //if empty, we have no events to update
        return;
    }
    
    Map<ID, Integer> mymap = new Map<ID, Integer>();
    AggregateResult[] ARs = [select count(id) mycount, parentid  from attachment where parentid in :parentIDs group by parentID];
        
    for (AggregateResult ar : ARs){
        Integer thisCount = (Integer) ar.get('mycount');
        ID thidID = (ID) ar.get('parentid');
        mymap.put(thidID, thisCount);
    }
    
    
    for (Event thisEvent : evs){
        System.debug('looping thorugh evs');
        ThisEvent.Note_Count__c = mymap.get(thisEvent.ID);
        System.debug('ThisEvent.id:' + thisEvent.Id + '    ThisEvent.Note_Count__c: '+ ThisEvent.Note_Count__c);
    }
    
    update evs;
    
}

and here is the test class I'm trying to use:
@isTest
private class test_Update_events_for_attachments {

    @isTest static void TestAddingSingleAttachment(){
        Event newEvent = new Event();
        newEvent.Subject ='Test';
        newEvent.DurationInMinutes =1440;
        newEvent.ActivityDate = System.today();
        newEvent.ActivityDateTime = System.today();
        insert newEvent;
        
        Test.startTest();
        Attachment attach=new Attachment();   	
    	attach.Name='Unit Test Attachment';
    	Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
    	attach.body=bodyBlob;
        attach.parentId=newEvent.id;
        insert attach;
 
        System.debug('newEvent.Id:' + newEvent.Id + '    attach.parentID: ' + attach.parentID + '       newEvent.Note_Count__c: ' + newEvent.Note_Count__c);
        System.assertEquals(newEvent.Id, attach.parentID);
        System.assertEquals(1, newEvent.Note_Count__c);
        Test.stopTest();
    }
    
    
}


 

Hi there,

 

I am getting the following ERROR:

Exception: System.JSONException: Illegal value for primitive

When I try to deserialize the HTTP response from Jive to an object.

 

JivePersonObject personRecord = (JivePersonObject) System.JSON.deserialize(jiveResponse, JivePersonObject.class);

 

I have validated the JSON string at http://jsonlint.com/ and it is valid. 

 

This is not happening for all the response. It is happening for some response and some of them don't have the issue.

 

I was wondering if anyone have come across this issue before. Not sure what I am doing wrong here. Thanks.

 

Sanch