android: Migrate to the Gradle build system
[strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / data / VpnType.java
1 /*
2 * Copyright (C) 2012-2014 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 package org.strongswan.android.data;
17
18 import java.util.EnumSet;
19
20 public enum VpnType
21 {
22 /* the order here must match the items in R.array.vpn_types */
23 IKEV2_EAP("ikev2-eap", EnumSet.of(VpnTypeFeature.USER_PASS)),
24 IKEV2_CERT("ikev2-cert", EnumSet.of(VpnTypeFeature.CERTIFICATE)),
25 IKEV2_CERT_EAP("ikev2-cert-eap", EnumSet.of(VpnTypeFeature.USER_PASS, VpnTypeFeature.CERTIFICATE)),
26 IKEV2_EAP_TLS("ikev2-eap-tls", EnumSet.of(VpnTypeFeature.CERTIFICATE)),
27 IKEV2_BYOD_EAP("ikev2-byod-eap", EnumSet.of(VpnTypeFeature.USER_PASS, VpnTypeFeature.BYOD));
28
29 /**
30 * Features of a VPN type.
31 */
32 public enum VpnTypeFeature
33 {
34 /** client certificate is required */
35 CERTIFICATE,
36 /** username and password are required */
37 USER_PASS,
38 /** enable BYOD features */
39 BYOD;
40 }
41
42 private String mIdentifier;
43 private EnumSet<VpnTypeFeature> mFeatures;
44
45 /**
46 * Enum which provides additional information about the supported VPN types.
47 *
48 * @param id identifier used to store and transmit this specific type
49 * @param features of the given VPN type
50 * @param certificate true if a client certificate is required
51 */
52 VpnType(String id, EnumSet<VpnTypeFeature> features)
53 {
54 mIdentifier = id;
55 mFeatures = features;
56 }
57
58 /**
59 * The identifier used to store this value in the database
60 * @return identifier
61 */
62 public String getIdentifier()
63 {
64 return mIdentifier;
65 }
66
67 /**
68 * Checks whether a feature is supported/required by this type of VPN.
69 *
70 * @return true if the feature is supported/required
71 */
72 public boolean has(VpnTypeFeature feature)
73 {
74 return mFeatures.contains(feature);
75 }
76
77 /**
78 * Get the enum entry with the given identifier.
79 *
80 * @param identifier get the enum entry with this identifier
81 * @return the enum entry, or the default if not found
82 */
83 public static VpnType fromIdentifier(String identifier)
84 {
85 for (VpnType type : VpnType.values())
86 {
87 if (identifier.equals(type.mIdentifier))
88 {
89 return type;
90 }
91 }
92 return VpnType.IKEV2_EAP;
93 }
94 }