-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Do not create session for login url #10460
- Loading branch information
Showing
8 changed files
with
129 additions
and
110 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...portal/portal-impl/src/main/java/com/enonic/xp/portal/impl/RedirectChecksumGenerator.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,67 @@ | ||
package com.enonic.xp.portal.impl; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import javax.crypto.KeyGenerator; | ||
import javax.crypto.Mac; | ||
import javax.crypto.SecretKey; | ||
import javax.crypto.spec.SecretKeySpec; | ||
|
||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
import com.enonic.xp.core.internal.HexCoder; | ||
import com.enonic.xp.shared.SharedMap; | ||
import com.enonic.xp.shared.SharedMapService; | ||
|
||
@Component(service = RedirectChecksumGenerator.class) | ||
public class RedirectChecksumGenerator | ||
{ | ||
private final SharedMap<String, Object> sharedMap; | ||
|
||
@Activate | ||
public RedirectChecksumGenerator( @Reference final SharedMapService sharedMapService ) | ||
{ | ||
this.sharedMap = sharedMapService.getSharedMap( "com.enonic.xp.internal.shared" ); | ||
} | ||
|
||
public String generateChecksum( final String redirect ) | ||
{ | ||
final SecretKey key = new SecretKeySpec( (byte[]) sharedMap.modify( "redirectTicketKey", orig -> { | ||
|
||
if ( orig != null ) | ||
{ | ||
return orig; | ||
} | ||
|
||
final KeyGenerator keyGenerator; | ||
try | ||
{ | ||
keyGenerator = KeyGenerator.getInstance( "HmacSHA1" ); | ||
Check failure Code scanning / CodeQL Use of a broken or risky cryptographic algorithm High
Cryptographic algorithm
HmacSHA1 Error loading related location |
||
} | ||
catch ( NoSuchAlgorithmException e ) | ||
{ | ||
throw new IllegalStateException( e ); | ||
} | ||
return keyGenerator.generateKey().getEncoded(); | ||
|
||
} ), "HmacSHA1" ); | ||
Check failure Code scanning / CodeQL Use of a broken or risky cryptographic algorithm High
Cryptographic algorithm
HmacSHA1 Error loading related location |
||
|
||
final Mac mac; | ||
try | ||
{ | ||
mac = Mac.getInstance( key.getAlgorithm() ); | ||
|
||
mac.init( key ); | ||
} | ||
catch ( NoSuchAlgorithmException | InvalidKeyException e ) | ||
{ | ||
throw new RuntimeException( e ); | ||
} | ||
|
||
return HexCoder.toHex( mac.doFinal( redirect.getBytes( StandardCharsets.UTF_8 ) ) ); | ||
} | ||
} |
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
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.