GWY
2022-04-27 12b7399736e90d33bfe0c2d29917d6f075246e00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
global class NetworkAccess implements Process.Plugin
{    
    global Process.PluginResult invoke(Process.PluginRequest request)
    {   
        Map<String, Object> result = new Map<String, Object>();  
        boolean isTrustedIP = false;
        
        String sourceIp = (String)request.inputParameters.get('IP');
        
        //IP not provided, use the current session IP address
        if(sourceIP == null || sourceIP == '')
        {
            Map<String,String> sessionAttributes;
            try 
            {
                sessionAttributes = Auth.SessionManagement.getCurrentSession();
            }
            catch(Exception e)
            {
                result.put('IsTrusted', false);
        
                return new Process.PluginResult(result);
            }
            
            for(string key : sessionAttributes.keySet())
            {
                system.debug('key: ' + key + ' value: ' + sessionAttributes.get(key));
            }
    
            sourceIP = sessionAttributes.get('SourceIp');
        }
        
        system.debug('SourceIP: ' + sourceIp);
        
        if(sourceIp != null)
            isTrustedIP = Auth.SessionManagement.inOrgNetworkRange(sourceIP);
         
        result.put('IsTrusted', isTrustedIP);
        
        return new Process.PluginResult(result);
    }
 
    global Process.PluginDescribeResult describe()
    {
        Process.PluginDescribeResult result = new Process.PluginDescribeResult();
        result.description='This plug-in verifies if the input IP address is in your organization trusted IP range';
        result.tag='Identity';
        
        result.inputParameters = new List<Process.PluginDescribeResult.InputParameter> {
            new Process.PluginDescribeResult.InputParameter('IP', Process.PluginDescribeResult.ParameterType.STRING, true)
        };
        
        result.outputParameters = new List<Process.PluginDescribeResult.OutputParameter> {
            new Process.PluginDescribeResult.OutputParameter('IsTrusted',
                Process.PluginDescribeResult.ParameterType.Boolean)
        };
           
        return result;
    }
}