fork download
  1. /* ----------------------------------------------------------------------------------------------------------------------------------------------------------
  2. Name: LoginAccessMarketProfileEventCondition.cls
  3. Description: Update Transactional Secuirty Policy
  4.  
  5. Date Version Author Summary of Changes
  6. ----------- ---------- --------------- ------------------------------------------------------------------------------------------------
  7. Nov 2024 1.0 Rushikesh Shinde US-ID_0016982 Transaction Security Policy - LoginAccessMarketProfile - Cleanup and simplification
  8.  
  9. ---------------------------------------------------------------------------------------------------------------------------------------------------------- */
  10.  
  11. global class LoginAccessMarketProfileEventCondition1 implements TxnSecurity.EventCondition {
  12. static final boolean AllowLogin = false;
  13. static final boolean RestricLogin = false;
  14.  
  15. public Boolean evaluate(SObject event) {
  16. system.debug('TestKK-Event' + event);
  17.  
  18. switch on event {
  19. when LoginEvent loginEvent {
  20. return evaluateNext(loginEvent);
  21. }
  22. when null {
  23. return false;
  24. }
  25. when else {
  26. return false;
  27. }
  28. }
  29. }
  30.  
  31. public Boolean evaluateNext(LoginEvent LoginObj) {
  32. // Login user details
  33. system.debug('TestHB' + LoginObj);
  34.  
  35. List<User> userList = [SELECT ProfileId, Profile.Name, Profile.PermissionsApiUserOnly, OpCo__c FROM User WHERE Id = :LoginObj.UserId];
  36.  
  37. // Added for the SR-00362417. IF Login Session is not related to Application then allow login as external Application/Integration
  38.  
  39. if (!LoginObj.LoginType.contains('Application')) {
  40. return AllowLogin;
  41. }
  42.  
  43. boolean value = evaluateThis(userList, LoginObj.LoginURL);
  44. return value;
  45. }
  46. public Boolean evaluateThis(List<User> userList, String LoginURL) {
  47. // Bypass if user is bypassed in DataManagementSCM
  48.  
  49. DataManagementSCM__c dmscmCSRecord = DataManagementSCM__c.getInstance(userList[0].Id);
  50. DataManagementSCM__c dmscmCSRecordOrgWide = DataManagementSCM__c.getOrgDefaults();
  51.  
  52. if ((dmscmCSRecord != null && dmscmCSRecord.ByPassLoginAccessMarketProfilePolicyCond__c) ||(dmscmCSRecordOrgWide != null && dmscmCSRecordOrgWide.ByPassLoginAccessMarketProfilePolicyCond__c))
  53. {
  54. system.debug('TestKK3');
  55. return AllowLogin;
  56. }
  57.  
  58.  
  59. // Bypass if user has API User Only permission
  60. Boolean profilePermissionsApiEnabled = (Boolean) userList[0] .Profile.PermissionsApiUserOnly;
  61.  
  62. if (profilePermissionsApiEnabled) {
  63. return AllowLogin;
  64. }
  65.  
  66.  
  67. // Bypass if user has LoginAccessPolicyBypass Custom Permission
  68. Boolean hasLoginAccessPolicyBypassPermission = false;
  69. hasLoginAccessPolicyBypassPermission = doesRunningUserHavePermission(userList[0],'LoginAccessPolicyBypass');
  70.  
  71. if (hasLoginAccessPolicyBypassPermission) {
  72.  
  73. system.debug('TestKK2' + hasLoginAccessPolicyBypassPermission);
  74. return AllowLogin;
  75. }
  76.  
  77.  
  78.  
  79. // Bypass if USer is SSO And URl is Not ( login or test)
  80.  
  81. if (((!LoginURL.contains(GEN_Constants.SandboxLoginURL)) || (!LoginURL.contains(GEN_Constants.ProdLoginURL)))) {
  82.  
  83. system.debug('TestKK17');
  84. return AllowLogin;
  85. }
  86.  
  87.  
  88.  
  89. // Bypass if user has LoginAccessPolicyBypass Custom Permission Non SSO
  90.  
  91. if (((LoginURL.contains(GEN_Constants.SandboxLoginURL)) ||(LoginURL.contains(GEN_Constants.ProdLoginURL))) && hasLoginAccessPolicyBypassPermission) {
  92. system.debug('TestKK2' + hasLoginAccessPolicyBypassPermission);
  93. return AllowLogin;
  94. }
  95.  
  96. else {
  97.  
  98. system.debug('TestKK18');
  99. return RestricLogin ;
  100. }
  101. }
  102.  
  103.  
  104. public static Boolean doesRunningUserHavePermission(User user, String apiName) {
  105. Set<Id> accessiblePermissionIds = new Set<Id>();
  106.  
  107. for(SetupEntityAccess access : [
  108. SELECT SetupEntityId FROM SetupEntityAccess
  109. WHERE SetupEntityType = 'CustomPermission' AND ParentId IN (
  110. SELECT PermissionSetId FROM PermissionSetAssignment
  111. WHERE AssigneeId = : user.Id // UserInfo.getUserId()
  112. )
  113. ]){
  114. accessiblePermissionIds.add(access.SetupEntityId);
  115. system.debug('TestKK --accessiblePermissionIds'+accessiblePermissionIds);
  116. }
  117.  
  118. return 0 < [
  119. SELECT count() FROM CustomPermission
  120. WHERE Id IN : accessiblePermissionIds
  121. AND DeveloperName = : apiName ];
  122. }
  123. }
Success #stdin #stdout #stderr 0.02s 12500KB
stdin
Standard input is empty
stdout
Object: nil error: did not understand #associationAt:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:114)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:39)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:81)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:81)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:81)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:81)
stderr
./prog:1: expected expression
./prog:39: expected expression
./prog:52: expected expression
./prog:52: expected expression
./prog:81: expected expression
./prog:81: expected expression