Skip to content

Commit 6cc5d20

Browse files
sgramponeBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:gamsaml20' into beta
1 parent fbdf12a commit 6cc5d20

File tree

12 files changed

+174
-296
lines changed

12 files changed

+174
-296
lines changed

gamsaml20/src/main/java/com/genexus/saml20/Binding.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44
public abstract class Binding {
55

66
abstract void init(String input);
7-
static String login(SamlParms parms, String relayState) { return ""; }
8-
static String logout(SamlParms parms, String relayState) { return ""; }
7+
8+
static String login(SamlParms parms, String relayState) {
9+
return "";
10+
}
11+
12+
static String logout(SamlParms parms, String relayState) {
13+
return "";
14+
}
15+
916
abstract boolean verifySignatures(SamlParms parms);
17+
1018
abstract String getLoginAssertions();
19+
1120
abstract String getLoginAttribute(String name);
21+
1222
abstract String getRoles(String name);
23+
1324
abstract String getLogoutAssertions();
1425
}

gamsaml20/src/main/java/com/genexus/saml20/PostBinding.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,57 @@
1010
import java.text.MessageFormat;
1111

1212
@SuppressWarnings("unused")
13-
public class PostBinding extends Binding{
13+
public class PostBinding extends Binding {
1414

1515
private static final Logger logger = LogManager.getLogger(PostBinding.class);
1616

1717
private Document xmlDoc;
1818

19-
public PostBinding()
20-
{
19+
public PostBinding() {
2120
logger.trace("PostBinding constructor");
2221
xmlDoc = null;
2322
}
2423
// EXTERNAL OBJECT PUBLIC METHODS - BEGIN
2524

2625

27-
public void init(String xml)
28-
{
26+
public void init(String xml) {
2927
logger.trace("init");
3028
this.xmlDoc = SamlAssertionUtils.canonicalizeXml(xml);
3129
logger.debug(MessageFormat.format("Init - XML IdP response: {0}", Encoding.documentToString(xmlDoc)));
3230
}
3331

34-
public static String login(SamlParms parms, String relayState)
35-
{
32+
public static String login(SamlParms parms, String relayState) {
3633
//not implemented yet
3734
logger.error("login - NOT IMPLEMENTED");
3835
return "";
3936
}
4037

41-
public static String logout(SamlParms parms, String relayState)
42-
{
38+
public static String logout(SamlParms parms, String relayState) {
4339
//not implemented yet
4440
logger.error("logout - NOT IMPLEMENTED");
4541
return "";
4642
}
4743

48-
public boolean verifySignatures(SamlParms parms)
49-
{
44+
public boolean verifySignatures(SamlParms parms) {
5045
return DSig.validateSignatures(this.xmlDoc, parms.getTrustCertPath(), parms.getTrustCertAlias(), parms.getTrustCertPass());
5146
}
5247

53-
public String getLoginAssertions()
54-
{
48+
public String getLoginAssertions() {
5549
logger.trace("getLoginAssertions");
5650
return SamlAssertionUtils.getLoginInfo(this.xmlDoc);
5751
}
5852

59-
public String getLogoutAssertions()
60-
{
53+
public String getLogoutAssertions() {
6154
logger.trace("getLogoutAssertions");
6255
return SamlAssertionUtils.getLogoutInfo(this.xmlDoc);
6356
}
6457

65-
public String getLoginAttribute(String name)
66-
{
58+
public String getLoginAttribute(String name) {
6759
logger.trace("getLoginAttribute");
6860
return SamlAssertionUtils.getLoginAttribute(this.xmlDoc, name);
6961
}
7062

71-
public String getRoles(String name)
72-
{
63+
public String getRoles(String name) {
7364
logger.debug("getRoles");
7465
return SamlAssertionUtils.getRoles(this.xmlDoc, name);
7566
}

gamsaml20/src/main/java/com/genexus/saml20/RedirectBinding.java

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.Map;
2020

2121
@SuppressWarnings("unused")
22-
public class RedirectBinding extends Binding{
22+
public class RedirectBinding extends Binding {
2323

2424
private static final Logger logger = LogManager.getLogger(RedirectBinding.class);
2525

@@ -29,13 +29,11 @@ public class RedirectBinding extends Binding{
2929
// EXTERNAL OBJECT PUBLIC METHODS - BEGIN
3030

3131

32-
public RedirectBinding()
33-
{
32+
public RedirectBinding() {
3433
logger.trace("RedirectBinding constructor");
3534
}
3635

37-
public void init(String queryString)
38-
{
36+
public void init(String queryString) {
3937
logger.trace("init");
4038
logger.debug(MessageFormat.format("init - queryString : {0}", queryString));
4139
this.redirectMessage = parseRedirect(queryString);
@@ -46,89 +44,75 @@ public void init(String queryString)
4644
}
4745

4846

49-
public static String login(SamlParms parms, String relayState)
50-
{
47+
public static String login(SamlParms parms, String relayState) {
5148
Document request = SamlAssertionUtils.createLoginRequest(parms.getId(), parms.getDestination(), parms.getAcs(), parms.getIssuer(), parms.getPolicyFormat(), parms.getAuthnContext(), parms.getSPName(), parms.getForceAuthn());
5249
return generateQuery(request, parms.getDestination(), parms.getCertPath(), parms.getCertPass(), parms.getCertAlias(), relayState);
5350
}
5451

55-
public static String logout(SamlParms parms, String relayState)
56-
{
52+
public static String logout(SamlParms parms, String relayState) {
5753
Document request = SamlAssertionUtils.createLogoutRequest(parms.getId(), parms.getIssuer(), parms.getNameID(), parms.getSessionIndex(), parms.getDestination());
5854
return generateQuery(request, parms.getDestination(), parms.getCertPath(), parms.getCertPass(), parms.getCertAlias(), relayState);
5955
}
6056

61-
public boolean verifySignatures(SamlParms parms)
62-
{
57+
public boolean verifySignatures(SamlParms parms) {
6358
logger.debug("verifySignatures");
6459

65-
try
66-
{
60+
try {
6761
return DSig.validateSignatures(this.xmlDoc, parms.getTrustCertPath(), parms.getTrustCertAlias(), parms.getTrustCertPass());
68-
}catch(Exception e)
69-
{
62+
} catch (Exception e) {
7063
logger.error("verifySignature", e);
7164
return false;
7265
}
7366
}
7467

75-
public String getLogoutAssertions()
76-
{
68+
public String getLogoutAssertions() {
7769
logger.trace("getLogoutAssertions");
7870
return SamlAssertionUtils.getLogoutInfo(this.xmlDoc);
7971
}
8072

81-
public String getRelayState()
82-
{
73+
public String getRelayState() {
8374
logger.trace("getRelayState");
8475
try {
8576
return this.redirectMessage.get("RelayState") == null ? "" : URLDecoder.decode(this.redirectMessage.get("RelayState"), StandardCharsets.UTF_8.name());
86-
}catch (Exception e)
87-
{
77+
} catch (Exception e) {
8878
logger.error("getRelayState", e);
8979
return "";
9080
}
9181
}
9282

93-
public String getLoginAssertions()
94-
{
83+
public String getLoginAssertions() {
9584
//Getting user's data by URL parms (GET) is deemed insecure so we are not implementing this method for redirect binding
9685
logger.error("getLoginAssertions - NOT IMPLEMENTED insecure SAML implementation");
9786
return "";
9887
}
9988

100-
public String getRoles(String name)
101-
{
89+
public String getRoles(String name) {
10290
//Getting user's data by URL parms (GET) is deemed insecure so we are not implementing this method for redirect binding
10391
logger.error("getRoles - NOT IMPLEMENTED insecure SAML implementation");
10492
return "";
10593
}
10694

107-
public String getLoginAttribute(String name)
108-
{
95+
public String getLoginAttribute(String name) {
10996
//Getting user's data by URL parms (GET) is deemed insecure so we are not implementing this method for redirect binding
11097
logger.error("getLoginAttribute - NOT IMPLEMENTED insecure SAML implementation");
11198
return "";
11299
}
113100

114101
// EXTERNAL OBJECT PUBLIC METHODS - END
115102

116-
private static Map<String, String> parseRedirect(String request)
117-
{
103+
private static Map<String, String> parseRedirect(String request) {
118104
logger.trace("parseRedirect");
119-
Map<String,String> result = new HashMap<>();
105+
Map<String, String> result = new HashMap<>();
120106
String[] redirect = request.split("&");
121107

122-
for(String s : redirect)
123-
{
108+
for (String s : redirect) {
124109
String[] res = s.split("=");
125110
result.put(res[0], res[1]);
126111
}
127112
return result;
128113
}
129114

130-
private static String generateQuery(Document request, String destination, String certPath, String certPass, String alias, String relayState)
131-
{
115+
private static String generateQuery(Document request, String destination, String certPath, String certPass, String alias, String relayState) {
132116
logger.trace("generateQuery");
133117
try {
134118
String samlRequestParameter = Encoding.delfateAndEncodeXmlParameter(Encoding.documentToString(request));
@@ -143,25 +127,22 @@ private static String generateQuery(Document request, String destination, String
143127

144128
logger.debug(MessageFormat.format("generateQuery - query: {0}", query));
145129
return MessageFormat.format("{0}?{1}", destination, query);
146-
}catch (Exception e)
147-
{
130+
} catch (Exception e) {
148131
logger.error("generateQuery", e);
149132
return "";
150133
}
151134

152135
}
153136

154-
private static String signRequest_RedirectBinding(String query, String path, String password, Hash hash, String alias)
155-
{
137+
private static String signRequest_RedirectBinding(String query, String path, String password, Hash hash, String alias) {
156138
logger.trace("signRequest_RedirectBinding");
157-
RSADigestSigner signer= new RSADigestSigner(Hash.getDigest(hash));
139+
RSADigestSigner signer = new RSADigestSigner(Hash.getDigest(hash));
158140
byte[] inputText = query.getBytes(StandardCharsets.UTF_8);
159141
try (InputStream inputStream = new ByteArrayInputStream(inputText)) {
160142
setUpSigner(signer, inputStream, Keys.loadPrivateKey(path, alias, password), true);
161143
byte[] outputBytes = signer.generateSignature();
162144
return Base64.toBase64String(outputBytes);
163-
}catch (Exception e)
164-
{
145+
} catch (Exception e) {
165146
logger.error("signRequest_RedirectBinding", e);
166147
return "";
167148
}

0 commit comments

Comments
 (0)