Skip to content

Commit 90ea56f

Browse files
committed
Mendix v9.0.5 Project files
1 parent 3ff5aa4 commit 90ea56f

274 files changed

Lines changed: 36153 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Source/AdministrationModule.mpr

13.4 MB
Binary file not shown.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package mendixsso.actions;
11+
12+
import com.mendix.systemwideinterfaces.MendixRuntimeException;
13+
import com.mendix.systemwideinterfaces.core.IContext;
14+
import com.mendix.webui.CustomJavaAction;
15+
import javax.crypto.BadPaddingException;
16+
import javax.crypto.Cipher;
17+
import javax.crypto.spec.GCMParameterSpec;
18+
import javax.crypto.spec.IvParameterSpec;
19+
import javax.crypto.spec.SecretKeySpec;
20+
import java.security.InvalidAlgorithmParameterException;
21+
import java.util.Base64;
22+
23+
public class DecryptString extends CustomJavaAction<java.lang.String>
24+
{
25+
private java.lang.String value;
26+
private java.lang.String key;
27+
private java.lang.String prefix;
28+
29+
public DecryptString(IContext context, java.lang.String value, java.lang.String key, java.lang.String prefix)
30+
{
31+
super(context);
32+
this.value = value;
33+
this.key = key;
34+
this.prefix = prefix;
35+
}
36+
37+
@java.lang.Override
38+
public java.lang.String executeAction() throws Exception
39+
{
40+
// BEGIN USER CODE
41+
if (this.value == null || !isStartsWithRightPrefix())
42+
return null;
43+
if (this.prefix == null || this.prefix.isEmpty())
44+
throw new MendixRuntimeException("Prefix should not be empty");
45+
if (this.key == null || this.key.isEmpty())
46+
throw new MendixRuntimeException("Key should not be empty");
47+
if (this.key.length() != 16)
48+
throw new MendixRuntimeException("Key length should be 16");
49+
50+
String decryptedText = null;
51+
52+
if (isEncryptedWithLegacyAlgorithm(this.value)) {
53+
decryptedText = decryptUsingLegacyAlgorithm();
54+
} else {
55+
decryptedText = decryptUsingGcm();
56+
}
57+
58+
return decryptedText;
59+
// END USER CODE
60+
}
61+
62+
/**
63+
* Returns a string representation of this action
64+
*/
65+
@java.lang.Override
66+
public java.lang.String toString()
67+
{
68+
return "DecryptString";
69+
}
70+
71+
// BEGIN EXTRA CODE
72+
private final int GCM_TAG_LENGTH = 16; // in bytes
73+
private final String LEGACY_PREFIX = "{AES}";
74+
private final String WRONG_KEY_ERROR_MESSAGE = "Cannot decrypt the text because it was either NOT encrypted with a key of length 16 or they key is different";
75+
76+
private String decryptUsingGcm() throws Exception {
77+
String[] s = this.value.substring(this.prefix.length()).split(";");
78+
79+
if (s.length < 2) //Not an encrypted string, just return the original value.
80+
return this.value;
81+
82+
Cipher c = Cipher.getInstance("AES/GCM/PKCS5PADDING");
83+
SecretKeySpec k = new SecretKeySpec(this.key.getBytes(), "AES");
84+
85+
try {
86+
GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, Base64.getDecoder().decode(s[0]));
87+
c.init(Cipher.DECRYPT_MODE, k, spec);
88+
byte[] encryptedData = Base64.getDecoder().decode(s[1]);
89+
return new String(c.doFinal(encryptedData));
90+
} catch (InvalidAlgorithmParameterException | BadPaddingException ex) {
91+
if (isEncryptedWithWrongKey(ex.getMessage()))
92+
throw new MendixRuntimeException(WRONG_KEY_ERROR_MESSAGE);
93+
else throw ex;
94+
}
95+
}
96+
97+
private boolean isEncryptedWithWrongKey(String message) {
98+
return
99+
message.equals("Wrong IV length: must be 16 bytes long") ||
100+
message.equals("Given final block not properly padded");
101+
}
102+
103+
private String decryptUsingLegacyAlgorithm() throws Exception {
104+
String[] s = this.value.substring(LEGACY_PREFIX.length()).split(";");
105+
106+
if (s.length < 2) //Not an encrypted string, just return the original value.
107+
return this.value;
108+
109+
Cipher c = Cipher.getInstance("AES/CBC/PKCS5PADDING");
110+
SecretKeySpec k = new SecretKeySpec(this.key.getBytes(), "AES");
111+
112+
try {
113+
c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(Base64.getDecoder().decode(s[0])));
114+
byte[] encryptedData = Base64.getDecoder().decode(s[1]);
115+
return new String(c.doFinal(encryptedData));
116+
} catch (InvalidAlgorithmParameterException | BadPaddingException ex) {
117+
if (isEncryptedWithWrongKey(ex.getMessage()))
118+
throw new MendixRuntimeException(WRONG_KEY_ERROR_MESSAGE);
119+
else throw ex;
120+
}
121+
}
122+
123+
private boolean isEncryptedWithLegacyAlgorithm(String text) {
124+
return text.startsWith(LEGACY_PREFIX);
125+
}
126+
127+
private boolean isStartsWithRightPrefix() {
128+
return this.value.startsWith(this.value) || isEncryptedWithLegacyAlgorithm(this.value);
129+
}
130+
// END EXTRA CODE
131+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package mendixsso.actions;
11+
12+
import com.mendix.systemwideinterfaces.MendixRuntimeException;
13+
import com.mendix.systemwideinterfaces.core.IContext;
14+
import com.mendix.webui.CustomJavaAction;
15+
import javax.crypto.Cipher;
16+
import javax.crypto.spec.SecretKeySpec;
17+
import java.util.Base64;
18+
19+
public class EncryptString extends CustomJavaAction<java.lang.String>
20+
{
21+
private java.lang.String value;
22+
private java.lang.String key;
23+
private java.lang.String prefix;
24+
25+
public EncryptString(IContext context, java.lang.String value, java.lang.String key, java.lang.String prefix)
26+
{
27+
super(context);
28+
this.value = value;
29+
this.key = key;
30+
this.prefix = prefix;
31+
}
32+
33+
@java.lang.Override
34+
public java.lang.String executeAction() throws Exception
35+
{
36+
// BEGIN USER CODE
37+
if (this.value == null)
38+
return null;
39+
if (this.prefix == null || this.prefix.isEmpty())
40+
throw new MendixRuntimeException("Prefix should not be empty");
41+
if (this.key == null || this.key.isEmpty())
42+
throw new MendixRuntimeException("Key should not be empty");
43+
if (this.key.length() != 16)
44+
throw new MendixRuntimeException("Key length should be 16");
45+
Cipher c = Cipher.getInstance("AES/GCM/PKCS5PADDING");
46+
SecretKeySpec k = new SecretKeySpec(this.key.getBytes(), "AES");
47+
c.init(Cipher.ENCRYPT_MODE, k);
48+
49+
byte[] encryptedData = c.doFinal(this.value.getBytes());
50+
byte[] iv = c.getIV();
51+
52+
return new StringBuilder(this.prefix +
53+
new String(Base64.getEncoder().encode(iv))).append(";").append(
54+
new String(Base64.getEncoder().encode(encryptedData))).toString();
55+
// END USER CODE
56+
}
57+
58+
/**
59+
* Returns a string representation of this action
60+
*/
61+
@java.lang.Override
62+
public java.lang.String toString()
63+
{
64+
return "EncryptString";
65+
}
66+
67+
// BEGIN EXTRA CODE
68+
// END EXTRA CODE
69+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package mendixsso.actions;
11+
12+
import com.mendix.core.Core;
13+
import com.mendix.logging.ILogNode;
14+
import com.mendix.systemwideinterfaces.core.IContext;
15+
import com.mendix.systemwideinterfaces.core.IMendixObject;
16+
import com.mendix.webui.CustomJavaAction;
17+
import mendixsso.implementation.UserManager;
18+
import mendixsso.implementation.utils.ForeignIdentityUtils;
19+
import mendixsso.implementation.utils.OpenIDUtils;
20+
import mendixsso.implementation.utils.UserProfileUtils;
21+
import mendixsso.proxies.UserProfile;
22+
import mendixsso.proxies.constants.Constants;
23+
24+
public class FindOrCreateUserWithUserInfo extends CustomJavaAction<IMendixObject>
25+
{
26+
private java.lang.String UserInfoJSON;
27+
28+
public FindOrCreateUserWithUserInfo(IContext context, java.lang.String UserInfoJSON)
29+
{
30+
super(context);
31+
this.UserInfoJSON = UserInfoJSON;
32+
}
33+
34+
@java.lang.Override
35+
public IMendixObject executeAction() throws Exception
36+
{
37+
// BEGIN USER CODE
38+
final ILogNode LOG = Core.getLogger(Constants.getLogNode());
39+
final IContext context = Core.createSystemContext();
40+
IMendixObject user = null;
41+
String uuid = null;
42+
try {
43+
final UserProfile userProfile = UserProfileUtils.getUserProfile(context, UserInfoJSON);
44+
45+
// We assume that openId cannot be null since that would imply bigger issues higher up in the SSO stack.
46+
uuid = OpenIDUtils.extractUUID(userProfile.getOpenId());
47+
ForeignIdentityUtils.lockForeignIdentity(uuid);
48+
49+
user = UserManager.findOrCreateUser(userProfile).getMendixObject();
50+
} catch (Throwable e) {
51+
LOG.error("Something went wrong while provisioning the user with the provided user info", e);
52+
} finally {
53+
if (uuid != null) {
54+
ForeignIdentityUtils.unlockForeignIdentity(uuid);
55+
}
56+
}
57+
return user;
58+
// END USER CODE
59+
}
60+
61+
/**
62+
* Returns a string representation of this action
63+
*/
64+
@java.lang.Override
65+
public java.lang.String toString()
66+
{
67+
return "FindOrCreateUserWithUserInfo";
68+
}
69+
70+
// BEGIN EXTRA CODE
71+
// END EXTRA CODE
72+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package mendixsso.actions;
11+
12+
import com.mendix.systemwideinterfaces.core.IContext;
13+
import com.mendix.webui.CustomJavaAction;
14+
import mendixsso.implementation.utils.OpenIDUtils;
15+
16+
/**
17+
* Generate a valid strong random password for Mendix user
18+
*/
19+
public class GenerateRandomPassword extends CustomJavaAction<java.lang.String>
20+
{
21+
private java.lang.Long length;
22+
23+
public GenerateRandomPassword(IContext context, java.lang.Long length)
24+
{
25+
super(context);
26+
this.length = length;
27+
}
28+
29+
@java.lang.Override
30+
public java.lang.String executeAction() throws Exception
31+
{
32+
// BEGIN USER CODE
33+
return OpenIDUtils.randomStrongPassword(length.intValue(), length.intValue(), 7, 9, 6);
34+
// END USER CODE
35+
}
36+
37+
/**
38+
* Returns a string representation of this action
39+
*/
40+
@java.lang.Override
41+
public java.lang.String toString()
42+
{
43+
return "GenerateRandomPassword";
44+
}
45+
46+
// BEGIN EXTRA CODE
47+
// END EXTRA CODE
48+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package mendixsso.actions;
11+
12+
import com.mendix.core.Core;
13+
import com.mendix.systemwideinterfaces.core.IContext;
14+
import com.mendix.webui.CustomJavaAction;
15+
import mendixsso.implementation.oidp.IdentityProviderMetaDataCache;
16+
import mendixsso.proxies.constants.Constants;
17+
18+
public class GetTokenEndpointURI extends CustomJavaAction<java.lang.String>
19+
{
20+
public GetTokenEndpointURI(IContext context)
21+
{
22+
super(context);
23+
}
24+
25+
@java.lang.Override
26+
public java.lang.String executeAction() throws Exception
27+
{
28+
// BEGIN USER CODE
29+
try {
30+
return IdentityProviderMetaDataCache.getInstance().getIdentityProviderMetaData().getProviderMetadata().getTokenEndpointURI().toString();
31+
} catch (Exception e) {
32+
Core.getLogger(Constants.getLogNode()).error("Something went wrong while retrieving the token endpoint URI from cache", e);
33+
return null;
34+
}
35+
// END USER CODE
36+
}
37+
38+
/**
39+
* Returns a string representation of this action
40+
*/
41+
@java.lang.Override
42+
public java.lang.String toString()
43+
{
44+
return "GetTokenEndpointURI";
45+
}
46+
47+
// BEGIN EXTRA CODE
48+
// END EXTRA CODE
49+
}

0 commit comments

Comments
 (0)