Skip to content

Commit 3d03ce8

Browse files
committed
Fix indentation
1 parent 81c7bf3 commit 3d03ce8

2 files changed

Lines changed: 98 additions & 100 deletions

File tree

com/onelogin/saml/AuthRequest.java

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616

1717
public class AuthRequest {
1818

19-
private final String id;
19+
private final String id;
2020
private final String issueInstant;
2121
private final AppSettings appSettings;
2222
public static final int base64 = 1;
23-
private Deflater deflater;
23+
private Deflater deflater;
2424

2525
public AuthRequest(AppSettings appSettings, AccountSettings accountSettings){
26-
this.appSettings = appSettings;
26+
this.appSettings = appSettings;
2727
id="_"+UUID.randomUUID().toString();
2828
SimpleDateFormat simpleDf = new SimpleDateFormat("yyyy-MM-dd'T'H:mm:ss'Z'");
2929
issueInstant = simpleDf.format(new Date());
3030
}
3131

3232
public String getRequest(int format) throws XMLStreamException, IOException {
33-
String result = "";
33+
String result = "";
3434

3535
ByteArrayOutputStream baos = new ByteArrayOutputStream();
3636

@@ -67,55 +67,54 @@ public String getRequest(int format) throws XMLStreamException, IOException {
6767
writer.writeEndElement();
6868

6969
writer.writeEndElement();
70-
writer.writeEndElement();
70+
writer.writeEndElement();
7171
writer.flush();
7272

73-
result = encodeSAMLRequest(baos.toByteArray());
74-
return result;
73+
result = encodeSAMLRequest(baos.toByteArray());
74+
return result;
7575
}
7676

77-
public static String getRidOfCRLF(String what) {
78-
String lf = "%0D";
79-
String cr = "%0A";
80-
String now = lf;
81-
82-
int index = what.indexOf(now);
83-
StringBuilder r = new StringBuilder();
77+
public static String getRidOfCRLF(String what) {
78+
String lf = "%0D";
79+
String cr = "%0A";
80+
String now = lf;
81+
int index = what.indexOf(now);
8482

85-
while (index!=-1) {
86-
r.append(what.substring(0,index));
87-
what = what.substring(index+3,what.length());
83+
StringBuilder r = new StringBuilder();
8884

89-
if (now.equals(lf)) {
90-
now = cr;
91-
} else {
92-
now = lf;
93-
}
85+
while (index!=-1) {
86+
r.append(what.substring(0,index));
87+
what = what.substring(index+3,what.length());
9488

95-
index = what.indexOf(now);
96-
}
97-
return r.toString();
98-
}
89+
if (now.equals(lf)) {
90+
now = cr;
91+
} else {
92+
now = lf;
93+
}
9994

100-
private String encodeSAMLRequest(byte[] pSAMLRequest) throws RuntimeException {
95+
index = what.indexOf(now);
96+
}
97+
return r.toString();
98+
}
10199

102-
Base64 base64Encoder = new Base64();
100+
private String encodeSAMLRequest(byte[] pSAMLRequest) throws RuntimeException {
103101

104-
try {
105-
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
106-
Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
102+
Base64 base64Encoder = new Base64();
107103

108-
DeflaterOutputStream def = new DeflaterOutputStream(byteArray, deflater);
109-
def.write(pSAMLRequest);
110-
def.close();
111-
byteArray.close();
104+
try {
105+
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
106+
Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
112107

113-
String stream = new String(base64Encoder.encode(byteArray.toByteArray()));
108+
DeflaterOutputStream def = new DeflaterOutputStream(byteArray, deflater);
109+
def.write(pSAMLRequest);
110+
def.close();
111+
byteArray.close();
114112

115-
return stream;
116-
} catch (Exception e) {
117-
throw new RuntimeException(e);
118-
}
119-
}
113+
String stream = new String(base64Encoder.encode(byteArray.toByteArray()));
120114

115+
return stream;
116+
} catch (Exception e) {
117+
throw new RuntimeException(e);
118+
}
119+
}
121120
}

com/onelogin/saml/Response.java

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -53,77 +53,76 @@ public void loadXmlFromBase64(String response) throws ParserConfigurationExcepti
5353
loadXml(decodedS);
5454
}
5555

