getNativeLibrariesNames();
16 | }
17 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/ZosUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos;
11 |
12 | public class ZosUtils {
13 | private ZosUtils() {
14 | // no instances
15 | }
16 |
17 | /**
18 | * @return True when running on z/OS.
19 | */
20 | public static boolean isRunningOnZos() {
21 | String osName = System.getProperty("os.name");
22 | return "z/OS".equals(osName);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/authentication/ZosAuthenticationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.authentication;
11 |
12 | import org.springframework.security.core.AuthenticationException;
13 | import org.zowe.commons.zos.security.platform.PlatformReturned;
14 |
15 | public class ZosAuthenticationException extends AuthenticationException {
16 | private static final long serialVersionUID = 6652673387938170807L;
17 | private final PlatformReturned platformReturned;
18 |
19 | public ZosAuthenticationException(String message, PlatformReturned platformReturned) {
20 | super(message);
21 | this.platformReturned = platformReturned;
22 | }
23 |
24 | public PlatformReturned getPlatformReturned() {
25 | return platformReturned;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/jni/Secur.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.jni;
11 |
12 | import static org.zowe.commons.zos.CommonsNativeLibraries.SECUR_LIBRARY_NAME;
13 |
14 | import org.zowe.commons.zos.LibLoader;
15 |
16 | import lombok.extern.slf4j.Slf4j;
17 |
18 | @Slf4j
19 | public class Secur {
20 | public Secur() {
21 | new LibLoader().loadLibrary(SECUR_LIBRARY_NAME);
22 | }
23 |
24 | public native int createSecurityEnvironment(String userid, String password, String applId);
25 |
26 | public native int createSecurityEnvironmentByDaemon(String userid, String applId);
27 |
28 | public native int removeSecurityEnvironment();
29 |
30 | public native int getLastErrno2();
31 |
32 | public native int setApplid(String applid);
33 | }
34 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/MockPlatformUser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | public class MockPlatformUser implements PlatformUser {
13 | // Sonar exclusion: The passwords are using only for testing with this mock
14 |
15 | public static final String VALID_USERID = "zowe";
16 | public static final String VALID_USERID2 = "zowe2";
17 | public static final String VALID_PASSWORD = "zowe"; // NOSONAR
18 | public static final String INVALID_USERID = "notzowe";
19 | public static final String INVALID_PASSWORD = "notzowe"; // NOSONAR
20 | public static final String EXPIRED_PASSWORD = "expired"; // NOSONAR
21 | public static final String FAILING_PASSWORD = "failing"; // NOSONAR
22 |
23 | @Override
24 | public PlatformReturned authenticate(String userid, String password) {
25 | if ((userid.equalsIgnoreCase(VALID_USERID) || userid.equalsIgnoreCase(VALID_USERID2))
26 | && password.equalsIgnoreCase(VALID_PASSWORD)) {
27 | return null;
28 | } else {
29 | PlatformReturned.PlatformReturnedBuilder builder = PlatformReturned.builder().success(false);
30 | if (EXPIRED_PASSWORD.equalsIgnoreCase(password)) {
31 | builder.errno(PlatformPwdErrno.EMVSEXPIRE.errno);
32 | } else if (FAILING_PASSWORD.equalsIgnoreCase(password)) {
33 | builder.errno(PlatformPwdErrno.EMVSERR.errno).errno2(PlatformErrno2.JREnvDirty.errno2);
34 | }
35 | return builder.build();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformClassFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | /**
13 | * Creates classes for platform-specific behavior. The purpose is wrap original
14 | * classes without interfaces and with static methods into classes that
15 | * implement interfaces. Implementations of this class factory can either return
16 | * the original z/OS classes or dummy implementations to enable unit testing or
17 | * running off z/OS for development purposes.
18 | */
19 | public interface PlatformClassFactory {
20 | Class> getPlatformReturnedClass() throws ClassNotFoundException;
21 |
22 | Class> getPlatformUserClass() throws ClassNotFoundException;
23 |
24 | Object getPlatformUser();
25 |
26 | Class> getPlatformAccessControlClass() throws ClassNotFoundException;
27 |
28 | Object getPlatformAccessControl() throws ClassNotFoundException;
29 |
30 | PlatformReturned convertPlatformReturned(Object safReturned)
31 | throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException;
32 | }
33 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformErrorType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | public enum PlatformErrorType {
13 | /**
14 | * Error during the security processing which means that security product did
15 | * not allow the action but no details should be shared with the user - e.g.
16 | * invalid user ID or password
17 | */
18 | DEFAULT,
19 | /**
20 | * Error during the security processing which means that security product did
21 | * not allow the action and details should be shared with the user - e.g expired
22 | * password
23 | */
24 | USER_EXPLAINED,
25 | /**
26 | * Internal failure during the security processing which means that security
27 | * product or the service are not configured properly
28 | */
29 | INTERNAL,
30 | /**
31 | * errno2 value is required to understand the cause of the failure
32 | */
33 | ERRNO2_REQUIRED
34 | }
35 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformReturned.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | import java.io.IOException;
13 | import java.io.ObjectInputStream;
14 | import java.io.ObjectOutputStream;
15 | import java.io.Serializable;
16 |
17 | import lombok.Builder;
18 | import lombok.Data;
19 |
20 | /**
21 | * More details about the z/OS security call results.
22 | *
23 | * See also:
24 | * https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.zsecurity.api.80.doc/com.ibm.os390.security/com/ibm/os390/security/PlatformReturned.html
25 | */
26 | @Data
27 | @Builder
28 | public class PlatformReturned implements Serializable {
29 |
30 | private static final long serialVersionUID = -2699057722238941755L;
31 |
32 | private boolean success;
33 | private int rc;
34 | private int errno;
35 | private int errno2;
36 | private String errnoMsg;
37 | private String stringRet;
38 | private transient Object objectRet;
39 |
40 | private void readObject(ObjectInputStream ois) throws IOException {
41 | success = ois.readBoolean();
42 | rc = ois.readInt();
43 | errno = ois.readInt();
44 | errno2 = ois.readInt();
45 | errnoMsg = ois.readUTF();
46 | stringRet = ois.readUTF();
47 | objectRet = this;
48 | }
49 |
50 | private void writeObject(ObjectOutputStream oos) throws IOException {
51 | oos.writeBoolean(success);
52 | oos.writeInt(rc);
53 | oos.writeInt(errno);
54 | oos.writeInt(errno2);
55 | oos.writeUTF(errnoMsg);
56 | oos.writeUTF(stringRet);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | /**
13 | * Interface to z/OS thread-level information.
14 | *
15 | * It is inspired by
16 | * https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.zsecurity.api.80.doc/com.ibm.os390.security/com/ibm/os390/security/PlatformThread.html
17 | * class. But it provides interface instead of class with static methods so
18 | * non-z/OS implementation of this inteface can be created.
19 | */
20 | public interface PlatformThread {
21 | /**
22 | * @return User ID associated with the current thread.
23 | */
24 | String getUserName();
25 | }
26 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformUser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | /**
13 | * Interface to do z/OS user authentication.
14 | *
15 | * It is inspired by
16 | * https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.zsecurity.api.80.doc/com.ibm.os390.security/com/ibm/os390/security/PlatformUser.html
17 | * class. But it provides interface instead of class with static methods so
18 | * non-z/OS implementation of this interface can be created.
19 | */
20 | public interface PlatformUser {
21 | /**
22 | * Authenticates an user.
23 | *
24 | * @return If successful, a null object is returned. If not successful an instance of
25 | * the PlatformReturned class is returned.
26 | */
27 | PlatformReturned authenticate(String userid, String password);
28 | }
29 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | public class SafConstants {
13 | private SafConstants() {
14 | // no instances
15 | }
16 |
17 | public static final String CLASS_FACILITY = "FACILITY";
18 | public static final String BPX_SERVER = "BPX.SERVER";
19 | }
20 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafPlatformError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | public class SafPlatformError extends RuntimeException {
13 | private static final long serialVersionUID = 1920433542069453114L;
14 |
15 | public SafPlatformError(Throwable e) {
16 | super(e);
17 | }
18 |
19 | public SafPlatformError(String message, Exception e) {
20 | super(message, e);
21 | }
22 |
23 | public SafPlatformError(String message) {
24 | super(message);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafPlatformThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | import java.lang.reflect.InvocationTargetException;
13 |
14 | public class SafPlatformThread implements PlatformThread {
15 |
16 | @Override
17 | public String getUserName() {
18 | try {
19 | return (String) Class.forName("com.ibm.os390.security.PlatformThread").getMethod("getUserName")
20 | .invoke(null);
21 |
22 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
23 | | SecurityException | ClassNotFoundException e) {
24 | throw new SafPlatformError(e.getMessage(), e);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafPlatformUser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | import java.lang.reflect.InvocationTargetException;
13 |
14 | public class SafPlatformUser implements PlatformUser {
15 | private final PlatformClassFactory platformClassFactory;
16 |
17 | public SafPlatformUser(PlatformClassFactory platformClassFactory) {
18 | this.platformClassFactory = platformClassFactory;
19 | }
20 |
21 | @Override
22 | public PlatformReturned authenticate(String userid, String password) {
23 | if ((password == null) || password.isEmpty()) {
24 | return PlatformReturned.builder().success(false).rc(0).errno(PlatformPwdErrno.EINVAL.errno).errno2(PlatformErrno2.ERRNO2_BASE | PlatformErrno2.JRPasswordLenError.errno2).build();
25 | }
26 | try {
27 | Object safReturned = platformClassFactory.getPlatformUserClass()
28 | .getMethod("authenticate", String.class, String.class)
29 | .invoke(platformClassFactory.getPlatformUser(), userid, password);
30 | if (safReturned == null) {
31 | return null;
32 | } else {
33 | return platformClassFactory.convertPlatformReturned(safReturned);
34 | }
35 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
36 | | SecurityException | ClassNotFoundException | NoSuchFieldException e) {
37 | throw new SafPlatformError(e.getMessage(), e);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | import org.zowe.commons.zos.ZosUtils;
13 | import org.zowe.commons.zos.security.jni.Secur;
14 |
15 | public class SafUtils {
16 |
17 | private static final SetApplid SECUR;
18 |
19 | static {
20 | if (ZosUtils.isRunningOnZos()) {
21 | SECUR = new SetApplid() {
22 |
23 | private final Secur secur = new Secur();
24 |
25 | @Override
26 | public int setApplid(String applid) {
27 | return secur.setApplid(applid);
28 | }
29 |
30 | };
31 | } else {
32 | SECUR = applId -> 0;
33 | }
34 | }
35 |
36 | /**
37 | * Sets the APPLID for the current thread so the PlatformUser.authenticate can
38 | * use PassTickets for the provide APPLID.
39 | *
40 | * The APPLID can be changed but not unset.
41 | *
42 | * @param applid The APPLID to be set. Up to 8 characters.
43 | */
44 | public static void setThreadApplid(String applid) {
45 | if ((applid == null) || applid.isEmpty()) {
46 | return;
47 | }
48 |
49 | SECUR.setApplid(applid);
50 | }
51 |
52 | private interface SetApplid {
53 |
54 | int setApplid(String applId);
55 |
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/service/AccessControlError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.service;
11 |
12 | import org.zowe.commons.zos.security.platform.PlatformReturned;
13 |
14 | public class AccessControlError extends RuntimeException {
15 | private static final long serialVersionUID = -101853226410917728L;
16 | private final PlatformReturned platformReturned;
17 |
18 | public AccessControlError(String message, PlatformReturned platformReturned) {
19 | super(message);
20 | this.platformReturned = platformReturned;
21 | }
22 |
23 | public PlatformReturned getPlatformReturned() {
24 | return platformReturned;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/service/SecurityRequestFailed.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.service;
11 |
12 | import lombok.Getter;
13 |
14 | public class SecurityRequestFailed extends RuntimeException {
15 | private static final long serialVersionUID = 6832104396884487813L;
16 |
17 | @Getter
18 | private final String module;
19 | @Getter
20 | private final int function;
21 | @Getter
22 | private final int errno;
23 |
24 | public SecurityRequestFailed(String module, int function, int errno, Throwable cause) {
25 | super(String.format("Platform security request has failed: module=%s, function=%d, errno=%d", module, function,
26 | errno), cause);
27 | this.module = module;
28 | this.function = function;
29 | this.errno = errno;
30 | }
31 |
32 | public SecurityRequestFailed(String module, int function, int errno) {
33 | this(module, function, errno, null);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/thread/CallInThreadLevelSecurityEnvironmentByDaemon.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.thread;
11 |
12 | import java.util.concurrent.Callable;
13 |
14 | import org.springframework.security.core.Authentication;
15 | import org.springframework.util.Assert;
16 | import org.zowe.commons.zos.security.service.PlatformSecurityService;
17 |
18 | public final class CallInThreadLevelSecurityEnvironmentByDaemon implements Callable {
19 | private final PlatformSecurityService service;
20 | private final Callable callable;
21 | private final Authentication authentication;
22 |
23 | public CallInThreadLevelSecurityEnvironmentByDaemon(PlatformSecurityService service, Callable callable,
24 | Authentication authentication) {
25 | Assert.notNull(service, "service cannot be null");
26 | Assert.notNull(callable, "callable cannot be null");
27 | Assert.notNull(authentication, "authentication cannot be null");
28 | this.service = service;
29 | this.callable = callable;
30 | this.authentication = authentication;
31 | }
32 |
33 | @Override
34 | public T call() throws Exception {
35 | createSecurityEnvironment();
36 | try {
37 | return callable.call();
38 | } finally {
39 | service.removeThreadSecurityContext();
40 | }
41 | }
42 |
43 | private void createSecurityEnvironment() {
44 | service.createThreadSecurityContextByDaemon(authentication.getName(), null);
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return callable.toString();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/thread/PlatformThreadLevelSecurity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.thread;
11 |
12 | import org.springframework.security.core.context.SecurityContext;
13 |
14 | import java.util.concurrent.Callable;
15 |
16 | public interface PlatformThreadLevelSecurity {
17 | Runnable wrapRunnableInEnvironmentForAuthenticatedUser(Runnable runnable);
18 |
19 | Runnable wrapRunnableInEnvironment(Runnable runnable, SecurityContext authentication);
20 |
21 | Callable wrapCallableInEnvironmentForAuthenticatedUser(Callable runnable);
22 |
23 | Callable wrapCallableInEnvironment(Callable runnable, SecurityContext authentication);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/thread/RunInThreadLevelSecurityEnvironmentByDaemon.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.thread;
11 |
12 | import org.springframework.security.core.Authentication;
13 | import org.springframework.util.Assert;
14 | import org.zowe.commons.zos.security.service.PlatformSecurityService;
15 |
16 | public final class RunInThreadLevelSecurityEnvironmentByDaemon implements Runnable {
17 | private final PlatformSecurityService service;
18 | private final Runnable runnable;
19 | private final Authentication authentication;
20 |
21 | public RunInThreadLevelSecurityEnvironmentByDaemon(PlatformSecurityService service, Runnable runnable,
22 | Authentication authentication) {
23 | Assert.notNull(service, "service cannot be null");
24 | Assert.notNull(runnable, "runnable cannot be null");
25 | Assert.notNull(authentication, "authentication cannot be null");
26 | this.service = service;
27 | this.runnable = runnable;
28 | this.authentication = authentication;
29 | }
30 |
31 | @Override
32 | public void run() {
33 | createSecurityEnvironment();
34 | try {
35 | runnable.run();
36 | } finally {
37 | service.removeThreadSecurityContext();
38 | }
39 | }
40 |
41 | private void createSecurityEnvironment() {
42 | service.createThreadSecurityContextByDaemon(authentication.getName(), null);
43 | }
44 |
45 | @Override
46 | public String toString() {
47 | return runnable.toString();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/resources/commons-messages_cs.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This program and the accompanying materials are made available and may be used, at your option, under either:
3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | #
6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | #
8 | # Copyright Contributors to the Zowe Project.
9 | #
10 |
11 | messages.org.zowe.commons.error.invalidMessageKey.text=Interní chyba: Neplatný klíč zprávy '%s'. Další pomoc vám poskytne technická podpora.
12 | messages.org.zowe.commons.error.invalidMessageKey.reason=Toto je interní chyba. Produkt se pokusil získat přístup ke zprávě pomocí klíče, který není definován.
13 | messages.org.zowe.commons.error.invalidMessageKey.action=Další pomoc vám poskytne technická podpora.
14 |
15 | messages.org.zowe.commons.rest.notFound.text=Služba nemůže najít požadovaný zdroj.
16 | messages.org.zowe.commons.service.started.text='%s' se spustila za %.3f sekund
17 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/main/resources/lib/README.md:
--------------------------------------------------------------------------------
1 | # `resources/lib` folder
2 |
3 | This folder is a placeholder for `.so` files that are z/OS shared object libraries.
4 |
5 | Zowe GitHub repositories cannot contain binary files so you need to build it using
6 | `zowe-api-dev zosbuild` command.
7 |
8 | This folder `resources/lib` is packaged into the JAR file. `.so` files in the JAR file
9 | can be extracted to regular files using `LibsExtractor`.
10 | These files need to be executable and program-controlled on z/OS in order to be loadable by Java.
11 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/AccentStrippingPatternLayerEncoderTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons;
11 |
12 | import static org.junit.Assert.assertEquals;
13 | import static org.mockito.Mockito.mock;
14 | import static org.mockito.Mockito.when;
15 |
16 | import org.junit.Test;
17 |
18 | import ch.qos.logback.classic.spi.ILoggingEvent;
19 | import ch.qos.logback.core.Layout;
20 |
21 | public class AccentStrippingPatternLayerEncoderTests {
22 | @Test
23 | public void testWrapRunnableInEnvironmentForAuthenticatedUser() {
24 | AccentStrippingPatternLayerEncoder encoder = new AccentStrippingPatternLayerEncoder();
25 | Layout layout = mock(Layout.class);
26 | ILoggingEvent event = null;
27 | when(layout.doLayout(event)).thenReturn("Příliš žluťoučký kůň úpěl ďábelské ódy");
28 | encoder.overrideLayout(layout);
29 | encoder.setStripAccents(true);
30 | byte[] bytes = encoder.encode(event);
31 | assertEquals("Prilis zlutoucky kun upel dabelske ody", new String(bytes));
32 | encoder.setStripAccents(false);
33 | byte[] bytes2 = encoder.encode(event);
34 | assertEquals("Příliš žluťoučký kůň úpěl ďábelské ódy", new String(bytes2));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/apiml/ApimlIntegrationFailureDetectorTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.apiml;
11 |
12 | import ch.qos.logback.classic.Level;
13 | import ch.qos.logback.classic.Logger;
14 | import ch.qos.logback.classic.LoggerContext;
15 | import ch.qos.logback.core.spi.FilterReply;
16 | import org.junit.Test;
17 | import org.zowe.commons.spring.SpringContext;
18 |
19 | import javax.net.ssl.SSLHandshakeException;
20 | import javax.net.ssl.SSLPeerUnverifiedException;
21 |
22 | import static org.junit.Assert.*;
23 |
24 | public class ApimlIntegrationFailureDetectorTests {
25 |
26 | @Test
27 | public void ApiMediationClientErrorIsDetected() {
28 | new SpringContext().setApplicationContext(null);
29 | ApimlIntegrationFailureDetector detector = new ApimlIntegrationFailureDetector();
30 | assertEquals(FilterReply.NEUTRAL,
31 | detector.decide(null, null, Level.INFO, null, null, new NullPointerException()));
32 | assertFalse(detector.reportFatalError(Level.INFO, new NullPointerException()));
33 | assertTrue(detector.reportFatalError(Level.ERROR, new SSLHandshakeException("test")));
34 | assertTrue(detector.reportFatalError(Level.ERROR, new SSLPeerUnverifiedException("test")));
35 |
36 | LoggerContext ctx = new LoggerContext();
37 | Logger logger = ctx.getLogger("com.netflix.DiscoveryClient");
38 | logger.setLevel(Level.ERROR);
39 | assertEquals(FilterReply.DENY, detector.decide(null, logger, Level.ERROR,
40 | null, null, new NullPointerException("test")));
41 |
42 | logger = ctx.getLogger("com.netflix.RedirectingEurekaHttpClient");
43 | assertEquals(FilterReply.DENY, detector.decide(null, logger, Level.ERROR,
44 | null, null, new NullPointerException(null)));
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/error/CommonsErrorServiceTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.error;
11 |
12 | import static org.junit.Assert.assertTrue;
13 |
14 | import java.util.Locale;
15 |
16 | import org.junit.Test;
17 |
18 | public class CommonsErrorServiceTests {
19 | @Test
20 | public void returnsReadableMessage() {
21 | assertTrue(CommonsErrorService.get()
22 | .getReadableMessage("org.zowe.commons.apiml.serviceCertificateNotTrusted", "param").contains("param"));
23 | }
24 |
25 | @Test
26 | public void returnsLocalizedMessage() {
27 | assertTrue(CommonsErrorService.get()
28 | .createApiMessage(Locale.forLanguageTag("cs"), "org.zowe.commons.rest.notFound").getMessages().get(0)
29 | .getMessageContent().contains("Služba"));
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/rest/response/BasicMessageTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.rest.response;
11 |
12 | import org.junit.Test;
13 |
14 | import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
15 | import static org.junit.jupiter.api.Assertions.assertEquals;
16 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
17 |
18 | public class BasicMessageTest {
19 | private Message getTestErrorMessage() {
20 | return new BasicMessage(MessageType.ERROR, "MAS0001", "Message text.");
21 | }
22 |
23 | private Message getTestInfoMessage() {
24 | return new BasicMessage(MessageType.INFO, "MAS0002", "Message text.");
25 | }
26 |
27 | @Test
28 | public void toReadableText() {
29 | Message message = getTestErrorMessage();
30 | assertEquals("MAS0001E Message text.", message.toReadableText());
31 | }
32 |
33 | @Test
34 | public void testHashCode() {
35 | Message message = getTestErrorMessage();
36 | assertNotEquals(0, message.hashCode());
37 | }
38 |
39 | @Test
40 | public void testEquals() {
41 | Message message = getTestErrorMessage();
42 | Message differentMessage = getTestInfoMessage();
43 | assertEquals(message, message);
44 | assertNotEquals(message, differentMessage);
45 | }
46 |
47 | @Test
48 | public void basicJsonFormat() {
49 | assertThatJson(getTestErrorMessage()).whenIgnoringPaths("messageInstanceId").isEqualTo("{\n" + " \"messageType\" : \"ERROR\",\n"
50 | + " \"messageNumber\" : \"MAS0001\",\n" + " \"messageContent\" : \"Message text.\"\n" + "}");
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/spring/DefaultMessageSourceTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.spring;
11 |
12 | import static org.junit.Assert.assertTrue;
13 |
14 | import org.junit.Test;
15 | import org.springframework.mock.env.MockEnvironment;
16 | import org.zowe.commons.error.CommonsErrorService;
17 |
18 | public class DefaultMessageSourceTests {
19 | @Test
20 | public void defaultMessageSourceContainsPortAndServiceName() {
21 | DefaultMessageSource defaultMessageSource = new DefaultMessageSource(CommonsErrorService.get(), new MockEnvironment().withProperty("apiml.service.serviceId", "testservice").withProperty("server.port", "1234"));
22 | defaultMessageSource.onApplicationEvent(null);
23 | assertTrue(CommonsErrorService.get().getDefaultMessageSource().endsWith(":1234:testservice"));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/spring/EnableEurekaLoggingTimerTaskTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.spring;
11 |
12 | import static org.junit.Assert.assertTrue;
13 | import static org.zowe.commons.spring.EnableEurekaLoggingTimerTask.EUREKA_LOGGER_NAMES;
14 |
15 | import org.junit.Test;
16 | import org.slf4j.LoggerFactory;
17 |
18 | import ch.qos.logback.classic.LoggerContext;
19 |
20 | public class EnableEurekaLoggingTimerTaskTests {
21 | SpringContext context = new SpringContext();
22 |
23 | @Test
24 | public void enableEurekaLoggingTimerTaskDoesNotFail() {
25 | LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
26 |
27 | new EnableEurekaLoggingTimerTask().run();
28 | for (String name : EUREKA_LOGGER_NAMES) {
29 | assertTrue(loggerContext.getLogger(name).isErrorEnabled());
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/spring/SpringContextTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.spring;
11 |
12 | import static org.junit.Assert.assertEquals;
13 |
14 | import org.junit.Test;
15 | import org.springframework.beans.factory.NoSuchBeanDefinitionException;
16 | import org.springframework.context.ApplicationContext;
17 | import org.springframework.context.support.GenericApplicationContext;
18 |
19 | public class SpringContextTests {
20 | SpringContext context = new SpringContext();
21 |
22 | @Test
23 | public void getApplicationContextReturnsSetContext() {
24 | try {
25 | ApplicationContext newContext = new GenericApplicationContext();
26 | context.setApplicationContext(newContext);
27 | assertEquals(newContext, SpringContext.getApplicationContext());
28 | } finally {
29 | context.setApplicationContext(null);
30 | }
31 | }
32 |
33 | @Test(expected = NoSuchBeanDefinitionException.class)
34 | public void getBeanFailsForNonExistentBean() {
35 | try {
36 | GenericApplicationContext newContext = new GenericApplicationContext();
37 | newContext.refresh();
38 | context.setApplicationContext(newContext);
39 | SpringContext.getBean(SpringContext.class);
40 | } finally {
41 | context.setApplicationContext(null);
42 | }
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/zos/security/platform/BadMockPlatformClassFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | public class BadMockPlatformClassFactory implements PlatformClassFactory {
13 |
14 | @Override
15 | public Class> getPlatformUserClass() throws ClassNotFoundException {
16 | return Class.forName("bad");
17 | }
18 |
19 | @Override
20 | public Class> getPlatformReturnedClass() throws ClassNotFoundException {
21 | return Class.forName("bad");
22 | }
23 |
24 | @Override
25 | public Object getPlatformUser() {
26 | return null;
27 | }
28 |
29 | @Override
30 | public Class> getPlatformAccessControlClass() throws ClassNotFoundException {
31 | return Class.forName("bad");
32 | }
33 |
34 | @Override
35 | public Object getPlatformAccessControl() throws ClassNotFoundException {
36 | return null;
37 | }
38 |
39 | @Override
40 | public PlatformReturned convertPlatformReturned(Object safReturned) throws ClassNotFoundException,
41 | IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
42 | return null;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/zos/security/platform/MockPlatformClassFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.commons.zos.security.platform;
11 |
12 | public class MockPlatformClassFactory implements PlatformClassFactory {
13 |
14 | @Override
15 | public Class> getPlatformUserClass() throws ClassNotFoundException {
16 | return MockPlatformUser.class;
17 | }
18 |
19 | @Override
20 | public Class> getPlatformReturnedClass() throws ClassNotFoundException {
21 | return PlatformReturned.class;
22 | }
23 |
24 | @Override
25 | public Object getPlatformUser() {
26 | return new MockPlatformUser();
27 | }
28 |
29 | @Override
30 | public Class> getPlatformAccessControlClass() throws ClassNotFoundException {
31 | return MockPlatformAccessControl.class;
32 | }
33 |
34 | @Override
35 | public Object getPlatformAccessControl() throws ClassNotFoundException {
36 | return new MockPlatformAccessControl();
37 | }
38 |
39 | @Override
40 | public PlatformReturned convertPlatformReturned(Object safReturned) throws ClassNotFoundException,
41 | IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
42 | return (PlatformReturned) safReturned;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/zos/security/platform/PlatformErnnoTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 |
11 | package org.zowe.commons.zos.security.platform;
12 |
13 | import static org.junit.Assert.assertEquals;
14 |
15 | import org.junit.Test;
16 |
17 | public class PlatformErnnoTests {
18 | @Test
19 | public void returnsErrno2ValueFromLongHexValue() {
20 | assertEquals(PlatformErrno2.JRSAFResourceUndefined, PlatformErrno2.valueOfErrno(0x93800CF));
21 | }
22 |
23 | @Test
24 | public void returnsAckErrnoValueFromInt() {
25 | assertEquals(PlatformAckErrno.ESRCH, PlatformAckErrno.valueOfErrno(143));
26 | }
27 |
28 | @Test
29 | public void returnsTlsErrnoValueFromInt() {
30 | assertEquals(PlatformTlsErrno.ESRCH, PlatformTlsErrno.valueOfErrno(143));
31 | }
32 |
33 | @Test
34 | public void returnsPwdErrnoValueFromInt() {
35 | assertEquals(PlatformPwdErrno.ESRCH, PlatformPwdErrno.valueOfErrno(143));
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/resources/test-duplicate-messages.yml:
--------------------------------------------------------------------------------
1 | messages:
2 | - key: org.zowe.commons.test.noArguments
3 | number: CSC0001
4 | type: ERROR
5 | text: "No arguments message"
6 |
7 | - key: org.zowe.commons.test.noArguments
8 | number: CSC0001
9 | type: ERROR
10 | text: "No arguments message"
11 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/resources/test-messages.yml:
--------------------------------------------------------------------------------
1 | messages:
2 | - key: org.zowe.commons.test.noArguments
3 | number: CSC0001
4 | type: ERROR
5 | text: "No arguments message"
6 |
7 | - key: org.zowe.commons.test.invalidParameterFormat
8 | number: TST0001
9 | type: INFO
10 | text: "Test message - expects decimal number %d"
11 |
12 | - key: org.zowe.commons.test.reason
13 | number: CSC0002
14 | type: ERROR
15 | text: "No arguments message"
16 | reason: Reason
17 |
18 | - key: org.zowe.commons.test.action
19 | number: CSC0003
20 | type: ERROR
21 | text: "No arguments message"
22 | action: Action
23 |
24 | - key: org.zowe.commons.test.reasonAndAction
25 | number: CSC0004
26 | type: ERROR
27 | text: "No arguments message"
28 | reason: Reason
29 | action: Action
30 |
31 | - key: org.zowe.commons.test.component
32 | number: CSC0005
33 | type: ERROR
34 | text: "No arguments message"
35 | component: zowe.sdk.commons.test
36 |
37 | - key: org.zowe.commons.test.localized
38 | number: CSC0006
39 | type: INFO
40 | text: "Localized message"
41 | component: "Component"
42 |
43 | - key: org.zowe.commons.test.parameters
44 | number: CSC0007
45 | type: INFO
46 | text: "Test message - expects decimal number %2$d and %1$s"
47 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/resources/test-messages_cs.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This program and the accompanying materials are made available and may be used, at your option, under either:
3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | #
6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | #
8 | # Copyright Contributors to the Zowe Project.
9 | #
10 |
11 | messages.org.zowe.commons.test.localized.text: Lokalizovaná zpráva
12 | messages.org.zowe.commons.test.localized.reason: Důvod
13 | messages.org.zowe.commons.test.localized.action: Akce
14 | messages.org.zowe.commons.test.localized.component: Komponenta
15 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/resources/test-saf-invalid.yml:
--------------------------------------------------------------------------------
1 | # This file is used by the SafPlatformAccessControlTests class for testing how the invalid definition is handled
2 | # `WRONG_LEVEL` is an invalid access level
3 | safAccess:
4 | ZOWE:
5 | RESOURCE:
6 | WRONG_LEVEL:
7 | - ZOWE
8 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/src/test/resources/test-saf.yml:
--------------------------------------------------------------------------------
1 | # This file is used by the MockPlatformAccessControl class for testing and when the service is running outside of z/OS
2 | # It defines what are the access levels for SAF resources and users
3 | #
4 | # There are to special values of access level:
5 | # - `FAILURE` - the check request will fail with an internal error
6 | # - `NONE` - there is no access to the resource but the resource is defined
7 | #
8 | # This file is stored in `src/test/resources/test-saf.yml` which means that it will be used by the unit tests only.
9 | #
10 | safAccess:
11 | FACILITY: # class
12 | BPX.SERVER: # resource
13 | READ: # access level
14 | - ZOWE # users
15 | BPX.DAEMON:
16 | UPDATE:
17 | - ZOWE
18 | ZOWE:
19 | SAMPLE.RESOURCE:
20 | UPDATE:
21 | - ZOWE
22 | - ZOWE2
23 | FAILING:
24 | FAILURE:
25 | - ZOWE
26 | - ZOWE2
27 | DENIED:
28 | NONE:
29 | - NONE
30 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/zossrc/jnitools.c:
--------------------------------------------------------------------------------
1 | #define _OPEN_SYS 1
2 | #include
3 | #include
4 | #include "jnitools.h"
5 |
6 | char *jstring_to_ebcdic(JNIEnv *env, jstring jstr)
7 | {
8 | if (jstr == NULL)
9 | {
10 | return NULL;
11 | }
12 |
13 | int len;
14 | jint rc = GetStringPlatformLength(env, jstr, &len, "IBM-1047");
15 | if (rc != 0)
16 | {
17 | return NULL;
18 | }
19 |
20 | char *str = __malloc31(len);
21 | rc = GetStringPlatform(env, jstr, str, len, "IBM-1047");
22 | if (rc != 0)
23 | {
24 | free(str);
25 | return NULL;
26 | }
27 |
28 | return str;
29 | }
30 |
31 | void free_if_not_null(void *ptr)
32 | {
33 | if (ptr != NULL)
34 | {
35 | free(ptr);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/zossrc/jnitools.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | char *jstring_to_ebcdic(JNIEnv *env, jstring jstr);
4 |
5 | void free_if_not_null(void *ptr);
6 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/zossrc/makefile:
--------------------------------------------------------------------------------
1 | # makefile boilerplate to build the JNI implementation (C++), metal C code, and
2 | # bind into a "shared object" called at REST API runtime via the /wto endpoint
3 | #
4 | # This program and the accompanying materials are made available and may be used, at your option, under either:
5 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
6 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
7 | #
8 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
9 | #
10 | # Copyright Contributors to the Zowe Project.
11 |
12 | CXX=xlc++
13 | CC=xlc
14 | ASM=as
15 |
16 | MTL_OPTS=metal,\
17 | langlvl(extended),\
18 | sscom,\
19 | nolongname,\
20 | inline,\
21 | genasm,\
22 | inlrpt,\
23 | csect,\
24 | nose,\
25 | lp64,\
26 | list,\
27 | warn64,\
28 | optimize(2),\
29 | list,\
30 | showinc,\
31 | showmacro,\
32 | source,\
33 | aggregate
34 |
35 | MTL_FLAGS=-S -W "c,$(MTL_OPTS)"
36 |
37 | MACLIBS=-ISYS1.MACLIB \
38 | -ICBC.SCCNSAM
39 |
40 | MTL_HEADERS=-I/usr/include/metal
41 |
42 | DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended),dll,xplink,exportall" \
43 | -qsearch=$(JAVA_HOME)/include \
44 | -qsource \
45 | -g \
46 | -c
47 |
48 | DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" \
49 | -g \
50 | -qsource
51 |
52 | ASM_FLAGS=-mrent
53 |
54 | SIDEDECKPATH = $(JAVA_HOME)/bin/j9vm
55 | SIDEDECK = libjvm
56 |
57 | PREFIX := "../lib/"
58 |
59 | LIB_SECUR = "libzowe-commons-secur.so"
60 |
61 | all: $(LIB_SECUR)
62 |
63 | install:
64 | mkdir -p $(PREFIX)
65 | cp -vp *.so $(PREFIX)
66 | ls -E $(PREFIX)
67 |
68 | $(LIB_SECUR): secur.o jnitools.o
69 | $(CXX) $(DLL_BND_FLAGS) -o $@ $(SIDEDECKPATH)/$(SIDEDECK).x jnitools.o $^ > $*.bind.lst
70 | extattr +p $@
71 |
72 | secur.o: secur.c
73 | $(CC) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^
74 |
75 | jnitools.o: jnitools.c
76 | $(CC) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^
77 |
78 | clean:
79 | rm *.o
80 | rm *.lst
81 | rm *.x
82 | rm *.so
83 | rm *.dbg
84 | rm *.s
85 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/zossrc/secur.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class org_zowe_commons_zos_security_jni_Secur */
4 |
5 | #ifndef _Included_org_zowe_commons_zos_security_jni_Secur
6 | #define _Included_org_zowe_commons_zos_security_jni_Secur
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: org_zowe_commons_zos_security_jni_Secur
12 | * Method: createSecurityEnvironment
13 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
14 | */
15 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_createSecurityEnvironment
16 | (JNIEnv *, jobject, jstring, jstring, jstring);
17 |
18 | /*
19 | * Class: org_zowe_commons_zos_security_jni_Secur
20 | * Method: createSecurityEnvironmentByDaemon
21 | * Signature: (Ljava/lang/String;Ljava/lang/String;)I
22 | */
23 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_createSecurityEnvironmentByDaemon
24 | (JNIEnv *, jobject, jstring, jstring);
25 |
26 | /*
27 | * Class: org_zowe_commons_zos_security_jni_Secur
28 | * Method: removeSecurityEnvironment
29 | * Signature: ()I
30 | */
31 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_removeSecurityEnvironment
32 | (JNIEnv *, jobject);
33 |
34 | /*
35 | * Class: org_zowe_commons_zos_security_jni_Secur
36 | * Method: getLastErrno2
37 | * Signature: ()I
38 | */
39 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_getLastErrno2
40 | (JNIEnv *, jobject);
41 |
42 | /*
43 | * Class: org_zowe_commons_zos_security_jni_Secur
44 | * Method: setApplid
45 | * Signature: (Ljava/lang/String;)I
46 | */
47 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_setApplid
48 | (JNIEnv *, jobject, jstring);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 | #endif
54 |
--------------------------------------------------------------------------------
/zowe-rest-api-commons-spring/zowe-api.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Zowe REST API Commons Library for Spring",
3 | "zosSourcesDir": "zossrc",
4 | "buildCommand": "make && make install",
5 | "buildFiles": {
6 | "libzowe-commons-secur.so": "src/main/resources/lib/libzowe-commons-secur.so"
7 | },
8 | "defaultDirName": "zowe-rest-api-commons-spring",
9 | "defaultHlqSegment": "ZOWE.SAMPLAPI.COMMONS",
10 | "zfsMegabytes": 10
11 | }
12 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .gradle
3 | build/
4 | gradle/wrapper/gradle-wrapper.jar
5 | !**/src/main/**
6 | !**/src/test/**
7 |
8 | ### STS ###
9 | .apt_generated
10 | .classpath
11 | .factorypath
12 | .project
13 | .settings
14 | .springBeans
15 | .sts4-cache
16 |
17 | ### IntelliJ IDEA ###
18 | .idea
19 | *.iws
20 | *.iml
21 | *.ipr
22 | out/
23 |
24 | ### NetBeans ###
25 | /nbproject/private/
26 | /nbbuild/
27 | /dist/
28 | /nbdist/
29 | /.nb-gradle/
30 |
31 | ### VS Code ###
32 | .vscode/
33 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/.licence/Apache-or-EPL-License-Header.txt:
--------------------------------------------------------------------------------
1 | This program and the accompanying materials are made available and may be used, at your option, under either:
2 | * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
3 | * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
4 |
5 | SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
6 |
7 | Copyright Contributors to the Zowe Project.
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/config/local/keystore.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-kotlin-spring/config/local/keystore.p12
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/config/local/local.yml:
--------------------------------------------------------------------------------
1 | # Configuration for running the locally on your workstation
2 | # It overrides service defaults provided in src/main/resources/local.yml
3 |
4 | spring.profiles.active: https
5 |
6 | server:
7 | address: 0.0.0.0
8 | port: 10090
9 | ssl:
10 | keyAlias: localhost
11 | keyPassword: password
12 | keyStore: config/local/keystore.p12 # For bootRun / CI
13 | # keyStore: zowe-rest-api-sample-kotlin-spring/config/local/keystore.p12 # For IDEA
14 | keyStorePassword: password
15 | keyStoreType: PKCS12
16 | trustStore: config/local/truststore.p12 # For bootRun / CI
17 | # trustStore: zowe-rest-api-sample-kotlin-spring/config/local/truststore.p12 # For IDEA
18 | trustStorePassword: password
19 | trustStoreType: PKCS12
20 |
21 | apiml:
22 | service:
23 | serviceId: zowekotlinsample
24 | hostname: localhost
25 | serviceIpAddress: 127.0.0.1
26 | port: ${server.port}
27 | baseUrl: ${apiml.service.scheme}://${apiml.service.hostname}:${apiml.service.port}
28 | discoveryServiceUrls:
29 | - https://localhost:10011/eureka
30 | ssl:
31 | enabled: true
32 | verifySslCertificatesOfServices: true
33 | ciphers: ${server.ssl.ciphers}
34 | protocol: ${server.ssl.protocol}
35 | enabled-protocols: ${server.ssl.protocol}
36 | keyStoreType: ${server.ssl.keyStoreType}
37 | trustStoreType: ${server.ssl.trustStoreType}
38 | keyAlias: ${server.ssl.keyAlias}
39 | keyPassword: ${server.ssl.keyPassword}
40 | keyStore: ${server.ssl.keyStore}
41 | keyStorePassword: ${server.ssl.keyStorePassword}
42 | trustStore: ${server.ssl.trustStore}
43 | trustStorePassword: ${server.ssl.trustStorePassword}
44 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/config/local/truststore.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-kotlin-spring/config/local/truststore.p12
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/config/zos/zos.yml.hbs:
--------------------------------------------------------------------------------
1 | # Configuration for running the on z/OS
2 | # It overrides service defaults provided in src/main/resources/application.yml
3 |
4 | spring.profiles.active: https
5 |
6 |
7 | server:
8 | address: 0.0.0.0
9 | port: {{port}}
10 | ssl:
11 | keyAlias: localhost
12 | keyPassword: password
13 | keyStore: etc/keystore.p12
14 | keyStorePassword: password
15 | keyStoreType: PKCS12
16 | trustStore: etc/truststore.p12
17 | trustStorePassword: password
18 | trustStoreType: PKCS12
19 |
20 | apiml:
21 | service:
22 | serviceId: zowekotlinsample
23 | hostname: localhost
24 | ipAddress: 127.0.0.1
25 | discoveryServiceUrls:
26 | - https://localhost:10021/eureka
27 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.caching=true
2 |
3 | # Repository URL for getting Zowe artifacts:
4 | zoweArtifactoryRepository=https://zowe.jfrog.io/zowe/libs-release
5 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/gradle/bootstrap/bootstrap-gradlew.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if not exist gradle/wrapper/gradle-wrapper.jar (
4 | echo Gradle wrapper not found. Attempting to download...
5 | powershell -Command "& {wget https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar -OutFile gradle/wrapper/gradle-wrapper.jar}"
6 | IF ERRORLEVEL 1 (
7 | echo Gradle wrapper download failed. Bootstrap failed.
8 | ) ELSE (
9 | echo Gradle wrapper download success. Bootstrap complete.
10 | )
11 | )
12 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/gradle/bootstrap/bootstrap-gradlew.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | if [ ! -f gradle/wrapper/gradle-wrapper.jar ]; then
4 | echo "Gradle wrapper not found. Attempting to download..."
5 | curl --silent --output gradle/wrapper/gradle-wrapper.jar \
6 | https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar
7 | rc=$?;
8 | if [ $rc != 0 ]; then
9 | echo "Gradle wrapper download failed. Bootstrap failed."
10 | exit 1
11 | else
12 | echo "Gradle wrapper download success. Bootstrap complete."
13 | exit 0
14 | fi
15 | else
16 | exit 0
17 | fi
18 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.name = "zowe-rest-api-sample-kotlin-spring"
2 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/integrationTest/kotlin/org/zowe/sample/kotlin/apiservice/greeting/GreetingControllerIntegrationTests.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.kotlin.apiservice.greeting
11 |
12 | import io.restassured.module.kotlin.extensions.Given
13 | import io.restassured.module.kotlin.extensions.Then
14 | import io.restassured.module.kotlin.extensions.When
15 | import org.apache.http.HttpHeaders
16 | import org.hamcrest.Matchers.equalTo
17 | import org.junit.jupiter.api.Test
18 | import org.zowe.sample.kotlin.apiservice.test.IntegrationTest
19 | import java.util.*
20 |
21 | const val GREETING_ENDPOINT = "/api/v1/greeting"
22 |
23 | class GreetingControllerIntegrationTests : IntegrationTest() {
24 |
25 | @Test
26 | fun `when greeting endpoint is called in English, Hello world is returned`() {
27 | Given {
28 | header(HttpHeaders.ACCEPT_LANGUAGE, Locale.US)
29 | } When {
30 | get(GREETING_ENDPOINT)
31 | } Then {
32 | statusCode(200)
33 | body("content", equalTo("Hello, world!"))
34 | }
35 | }
36 |
37 | @Test
38 | fun `when greeting endpoint is called in Czech, Ahoj svete is returned`() {
39 | Given {
40 | header(HttpHeaders.ACCEPT_LANGUAGE, "cs-CZ")
41 | } When {
42 | get(GREETING_ENDPOINT)
43 | } Then {
44 | statusCode(200)
45 | body("content", equalTo("Ahoj, světe!"))
46 | }
47 | }
48 |
49 | @Test
50 | fun `when greeting endpoint is called with the name parameter, Hello Jirka is returned`() {
51 | Given {
52 | header(HttpHeaders.ACCEPT_LANGUAGE, Locale.US)
53 | param("name", "Jirka")
54 | } When {
55 | get(GREETING_ENDPOINT)
56 | } Then {
57 | statusCode(200)
58 | body("content", equalTo("Hello, Jirka!"))
59 | }
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/integrationTest/kotlin/org/zowe/sample/kotlin/apiservice/test/IntegrationTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.kotlin.apiservice.test
11 |
12 | import org.junit.jupiter.api.BeforeAll
13 | import org.junit.jupiter.api.TestInstance
14 |
15 | @TestInstance(TestInstance.Lifecycle.PER_CLASS)
16 | open class IntegrationTest {
17 |
18 | private val serviceUnderTest = ServiceUnderTest()
19 |
20 | @BeforeAll
21 | fun setup() {
22 | serviceUnderTest.waitUntilIsReady()
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/main/kotlin/org/zowe/sample/kotlin/apiservice/ZoweKotlinApiServiceApplication.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.kotlin.apiservice
11 |
12 | import org.springframework.boot.autoconfigure.SpringBootApplication
13 | import org.springframework.boot.runApplication
14 |
15 | @SpringBootApplication
16 | class ZoweRestApiSampleKotlinSpringApplication
17 |
18 | fun main(args: Array) {
19 | runApplication(*args)
20 | }
21 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/main/kotlin/org/zowe/sample/kotlin/apiservice/config/ApplicationConfig.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.kotlin.apiservice.config
11 |
12 | import org.springframework.context.annotation.ComponentScan
13 | import org.springframework.context.annotation.Configuration
14 | import org.springframework.context.annotation.FilterType
15 | import org.zowe.apiml.enable.EnableApiDiscovery
16 |
17 | @Configuration
18 | @EnableApiDiscovery
19 | @ComponentScan(
20 | basePackages = ["org.zowe.commons.spring"],
21 | useDefaultFilters = false,
22 | includeFilters = [ComponentScan.Filter(type = FilterType.REGEX,
23 | pattern = [
24 | "org.zowe.commons.spring.CustomRestExceptionHandler",
25 | "org.zowe.commons.spring.WebConfig"
26 | ]
27 | )]
28 | )
29 | class ApplicationConfig {
30 | }
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/main/kotlin/org/zowe/sample/kotlin/apiservice/config/WebSecurityConfig.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.kotlin.apiservice.config
11 |
12 | import org.springframework.context.annotation.Configuration
13 | import org.springframework.security.config.annotation.web.builders.HttpSecurity
14 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
15 |
16 | @Configuration
17 | class WebSecurityConfig : WebSecurityConfigurerAdapter() {
18 |
19 | override fun configure(http: HttpSecurity) {
20 | http.authorizeRequests().anyRequest().permitAll()
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/main/kotlin/org/zowe/sample/kotlin/apiservice/greeting/Greeting.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.kotlin.apiservice.greeting
11 |
12 | import io.swagger.v3.oas.annotations.media.Schema
13 |
14 | data class Greeting(
15 |
16 | @Schema(description = "Generated sequence ID of the message")
17 | val id: Long,
18 |
19 | @Schema(description = "The greeting message")
20 | val content: String,
21 |
22 | @Schema(description = "The locale language tag used for this message")
23 | val languageTag: String
24 | )
25 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This program and the accompanying materials are made available and may be used, at your option, under either:
3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | #
6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | #
8 | # Copyright Contributors to the Zowe Project.
9 | #
10 |
11 | GreetingController.greeting=Hello
12 | GreetingController.greetingTemplate={0}, {1}\!
13 | GreetingController.world=world
14 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/main/resources/messages_cs.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This program and the accompanying materials are made available and may be used, at your option, under either:
3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | #
6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | #
8 | # Copyright Contributors to the Zowe Project.
9 | #
10 |
11 | GreetingController.greeting=Ahoj
12 | GreetingController.greetingTemplate={0}, {1}\!
13 | GreetingController.world=světe
14 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/main/resources/messages_en.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This program and the accompanying materials are made available and may be used, at your option, under either:
3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | #
6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | #
8 | # Copyright Contributors to the Zowe Project.
9 | #
10 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/src/main/resources/messages_es.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This program and the accompanying materials are made available and may be used, at your option, under either:
3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | #
6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | #
8 | # Copyright Contributors to the Zowe Project.
9 | #
10 |
11 | GreetingController.greeting=Hola
12 | GreetingController.greetingTemplate=¡{0}, {1}\!
13 | GreetingController.world=mundo
14 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-kotlin-spring/zowe-api.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Zowe Kotlin Sample REST API",
3 | "zosSourcesDir": "zossrc",
4 | "buildCommand": "make && make install",
5 | "buildFiles": {
6 | },
7 | "deployment": {
8 | "files": {
9 | "build/libs/zowe-rest-api-sample-kotlin-spring-0.0.1-SNAPSHOT.jar": {
10 | "target": "bin/zowe-rest-api-sample-kotlin-spring.jar",
11 | "postSoUpdateCommands": [
12 | ],
13 | "binary": true
14 | }
15 | }
16 | },
17 | "shellStartCommand": "$JAVA -Djava.library.path=\"./lib:${LIBPATH}\" -Xquickstart -jar bin/zowe-rest-api-sample-kotlin-spring.jar --spring.config.additional-location=file:etc/zos.yml",
18 | "jobTemplatePath": "src/main/jcl/template.jcl",
19 | "jobPath": "build/api.jcl",
20 | "defaultDirName": "zowe-rest-api-sample-kotlin-spring",
21 | "defaultHlqSegment": "ZOWE.KOTLIN.SAMPLAPI",
22 | "zfsMegabytes": 100,
23 | "configurations": {
24 | "zos": {
25 | "files": {
26 | "config/zos/zos.yml.hbs": {
27 | "target": "etc/zos.yml",
28 | "binary": true,
29 | "template": true
30 | },
31 | "config/local/keystore.p12": {
32 | "target": "etc/keystore.p12",
33 | "binary": true
34 | },
35 | "config/local/truststore.p12": {
36 | "target": "etc/truststore.p12",
37 | "binary": true
38 | }
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 4
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 | max_line_length = 120
11 |
12 | [*.md]
13 | max_line_length = off
14 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | /bin/
4 | gradle/wrapper/gradle-wrapper.jar
5 | .DS_Store
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 | /out/
22 |
23 | ### NetBeans ###
24 | /nbproject/private/
25 | /nbbuild/
26 | /dist/
27 | /nbdist/
28 | /.nb-gradle/
29 |
30 | ### VS Code ###
31 | .vscode/
32 |
33 | deploy/scripts/out
34 | deploy/templates/jcl/out
35 | deploy-config.json5
36 | node_modules
37 | *.so
38 | user-zowe-api.json
39 | lastJob.json
40 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/.licence/Apache-or-EPL-License-Header.txt:
--------------------------------------------------------------------------------
1 | This program and the accompanying materials are made available and may be used, at your option, under either:
2 | * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
3 | * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
4 |
5 | SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
6 |
7 | Copyright Contributors to the Zowe Project.
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/config/local/application.yml:
--------------------------------------------------------------------------------
1 | # Configuration for running the locally on your workstation
2 | # It overrides service defaults provided in src/main/resources/application.yml
3 |
4 | spring.profiles.active: https,diag
5 |
6 | logging:
7 | level:
8 | org.zowe.commons.zos.security: DEBUG
9 |
10 | server:
11 | address: 0.0.0.0
12 | port: 10080
13 | ssl:
14 | keyAlias: localhost
15 | keyPassword: password
16 | keyStore: config/local/keystore.p12 # Gradle
17 | # keyStore: zowe-rest-api-sample-spring/config/local/keystore.p12 # IntelliJ
18 | keyStorePassword: password
19 | keyStoreType: PKCS12
20 | trustStore: config/local/truststore.p12 # Gradle
21 | # trustStore: zowe-rest-api-sample-spring/config/local/truststore.p12 # IntelliJ
22 | trustStorePassword: password
23 | trustStoreType: PKCS12
24 |
25 | apiml:
26 | enabled: false
27 | service:
28 | serviceId: zowesample
29 | hostname: localhost
30 | ipAddress: 127.0.0.1
31 | discoveryServiceUrls:
32 | - https://localhost:10011/eureka
33 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/config/local/keystore.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/config/local/keystore.p12
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/config/local/truststore.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/config/local/truststore.p12
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/config/zos/application.yml.hbs:
--------------------------------------------------------------------------------
1 | # Configuration for running the on z/OS
2 | # It overrides service defaults provided in src/main/resources/application.yml
3 |
4 | spring.profiles.active: https,diag,zos
5 |
6 | logging:
7 | level:
8 | org.zowe.commons.zos.security: DEBUG
9 |
10 | server:
11 | address: 0.0.0.0
12 | port: {{port}}
13 | ssl:
14 | keyAlias: localhost
15 | keyPassword: password
16 | keyStore: etc/keystore.p12
17 | keyStorePassword: password
18 | keyStoreType: PKCS12
19 | trustStore: etc/truststore.p12
20 | trustStorePassword: password
21 | trustStoreType: PKCS12
22 |
23 | apiml:
24 | enabled: false
25 | service:
26 | serviceId: zowesample
27 | hostname: localhost
28 | ipAddress: 127.0.0.1
29 | discoveryServiceUrls:
30 | - https://localhost:10011/eureka
31 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/config.md:
--------------------------------------------------------------------------------
1 | # Configuration
2 |
3 | Java applications that are using Spring Boot have configuration their configuration in the [`application.yml`](/src/main/resources/application.yml) and/or `bootstrap.yml` files. These files are packaged in the JAR file so the user cannot change them.
4 |
5 | There are various ways how these values can be overridden in Spring Boot (external YML file, environment variables, Java System properties).
6 |
7 | The Java System properties are a common way how to provide external configuration options. They are defined using `-D` options for Java. Java System properties can override any configuration.
8 |
9 | The values for Java System properties can be defined in STDENV member of JZOS Batch Launcher for Java started tasks on z/OS.
10 |
11 | When your run the sample application on your computer using `gradlew bootRun` it is using external configuration file [`config/local/application.yml`](/config/local/application.yml). This file contains the value for running on your computer in development mode.
12 |
13 | ## Overriding Properties using CLI
14 |
15 | Let's say that we want to use port `10081` instead of default `10080`. This is set by property `server.port`.
16 |
17 | Running from JAR:
18 |
19 | java -Dserver.port=10081 -jar build/libs/*.jar --spring.config.additional-location=file:./config/local/application.yml
20 |
21 | Running by Gradle:
22 |
23 | ./gradlew bootRun --args='--spring.config.additional-location=file:./config/local/application.yml --server.port=10081'
24 |
25 | ## YAML Files Conventions
26 |
27 | 1. Extension is `.yml`
28 | 2. Indentation is 4 spaces
29 | 3. Property names are using `camelCase`
30 | 4. The `application.yml` bundled into the JAR should contain only valid or typical values for any deployment (ie. it should not contain values that are correct only on your computer)
31 |
32 | ## Resources
33 |
34 | - Intro to Spring YML configuration -
35 | - Full reference -
36 | - For advanced use case of sharing a common YML file -
37 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/images/greeting-api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/greeting-api.png
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/images/hello-endpoint-swaggerui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/hello-endpoint-swaggerui.png
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/images/java-started-service.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/java-started-service.png
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/images/landing-page.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/landing-page.png
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/images/sign-in.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/sign-in.png
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/images/swagger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/swagger.png
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/images/vscode-yaml-help.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/vscode-yaml-help.png
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/java-debugging.md:
--------------------------------------------------------------------------------
1 | # Java Debugging
2 |
3 | Option `-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=10081,suspend=n` will cause that the service will open a port for remote debugging. The server will start and work as usual. You can connect to the port 10081 from the remote debugger in your IDE.
4 |
5 | Example how to start the sample service with the debugging port:
6 |
7 | ```bash
8 | java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=10081,suspend=n -jar build/libs/zowe-rest-api-sample-spring-*.jar --spring.config.additional-location=file:config/local/application.yml
9 | ```
10 |
11 | ## Debugging on z/OS
12 |
13 | The `zowe-api-dev start` command can insert the right options to the Java on z/OS.
14 |
15 | You need to use option `-d` or `--debugPort` on the `start` command. For example:
16 |
17 | ```bash
18 | zowe-api-dev start --debugPort 10181
19 | ```
20 |
21 | It can be used with the `--job` option as well:
22 |
23 | ```bash
24 | zowe-api-dev start --job --debugPort 10181
25 | ```
26 |
27 | Then you can attach to the Java process on z/OS with your debugger.
28 |
29 | If you are using VS Code then you need to change the `hostName` and `port` to your z/OS host and the selected port.
30 |
31 | For example:
32 |
33 | ```json
34 | {
35 | "type": "java",
36 | "name": "Debug (Attach) - Remote",
37 | "request": "attach",
38 | "hostName": "ca32.lvn.broadcom.net",
39 | "port": 10181
40 | }
41 | ```
42 |
43 | ## Resources
44 |
45 | * [VS Code -Running and Debugging Java](https://code.visualstudio.com/docs/java/java-debugging)
46 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/logging.md:
--------------------------------------------------------------------------------
1 | # Logging
2 |
3 | The default settings of the sample application produce a clean log that contains
4 | only important informational messages from the REST API service user perspective.
5 | Warnings and errors will be displayed. But information for developers are not included by default.
6 |
7 | ## Debug Profile
8 |
9 | In order to see debugging messages that are useful for developers, a debugging profile needs to be enabled.
10 | This profile is called `debug`.
11 |
12 | You can pass it as a command line argument `--spring.profiles.include=debug` when you start the JAR. For example:
13 |
14 | java -jar build/libs/*.jar --spring.config.additional-location=file:./config/local/application.yml --spring.profiles.include=debug
15 |
16 | Or with Gradle:
17 |
18 | ./gradlew bootRun --args='--spring.config.additional-location=file:./config/local/application.yml --spring.profiles.include=debug'
19 |
20 | ## Diagnostics Profile
21 |
22 | There is a profile called `diag` that is enabled in [`config/local/application.yml`](/config/local/application.yml).
23 |
24 | This profile enables all Spring Actuator endpoints that you can see at:
25 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/versioning.md:
--------------------------------------------------------------------------------
1 | # Versioning
2 |
3 | - The version of the sample REST API service is set to `version = '0.0.1-SNAPSHOT'` in `build.gradle` file. You can change it when you develop your REST API service.
4 |
5 | - The version of the SDK commons library `org.zowe:zowe-rest-api-commons-spring` follow [semantic version](https://semver.org/) as it is specified in `build.gradle` in this line:
6 |
7 | ```return "org.zowe:zowe-rest-api-commons-spring:"```
8 |
9 | - When you download the latest sample ZIP file it will use the latest SDK commons library at that time.
10 |
11 | - If you want to use newer version in future, you need to manually update the version number. Since the current version is `0.x` there can be breaking changes at any time until `1.x` is reached but we will try to keep number of breaking changes at minimum.
12 |
13 | - For SDK developers: The published versions are controlled by Git tags. You do not need to change the versions in the code.
14 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/docs/web-security.md:
--------------------------------------------------------------------------------
1 | # Web Security
2 |
3 | ## Authentication
4 |
5 | The REST API service is protected by **HTTP Basic authentication** that is connected to `ZosAuthenticationProvider`.
6 |
7 | The REST API endpoints that require HTTP Basic authentication have declare it in the `@ApiOperation` annotation.
8 | This annotation is used only for API documentation.
9 |
10 | ```java
11 | import static org.zowe.sample.apiservice.apidoc.ApiDocConstants.DOC_SCHEME_BASIC_AUTH;
12 |
13 | @ApiOperation(..., authorizations = { @Authorization(value = DOC_SCHEME_BASIC_AUTH) })
14 | @GetMapping("/greeting")
15 | public Greeting greeting(
16 | ```
17 |
18 | The real protection by the authentication is configured in `WebSecurityConfig` class:
19 |
20 | ```java
21 | http.authorizeRequests().anyRequest().authenticated();
22 | ```
23 |
24 | ## Implementation
25 |
26 | More details are provided at [z/OS Security](zos-security.md).
27 |
28 | ## Future Direction
29 |
30 | The sample and SDK supports only the HTTP Basic authentication at this moment.
31 | HTTP Basic authentication will be always supported since it is the most easiest method supported by all clients.
32 |
33 | In order to support multi-factor authentication, the SDK and sample will support **stateless token-based authentication** in future.
34 |
35 | It will use following services:
36 |
37 | - [Zowe Authentication and Authorization Service](https://github.com/zowe/api-layer/wiki/Zowe-Authentication-and-Authorization-Service)
38 | - possibly other token-based security services such as z/OSMF
39 |
40 | It will be controlled by a configuration property (no or minimal change in Java code will be required).
41 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.caching=true
2 |
3 | # Repository URL for getting Zowe artifacts:
4 | zoweArtifactoryRepository=https://zowe.jfrog.io/zowe/libs-release
5 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/gradle/bootstrap/bootstrap-gradlew.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if not exist gradle/wrapper/gradle-wrapper.jar (
4 | echo Gradle wrapper not found. Attempting to download...
5 | powershell -Command "& {wget https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar -OutFile gradle/wrapper/gradle-wrapper.jar}"
6 | IF ERRORLEVEL 1 (
7 | echo Gradle wrapper download failed. Bootstrap failed.
8 | ) ELSE (
9 | echo Gradle wrapper download success. Bootstrap complete.
10 | )
11 | )
12 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/gradle/bootstrap/bootstrap-gradlew.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | if [ ! -f gradle/wrapper/gradle-wrapper.jar ]; then
4 | echo "Gradle wrapper not found. Attempting to download..."
5 | curl --silent --output gradle/wrapper/gradle-wrapper.jar \
6 | https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar
7 | rc=$?;
8 | if [ $rc != 0 ]; then
9 | echo "Gradle wrapper download failed. Bootstrap failed."
10 | exit 1
11 | else
12 | echo "Gradle wrapper download success. Bootstrap complete."
13 | exit 0
14 | fi
15 | else
16 | exit 0
17 | fi
18 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/lombok.config:
--------------------------------------------------------------------------------
1 | lombok.addLombokGeneratedAnnotation = true
2 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | }
5 | }
6 | rootProject.name = 'zowe-rest-api-sample-spring'
7 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/integrationTest/java/org/zowe/sample/apiservice/greeting/GreetingControllerIntegrationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.greeting;
11 |
12 | import static io.restassured.RestAssured.given;
13 | import static io.restassured.RestAssured.when;
14 | import static org.hamcrest.Matchers.containsString;
15 | import static org.hamcrest.Matchers.equalTo;
16 |
17 | import org.junit.Test;
18 | import org.springframework.http.HttpHeaders;
19 | import org.zowe.sample.apiservice.test.IntegrationTests;
20 |
21 | public class GreetingControllerIntegrationTests extends IntegrationTests {
22 | @Test
23 | public void returnsGreeting() throws Exception {
24 | when().get("/api/v1/greeting").then().statusCode(200).body("content", equalTo("Hello, world!"));
25 | }
26 |
27 | @Test
28 | public void failsWithoutAuthentication() throws Exception {
29 | given().auth().none().when().get("/api/v1/greeting").then().statusCode(401)
30 | .headers(HttpHeaders.WWW_AUTHENTICATE, containsString("Basic realm=\"Zowe Sample API Service\""));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/integrationTest/java/org/zowe/sample/apiservice/test/IntegrationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.test;
11 |
12 | import org.junit.Before;
13 |
14 | public class IntegrationTests {
15 | protected ServiceUnderTest serviceUnderTest = ServiceUnderTest.getInstance();
16 |
17 | @Before
18 | public void setup() {
19 | serviceUnderTest.waitUntilIsReady();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/integrationTest/java/org/zowe/sample/apiservice/wto/WtoControllerIntegrationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.wto;
11 |
12 | import static io.restassured.RestAssured.when;
13 | import static org.hamcrest.Matchers.equalTo;
14 | import static org.hamcrest.Matchers.isEmptyOrNullString;
15 | import static org.hamcrest.Matchers.not;
16 |
17 | import org.junit.Test;
18 | import org.zowe.sample.apiservice.test.IntegrationTests;
19 |
20 | public class WtoControllerIntegrationTests extends IntegrationTests {
21 | @Test
22 | public void returnsWtoMessage() throws Exception {
23 | when().get("/api/v1/wto").then().statusCode(200).body("content", equalTo("Hello, world!")).body("message",
24 | not(isEmptyOrNullString()));
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/AppNativeLibraries.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | import org.zowe.commons.zos.NativeLibraries;
16 |
17 | public class AppNativeLibraries implements NativeLibraries {
18 | public static final String SAMPLE_LIBRARY_NAME = "zowe-sample";
19 |
20 | @Override
21 | public List getNativeLibrariesNames() {
22 | List libraries = new ArrayList<>();
23 | libraries.add(SAMPLE_LIBRARY_NAME);
24 | return libraries;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/LibsExtractor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | import org.zowe.commons.zos.LibExtractor;
16 | import org.zowe.commons.zos.CommonsNativeLibraries;
17 |
18 | public class LibsExtractor {
19 | public static void main(String[] args) { // NOSONAR
20 | LibExtractor ex = new LibExtractor();
21 | List libraries = new ArrayList<>();
22 | libraries.addAll(new AppNativeLibraries().getNativeLibrariesNames());
23 | libraries.addAll(new CommonsNativeLibraries().getNativeLibrariesNames());
24 | if (args.length == 1) {
25 | for(String library: libraries) {
26 | ex.extractLibrary(library, args[0]);
27 | }
28 | } else {
29 | System.err.println("No arguments provided. Expected: targetDir"); // NOSONAR
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/ZoweApiServiceApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice;
11 |
12 | import org.springframework.boot.SpringApplication;
13 | import org.springframework.boot.autoconfigure.SpringBootApplication;
14 | import org.springframework.context.annotation.ComponentScan;
15 |
16 | @SpringBootApplication
17 | @ComponentScan
18 | public class ZoweApiServiceApplication {
19 |
20 | public static void main(String[] args) { // NOSONAR
21 | SpringApplication.run(ZoweApiServiceApplication.class, args);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/config/ApplicationConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.config;
11 |
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.beans.factory.annotation.Value;
14 | import org.springframework.boot.context.event.ApplicationReadyEvent;
15 | import org.springframework.context.ApplicationListener;
16 | import org.springframework.context.annotation.Bean;
17 | import org.springframework.context.annotation.ComponentScan;
18 | import org.springframework.context.annotation.Configuration;
19 | import org.zowe.commons.error.ErrorService;
20 | import org.zowe.commons.error.ErrorServiceImpl;
21 | import org.zowe.commons.spring.ServiceStartupEventHandler;
22 |
23 | @Configuration
24 | @ComponentScan("org.zowe.commons")
25 | public class ApplicationConfig implements ApplicationListener {
26 |
27 | @Value("${apiml.service.title}")
28 | private String serviceTitle;
29 |
30 | @Autowired
31 | private ServiceStartupEventHandler serviceStartupEventHandler;
32 |
33 | private final ErrorService errorService = ErrorServiceImpl.getDefault();
34 |
35 | @Bean
36 | public ErrorService errorService() {
37 | return errorService;
38 | }
39 |
40 | @Override
41 | public void onApplicationEvent(final ApplicationReadyEvent event) {
42 | serviceStartupEventHandler.onServiceStartup(serviceTitle, ServiceStartupEventHandler.DEFAULT_DELAY_FACTOR);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/greeting/EmptyNameError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.greeting;
11 |
12 | public class EmptyNameError extends RuntimeException {
13 | private static final long serialVersionUID = -5418694915255263383L;
14 | }
15 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/greeting/Greeting.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.greeting;
11 |
12 | import io.swagger.annotations.ApiModelProperty;
13 | import lombok.Data;
14 |
15 | @Data
16 | public class Greeting {
17 | @ApiModelProperty(value = "Generated sequence ID of the message")
18 | private final long id;
19 |
20 | @ApiModelProperty(value = "The greeting message")
21 | private final String content;
22 |
23 | @ApiModelProperty(value = "The locale language tag used for this message")
24 | private final String languageTag;
25 | }
26 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/greeting/GreetingControllerExceptionHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.greeting;
11 |
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.context.i18n.LocaleContextHolder;
14 | import org.springframework.core.Ordered;
15 | import org.springframework.core.annotation.Order;
16 | import org.springframework.http.HttpStatus;
17 | import org.springframework.http.MediaType;
18 | import org.springframework.http.ResponseEntity;
19 | import org.springframework.web.bind.annotation.ControllerAdvice;
20 | import org.springframework.web.bind.annotation.ExceptionHandler;
21 | import org.zowe.commons.error.ErrorService;
22 | import org.zowe.commons.rest.response.ApiMessage;
23 |
24 | /**
25 | * Creates responses for exceptional behavior of the {@link GreetingController}.
26 | */
27 | @ControllerAdvice(assignableTypes = {GreetingController.class})
28 | @Order(Ordered.HIGHEST_PRECEDENCE)
29 | public class GreetingControllerExceptionHandler {
30 | private final ErrorService errorService;
31 |
32 | @Autowired
33 | public GreetingControllerExceptionHandler(ErrorService errorService) {
34 | this.errorService = errorService;
35 | }
36 |
37 | @ExceptionHandler(EmptyNameError.class)
38 | public ResponseEntity handleEmptyName(EmptyNameError exception) {
39 | ApiMessage message = errorService.createApiMessage(LocaleContextHolder.getLocale(), "org.zowe.sample.apiservice.greeting.empty");
40 |
41 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).contentType(MediaType.APPLICATION_JSON).body(message);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/greeting/GreetingSettings.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.greeting;
11 |
12 | import io.swagger.annotations.ApiModelProperty;
13 | import lombok.Data;
14 | import lombok.NoArgsConstructor;
15 |
16 | @Data
17 | @NoArgsConstructor
18 | public class GreetingSettings {
19 | @ApiModelProperty(value = "The greeting message without the name")
20 | private String greeting;
21 | }
22 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/wto/OffZosWto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.wto;
11 |
12 | import org.springframework.context.annotation.Profile;
13 | import org.springframework.stereotype.Service;
14 |
15 | /**
16 | * off-z/OS implementation to allow the server to be run off z/OS for testing
17 | */
18 | @Profile("!zos")
19 | @Service
20 | public class OffZosWto implements Wto {
21 |
22 | public WtoResponse call(int id, String content) {
23 | int rc = 0;
24 | String message = "[Mock] Message set from JNI";
25 | return new WtoResponse(id, content, rc, message);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/wto/Wto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.wto;
11 |
12 | /**
13 | * Generic interface implemented in for z/OS and off-z/OS
14 | */
15 | public interface Wto {
16 | WtoResponse call(int id, String content);
17 | }
18 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/wto/WtoResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.wto;
11 |
12 | import lombok.Data;
13 |
14 | /**
15 | * Class to model the data returned from the /wto endpoint
16 | */
17 | @Data
18 | public class WtoResponse {
19 | private final int id;
20 | private final String content;
21 | private final int rc;
22 | private final String message;
23 | }
24 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/wto/ZosWto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.wto;
11 |
12 | import org.springframework.context.annotation.Profile;
13 | import org.springframework.stereotype.Service;
14 | import org.zowe.commons.zos.LibLoader;
15 |
16 | import static org.zowe.sample.apiservice.AppNativeLibraries.SAMPLE_LIBRARY_NAME;
17 |
18 | /**
19 | * z/OS implementation calling the native, OS-linkage service WTO via a "shared
20 | * object" loaded at server runtime.
21 | */
22 | @Profile("zos")
23 | @Service
24 | public class ZosWto implements Wto {
25 | static {
26 | new LibLoader().loadLibrary(SAMPLE_LIBRARY_NAME);
27 | }
28 |
29 | private native int wto(int id, String content);
30 |
31 | private String message; // String class variable set in JNI code
32 |
33 | public WtoResponse call(int id, String content) {
34 | int rc = wto(id, content);
35 | return new WtoResponse(id, content, rc, message);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/resources/META-INF/additional-spring-configuration-metadata.json:
--------------------------------------------------------------------------------
1 | {"properties": [
2 | {
3 | "name": "zowe.sample.authentication",
4 | "type": "java.lang.String",
5 | "description": "Text describing how to authenticate in Swagger UI"
6 | }
7 | ]}
8 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/resources/lib/README.md:
--------------------------------------------------------------------------------
1 | # `resources/lib` folder
2 |
3 | This folder is a placeholder for `.so` files that are z/OS shared object libraries.
4 |
5 | Zowe GitHub repositories cannot contain binary files so you need to build it using
6 | `zowe-api-dev zosbuild` command.
7 |
8 | This folder `resources/lib` is packaged into the JAR file. `.so` files in the JAR file
9 | can be extracted to regular files using `LibsExtractor`.
10 | These files need to be executable and program-controlled on z/OS in order to be loadable by Java.
11 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 | 0
8 |
9 |
10 |
11 |
12 |
13 | %d{yyyy-MM-dd HH:mm:ss.SSS} %clr(<ZWEASA1:%thread:${PID:- }>){magenta} %X{userid:-} %clr(\(%logger:%line\)){cyan} %clr(%level) %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This program and the accompanying materials are made available and may be used, at your option, under either:
3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | #
6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | #
8 | # Copyright Contributors to the Zowe Project.
9 | #
10 |
11 | GreetingController.greeting=Hello
12 | GreetingController.greetingTemplate=%s, %s\!
13 | GreetingController.world=world
14 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/resources/messages.yml:
--------------------------------------------------------------------------------
1 | messages:
2 | - key: org.zowe.sample.apiservice.greeting.empty
3 | number: ZWEASA001
4 | type: ERROR
5 | text: "The provided name is empty. Provide a name that is not empty."
6 | - key: org.zowe.commons.service.started
7 | number: ZWEASA101
8 | type: INFO
9 | text: "'%s' has been started in %.3f seconds"
10 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/resources/messages_cs.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This program and the accompanying materials are made available and may be used, at your option, under either:
3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | #
6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | #
8 | # Copyright Contributors to the Zowe Project.
9 | #
10 |
11 | GreetingController.greeting=Ahoj
12 | GreetingController.greetingTemplate=%s, %s\!
13 | GreetingController.world=světe
14 | messages.org.zowe.sample.apiservice.greeting.empty.text=Zadané jméno je prázdné. Zadejte jméno, které není prázdné.
15 | messages.org.zowe.commons.service.started.text='%s' se spustila za %.3f vteřin
16 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/resources/messages_es.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This program and the accompanying materials are made available and may be used, at your option, under either:
3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | #
6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | #
8 | # Copyright Contributors to the Zowe Project.
9 | #
10 |
11 | GreetingController.greeting=Hola
12 | GreetingController.greetingTemplate=¡%s, %s\!
13 | GreetingController.world=mundo
14 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/main/resources/test-saf.yml:
--------------------------------------------------------------------------------
1 | # This file is used by the MockPlatformAccessControl class for testing and when the service is running outside of z/OS
2 | # It defines what are the access levels for SAF resources and users
3 | #
4 | # There are to special values of access level:
5 | # - `FAILURE` - the check request will fail with an internal error
6 | # - `NONE` - there is no access to the resource but the resource is defined
7 | #
8 | # This file is stored in `src/main/resources/test-saf.yml` which means that it will be used by the service and its unit tests.
9 | # If you can create a different file in `src/test/resources/test-saf.yml` then unit tests will use different definitions.
10 | #
11 | safAccess:
12 | FACILITY: # class
13 | BPX.SERVER: # resource
14 | READ: # access level
15 | - ZOWE # users
16 | BPX.DAEMON:
17 | UPDATE:
18 | - ZOWE
19 | - ZOWE2
20 | JESSPOOL:
21 | ALL:
22 | READ:
23 | - ZOWE
24 | - ZOWE2
25 | ZOWE:
26 | SAMPLE.RESOURCE:
27 | UPDATE:
28 | - ZOWE
29 | - ZOWE2
30 | CONTROL:
31 | - NONE
32 | FAILING:
33 | FAILURE:
34 | - ZOWE
35 | - ZOWE2
36 | DENIED:
37 | NONE:
38 | - NONE
39 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/test/java/org/zowe/sample/apiservice/TestUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice;
11 |
12 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.EXPIRED_PASSWORD;
13 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.FAILING_PASSWORD;
14 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.INVALID_PASSWORD;
15 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.VALID_PASSWORD;
16 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.VALID_USERID;
17 |
18 | import java.util.Base64;
19 |
20 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
21 | import org.zowe.commons.zos.security.platform.MockPlatformUser;
22 |
23 | public class TestUtils {
24 | public static final String ZOWE_BASIC_AUTHENTICATION = "Basic "
25 | + Base64.getEncoder().encodeToString((VALID_USERID + ":" + VALID_PASSWORD).getBytes());
26 | public static final String ZOWE_BASIC_AUTHENTICATION_INVALID = "Basic "
27 | + Base64.getEncoder().encodeToString((VALID_USERID + ":" + INVALID_PASSWORD).getBytes());
28 | public static final String ZOWE_BASIC_AUTHENTICATION_FAILING = "Basic "
29 | + Base64.getEncoder().encodeToString((VALID_USERID + ":" + FAILING_PASSWORD).getBytes());
30 | public static final String ZOWE_BASIC_AUTHENTICATION_EXPIRED = "Basic "
31 | + Base64.getEncoder().encodeToString((VALID_USERID + ":" + EXPIRED_PASSWORD).getBytes());
32 | public static final UsernamePasswordAuthenticationToken ZOWE_AUTHENTICATION_TOKEN = new UsernamePasswordAuthenticationToken(
33 | MockPlatformUser.VALID_USERID, null);
34 | }
35 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/test/java/org/zowe/sample/apiservice/ZoweApiServiceApplicationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice;
11 |
12 | import static org.junit.Assert.assertEquals;
13 |
14 | import org.junit.Test;
15 | import org.junit.runner.RunWith;
16 | import org.springframework.boot.test.context.SpringBootTest;
17 | import org.springframework.security.web.csrf.CsrfToken;
18 | import org.springframework.security.web.csrf.DefaultCsrfToken;
19 | import org.springframework.test.context.junit4.SpringRunner;
20 | import org.zowe.commons.spring.security.CsrfController;
21 |
22 | @RunWith(SpringRunner.class)
23 | @SpringBootTest
24 | public class ZoweApiServiceApplicationTests {
25 |
26 | @Test
27 | public void csrfControllerReturnsCsrfToken() {
28 | CsrfController controller = new CsrfController();
29 | CsrfToken token = new DefaultCsrfToken("headerName", "parameterName", "token");
30 | assertEquals(token, controller.csrf(token));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/src/test/java/org/zowe/sample/apiservice/wto/WtoControllerTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | package org.zowe.sample.apiservice.wto;
11 |
12 | import static org.hamcrest.CoreMatchers.is;
13 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
16 |
17 | import org.junit.Test;
18 | import org.junit.runner.RunWith;
19 | import org.springframework.beans.factory.annotation.Autowired;
20 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
21 | import org.springframework.http.MediaType;
22 | import org.springframework.test.context.junit4.SpringRunner;
23 | import org.springframework.test.web.servlet.MockMvc;
24 | import org.zowe.sample.apiservice.TestUtils;
25 |
26 | @RunWith(SpringRunner.class)
27 | @WebMvcTest(WtoController.class)
28 | public class WtoControllerTests {
29 |
30 | @Autowired
31 | private MockMvc mvc;
32 |
33 | @Test
34 | public void returnsWtoMessage() throws Exception {
35 | mvc.perform(get("/api/v1/wto").header("Authorization", TestUtils.ZOWE_BASIC_AUTHENTICATION)
36 | .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
37 | .andExpect(jsonPath("$.content", is("Hello, world!")))
38 | .andExpect(jsonPath("$.message", is("[Mock] Message set from JNI")));
39 | }
40 |
41 | @Test
42 | public void failsWithoutAuthentication() throws Exception {
43 | mvc.perform(get("/api/v1/wto")).andExpect(status().isUnauthorized());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/zossrc/makefile:
--------------------------------------------------------------------------------
1 | # makefile boilerplate to build the JNI implementation (C++), metal C code, and
2 | # bind into a "shared object" called at REST API runtime via the /wto endpoint
3 | #
4 | # This program and the accompanying materials are made available and may be used, at your option, under either:
5 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
6 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
7 | #
8 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
9 | #
10 | # Copyright Contributors to the Zowe Project.
11 |
12 | CXX=xlc++
13 | CC=xlc
14 | ASM=as
15 |
16 | MTL_OPTS=metal,\
17 | langlvl(extended),\
18 | sscom,\
19 | nolongname,\
20 | inline,\
21 | genasm,\
22 | inlrpt,\
23 | csect,\
24 | nose,\
25 | lp64,\
26 | list,\
27 | warn64,\
28 | optimize(2),\
29 | list,\
30 | showinc,\
31 | showmacro,\
32 | source,\
33 | aggregate
34 |
35 | MTL_FLAGS=-S -W "c,$(MTL_OPTS)"
36 |
37 | MACLIBS=-ISYS1.MACLIB \
38 | -ICBC.SCCNSAM
39 |
40 | MTL_HEADERS=-I/usr/include/metal
41 |
42 | DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended),dll,xplink,exportall"\
43 | -qsearch=$(JAVA_HOME)/include \
44 | -qsource \
45 | -g \
46 | -c
47 |
48 | DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" \
49 | -g \
50 | -qsource
51 |
52 | ASM_FLAGS=-mrent
53 |
54 | SIDEDECKPATH = $(JAVA_HOME)/bin/j9vm
55 | SIDEDECK = libjvm
56 |
57 | PREFIX := "../lib/"
58 |
59 | all: libzowe-sample.so
60 |
61 | install:
62 | mkdir -p $(PREFIX)
63 | cp -vp *.so $(PREFIX)
64 | extattr +p $(PREFIX)/*.so
65 | ls -E $(PREFIX)
66 |
67 | libzowe-sample.so: wtojni.o wtoexec.o
68 | $(CXX) $(DLL_BND_FLAGS) -o $@ $^ > $*.bind.lst
69 | extattr +p $@
70 |
71 | wtojni.o: wtojni.cpp
72 | $(CXX) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^
73 |
74 | wtoexec.o: wtoexec.s
75 | $(ASM) $(ASM_FLAGS) -a=$*.asm.lst $(MACLIBS) -o $@ $^
76 |
77 | wtoexec.s: wtoexec.c
78 | $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^
79 |
80 | clean:
81 | rm *.o
82 | rm *.lst
83 | rm *.x
84 | rm *.so
85 | rm *.dbg
86 | rm wtoexec.s
87 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/zossrc/wtoexec.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This program and the accompanying materials are made available and may be used, at your option, under either:
3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5 | *
6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
7 | *
8 | * Copyright Contributors to the Zowe Project.
9 | */
10 | #include "wtoexec.h"
11 | #include "wto.h"
12 |
13 | #include
14 | #include
15 |
16 | /**
17 | * Metal C implementation running with z/OS linkage conventions and called
18 | * via JNI - C++ layer.
19 | *
20 | * Force the compiler and assembler to treat this function as a
21 | * "main" to aquire stack space. For production, create your
22 | * own or use your site's PROLOG & EPILOG.
23 | */
24 | #pragma prolog(WTOEXE, "&CCN_MAIN SETB 1 \n MYPROLOG")
25 |
26 | int WTOEXE(int *number, const char *string)
27 | {
28 | WTO_BUF buf = {0};
29 | buf.len = sprintf(buf.msg, "Number was: '%d'; String was: '%s'", *number, string);
30 | return wto(&buf);
31 | }
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/zossrc/wtoexec.h:
--------------------------------------------------------------------------------
1 | #ifndef WTOEXEC_H
2 | #define WTOEXEC_H
3 |
4 | /*
5 | * This program and the accompanying materials are made available and may be used, at your option, under either:
6 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR
7 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10 | *
11 | * Copyright Contributors to the Zowe Project.
12 | */
13 |
14 | /**
15 | * C/C++ interlanguage - "OS" meaning to call non-Language Environment conforming assembler.
16 | */
17 | #if defined(__cplusplus) && (defined(__IBMCPP__) || defined(__IBMC__))
18 | extern "OS"
19 | {
20 | #elif defined(__cplusplus)
21 | extern "C"
22 | {
23 | #endif
24 |
25 | int WTOEXE(int *, const char *);
26 |
27 | #if defined(__cplusplus)
28 | }
29 | #endif
30 |
31 | #endif
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/zossrc/wtojni.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class org_zowe_sample_apiservice_wto_ZosWto */
4 |
5 | #ifndef _Included_org_zowe_sample_apiservice_wto_ZosWto
6 | #define _Included_org_zowe_sample_apiservice_wto_ZosWto
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: org_zowe_sample_apiservice_wto_ZosWto
12 | * Method: wto
13 | * Signature: (ILjava/lang/String;)I
14 | */
15 | JNIEXPORT jint JNICALL Java_org_zowe_sample_apiservice_wto_ZosWto_wto
16 | (JNIEnv *, jobject, jint, jstring);
17 |
18 | #ifdef __cplusplus
19 | }
20 | #endif
21 | #endif
22 |
--------------------------------------------------------------------------------
/zowe-rest-api-sample-spring/zowe-api.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Zowe Sample REST API Service",
3 | "zosSourcesDir": "zossrc",
4 | "buildCommand": "make && make install",
5 | "buildFiles": {
6 | "libzowe-sample.so": "src/main/resources/lib/libzowe-sample.so"
7 | },
8 | "deployment": {
9 | "files": {
10 | "build/libs/zowe-rest-api-sample-spring-0.0.1-SNAPSHOT.jar": {
11 | "target": "bin/zowe-rest-api-sample-spring.jar",
12 | "postSoUpdateCommands": [
13 | "mkdir -p lib/ && $JAVA -cp bin/zowe-rest-api-sample-spring.jar -Dloader.main=org.zowe.sample.apiservice.LibsExtractor org.springframework.boot.loader.PropertiesLauncher lib && extattr +p lib/*.so && chmod a+x lib/*.so && ls -E lib/"
14 | ],
15 | "binary": true
16 | }
17 | }
18 | },
19 | "shellStartCommand": "$JAVA -Dorg.zowe.commons.logging.stripAccents=true -Duser.language=en -Duser.country=US -Djava.library.path=\"./lib:${LIBPATH}\" -Xquickstart -jar bin/zowe-rest-api-sample-spring.jar --spring.config.additional-location=file:etc/application.yml",
20 | "jobTemplatePath": "src/main/jcl/template.jcl",
21 | "jobPath": "build/api.jcl",
22 | "defaultDirName": "zowe-rest-api-sample-spring",
23 | "defaultHlqSegment": "ZOWE.SAMPLAPI",
24 | "zfsMegabytes": 200,
25 | "configurations": {
26 | "zos": {
27 | "files": {
28 | "config/zos/application.yml.hbs": {
29 | "target": "etc/application.yml",
30 | "binary": true,
31 | "template": true
32 | },
33 | "config/local/keystore.p12": {
34 | "target": "etc/keystore.p12",
35 | "binary": true
36 | },
37 | "config/local/truststore.p12": {
38 | "target": "etc/truststore.p12",
39 | "binary": true
40 | }
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------