-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #416 from wttech/de-kotlin
rewritten Kotlin source code to Java
- Loading branch information
Showing
108 changed files
with
4,551 additions
and
3,649 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/aem/core/src/main/java/com/cognifide/apm/core/crypto/DecryptionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*- | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
package com.cognifide.apm.core.crypto; | ||
|
||
import com.adobe.granite.crypto.CryptoException; | ||
import com.adobe.granite.crypto.CryptoSupport; | ||
import com.cognifide.apm.core.Property; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.apache.commons.lang.text.StrSubstitutor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
@Component( | ||
service = DecryptionService.class, | ||
property = { | ||
Property.DESCRIPTION + "APM Service for decryption encrypted values", | ||
Property.VENDOR | ||
} | ||
) | ||
public class DecryptionService { | ||
|
||
@Reference | ||
private CryptoSupport cryptoSupport; | ||
|
||
public String decrypt(String text) { | ||
Map<String, String> tokens = Optional.ofNullable(StringUtils.substringsBetween(text, "{", "}")) | ||
.map(Arrays::stream) | ||
.orElse(Stream.empty()) | ||
.distinct() | ||
.collect(Collectors.toMap(Function.identity(), token -> unprotect("{" + token + "}"))); | ||
StrSubstitutor strSubstitutor = new StrSubstitutor(tokens, "{", "}"); | ||
return tokens.isEmpty() ? text : strSubstitutor.replace(text); | ||
} | ||
|
||
protected String unprotect(String text) { | ||
try { | ||
return cryptoSupport.unprotect(text); | ||
} catch (CryptoException e) { | ||
throw new IllegalArgumentException(String.format("Unable to decrypt '%s', wrong hmac or master key", text), e); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/aem/core/src/main/java/com/cognifide/apm/core/crypto/ProtectTextForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
|
||
package com.cognifide.apm.core.crypto; | ||
|
||
import com.cognifide.apm.core.endpoints.params.RequestParameter; | ||
import javax.inject.Inject; | ||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.models.annotations.Model; | ||
|
||
@Model(adaptables = SlingHttpServletRequest.class) | ||
public class ProtectTextForm { | ||
|
||
@Inject | ||
@RequestParameter(value = "text", optional = false) | ||
private String text; | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/aem/core/src/main/java/com/cognifide/apm/core/crypto/ProtectTextServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
package com.cognifide.apm.core.crypto; | ||
|
||
import com.adobe.granite.crypto.CryptoException; | ||
import com.adobe.granite.crypto.CryptoSupport; | ||
import com.cognifide.apm.core.Property; | ||
import com.cognifide.apm.core.endpoints.response.ResponseEntity; | ||
import com.cognifide.apm.core.endpoints.utils.RequestProcessor; | ||
import java.io.IOException; | ||
import javax.servlet.Servlet; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.SlingHttpServletResponse; | ||
import org.apache.sling.api.servlets.SlingAllMethodsServlet; | ||
import org.apache.sling.models.factory.ModelFactory; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
@Component( | ||
service = Servlet.class, | ||
property = { | ||
Property.PATH + "/bin/apm/scripts/protect", | ||
Property.METHOD + "POST", | ||
Property.DESCRIPTION + "APM Encrypt Text Servlet", | ||
Property.VENDOR | ||
} | ||
) | ||
public class ProtectTextServlet extends SlingAllMethodsServlet { | ||
|
||
@Reference | ||
private CryptoSupport cryptoSupport; | ||
|
||
@Reference | ||
private ModelFactory modelFactory; | ||
|
||
@Override | ||
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { | ||
RequestProcessor.process(modelFactory, ProtectTextForm.class, request, response, (form, resourceResolver) -> { | ||
try { | ||
return ResponseEntity.ok("Text successfully encrypted") | ||
.addEntry("text", cryptoSupport.protect(form.getText())); | ||
} catch (CryptoException e) { | ||
return ResponseEntity.badRequest(StringUtils.defaultString(e.getMessage(), "Errors while encrypting text")); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.