56-
public boolean isValid() throws Exception {
57-
NodeList nodes = xmlDoc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
56+
public boolean isValid() throws Exception {
57+
NodeList nodes = xmlDoc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
5858

59-
if (nodes == null || nodes.getLength() == 0) {
60-
throw new Exception("Can't find signature in document.");
61-
}
59+
if (nodes == null || nodes.getLength() == 0) {
60+
throw new Exception("Can't find signature in document.");
61+
}
6262

63-
if (setIdAttributeExists()) {
64-
tagIdAttributes(xmlDoc);
65-
}
63+
if (setIdAttributeExists()) {
64+
tagIdAttributes(xmlDoc);
65+
}
6666

67-
X509Certificate cert = certificate.getX509Cert();
68-
DOMValidateContext ctx = new DOMValidateContext(cert.getPublicKey(), nodes.item(0));
69-
XMLSignatureFactory sigF = XMLSignatureFactory.getInstance("DOM");
70-
XMLSignature xmlSignature = sigF.unmarshalXMLSignature(ctx);
67+
X509Certificate cert = certificate.getX509Cert();
68+
DOMValidateContext ctx = new DOMValidateContext(cert.getPublicKey(), nodes.item(0));
69+
XMLSignatureFactory sigF = XMLSignatureFactory.getInstance("DOM");
70+
XMLSignature xmlSignature = sigF.unmarshalXMLSignature(ctx);
7171

72-
return xmlSignature.validate(ctx);
73-
}
72+
return xmlSignature.validate(ctx);
73+
}
7474

7575
public String getNameId() throws Exception {
76-
NodeList nodes = xmlDoc.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "NameID");
76+
NodeList nodes = xmlDoc.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "NameID");
7777

78-
if(nodes.getLength()==0){
79-
throw new Exception("No name id found in document");
80-
}
78+
if(nodes.getLength()==0){
79+
throw new Exception("No name id found in document");
80+
}
8181

82-
return nodes.item(0).getTextContent();
82+
return nodes.item(0).getTextContent();
8383
}
8484

85-
public String getAttribute(String name) {
86-
HashMap attributes = getAttributes();
87-
if (!attributes.isEmpty()) {
88-
return attributes.get(name).toString();
89-
}
90-
return null;
91-
}
85+
public String getAttribute(String name) {
86+
HashMap attributes = getAttributes();
87+
if (!attributes.isEmpty()) {
88+
return attributes.get(name).toString();
89+
}
90+
return null;
91+
}
9292

93-
public HashMap getAttributes() {
94-
HashMap<String,ArrayList> attributes = new HashMap<>();
95-
NodeList nodes = xmlDoc.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute");
96-
97-
if(nodes.getLength()!=0){
98-
for (int i = 0; i < nodes.getLength(); i++) {
99-
NamedNodeMap attrName = nodes.item(i).getAttributes();
100-
String attName = attrName.getNamedItem("Name").getNodeValue();
101-
NodeList children = nodes.item(i).getChildNodes();
102-
103-
ArrayList<String> attrValues = new ArrayList<String>();
104-
for (int j = 0; j < children.getLength(); j++) {
105-
attrValues.add(children.item(j).getTextContent());
106-
}
107-
attributes.put(attName, attrValues);
108-
}
109-
} else
110-
return null;
111-
return attributes;
93+
public HashMap getAttributes() {
94+
HashMap<String,ArrayList> attributes = new HashMap<>();
95+
NodeList nodes = xmlDoc.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute");
96+
97+
if(nodes.getLength()!=0){
98+
for (int i = 0; i < nodes.getLength(); i++) {
99+
NamedNodeMap attrName = nodes.item(i).getAttributes();
100+
String attName = attrName.getNamedItem("Name").getNodeValue();
101+
NodeList children = nodes.item(i).getChildNodes();
102+
103+
ArrayList<String> attrValues = new ArrayList<String>();
104+
for (int j = 0; j < children.getLength(); j++) {
105+
attrValues.add(children.item(j).getTextContent());
106+
}
107+
attributes.put(attName, attrValues);
108+
}
109+
} else {
110+
return null;
111+
}
112+
return attributes;
112113
}
113114

114-
private boolean setIdAttributeExists() {
115-
for (Method method : Element.class.getDeclaredMethods()) {
116-
if (method.getName().equals("setIdAttribute")) {
117-
return true;
118-
}
119-
}
120-
return false;
121-
}
122-
123-
private void tagIdAttributes(Document xmlDoc) {
124-
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
125-
}
126-
127-
115+
private boolean setIdAttributeExists() {
116+
for (Method method : Element.class.getDeclaredMethods()) {
117+
if (method.getName().equals("setIdAttribute")) {
118+
return true;
119+
}
120+
}
121+
return false;
122+
}
128123

124+
private void tagIdAttributes(Document xmlDoc) {
125+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
126+
}
129127
}
128+

0 commit comments

Comments
 (0)