-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* zowe jwt Signed-off-by: achmelo <[email protected]> * translate x509 into zoweJWT Signed-off-by: achmelo <[email protected]> * update header after LB Signed-off-by: achmelo <[email protected]> * integration tests for zowejwtscheme Signed-off-by: achmelo <[email protected]> * fix tests Signed-off-by: achmelo <[email protected]> * run when zosmf auth tests Signed-off-by: achmelo <[email protected]> * hostname Signed-off-by: achmelo <[email protected]> * cleanup Signed-off-by: achmelo <[email protected]> * common string Signed-off-by: achmelo <[email protected]> * get JWT in create command Signed-off-by: achmelo <[email protected]> * send empty header in case of missing auth in request Signed-off-by: achmelo <[email protected]> * return empty command Signed-off-by: achmelo <[email protected]> * translate all exceptions from createTokenWithoutCreds into custom so it can be propagated with zuul exception Signed-off-by: achmelo <[email protected]> * use header to inform about transformation failure Signed-off-by: achmelo <[email protected]> * styles Signed-off-by: achmelo <[email protected]> * custom exception, code smells Signed-off-by: achmelo <[email protected]> * override default method Signed-off-by: achmelo <[email protected]> * documentation, mark applyToRequest as deprecated Signed-off-by: achmelo <[email protected]> * return failure header to client Signed-off-by: achmelo <[email protected]> * inform about invalid token Signed-off-by: achmelo <[email protected]> * higher timeout Signed-off-by: achmelo <[email protected]> * higher timeout all container tests Signed-off-by: achmelo <[email protected]> * remove cookie and add error header if token is expired Signed-off-by: achmelo <[email protected]>
- Loading branch information
Showing
16 changed files
with
591 additions
and
83 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
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
73 changes: 73 additions & 0 deletions
73
gateway-service/src/main/java/org/zowe/apiml/gateway/security/service/schema/JwtCommand.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,73 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
package org.zowe.apiml.gateway.security.service.schema; | ||
|
||
import com.netflix.zuul.context.RequestContext; | ||
import org.apache.http.HttpRequest; | ||
import org.zowe.apiml.util.CookieUtil; | ||
import org.zowe.apiml.util.Cookies; | ||
|
||
import java.net.HttpCookie; | ||
|
||
public abstract class JwtCommand extends AuthenticationCommand { | ||
|
||
public static final String COOKIE_HEADER = "cookie"; | ||
public static final String AUTH_FAIL_HEADER = "X-Zowe-Auth-Failure"; | ||
|
||
public static void createCookie(Cookies cookies, String name, String token) { | ||
HttpCookie jwtCookie = new HttpCookie(name, token); | ||
jwtCookie.setSecure(true); | ||
jwtCookie.setHttpOnly(true); | ||
jwtCookie.setVersion(0); | ||
cookies.set(jwtCookie); | ||
} | ||
|
||
public static void setCookie(RequestContext context, String name, String value) { | ||
context.addZuulRequestHeader(COOKIE_HEADER, | ||
CookieUtil.setCookie( | ||
context.getZuulRequestHeaders().get(COOKIE_HEADER), | ||
name, | ||
value | ||
) | ||
); | ||
} | ||
|
||
public static void setErrorHeader(RequestContext context, String value) { | ||
context.addZuulRequestHeader(AUTH_FAIL_HEADER, value); | ||
context.addZuulResponseHeader(AUTH_FAIL_HEADER, value); | ||
} | ||
|
||
public static void addErrorHeader(HttpRequest request, String value) { | ||
request.addHeader(AUTH_FAIL_HEADER, value); | ||
} | ||
|
||
public static void removeCookie(RequestContext context, String name) { | ||
context.addZuulRequestHeader(COOKIE_HEADER, | ||
CookieUtil.removeCookie( | ||
context.getZuulRequestHeaders().get(COOKIE_HEADER), | ||
name | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean isExpired() { | ||
if (getExpireAt() == null) return false; | ||
|
||
return System.currentTimeMillis() > getExpireAt(); | ||
} | ||
|
||
@Override | ||
public boolean isRequiredValidSource() { | ||
return true; | ||
} | ||
|
||
public abstract Long getExpireAt(); | ||
} |
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.