/*
- * Copyright (C) 2012-2013 Tobias Brunner
+ * Copyright (C) 2012-2014 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
package org.strongswan.android.data;
+import java.util.EnumSet;
+
public enum VpnType
{
/* the order here must match the items in R.array.vpn_types */
- IKEV2_EAP("ikev2-eap", true, false),
- IKEV2_CERT("ikev2-cert", false, true),
- IKEV2_CERT_EAP("ikev2-cert-eap", true, true),
- IKEV2_BYOD_EAP("ikev2-byod-eap", true, false, true);
-
- private String mIdentifier;
- private boolean mCertificate;
- private boolean mUsernamePassword;
- private boolean mBYOD;
+ IKEV2_EAP("ikev2-eap", EnumSet.of(VpnTypeFeature.USER_PASS)),
+ IKEV2_CERT("ikev2-cert", EnumSet.of(VpnTypeFeature.CERTIFICATE)),
+ IKEV2_CERT_EAP("ikev2-cert-eap", EnumSet.of(VpnTypeFeature.USER_PASS, VpnTypeFeature.CERTIFICATE)),
+ IKEV2_BYOD_EAP("ikev2-byod-eap", EnumSet.of(VpnTypeFeature.USER_PASS, VpnTypeFeature.CERTIFICATE, VpnTypeFeature.BYOD));
/**
- * Enum which provides additional information about the supported VPN types.
- *
- * @param id identifier used to store and transmit this specific type
- * @param userpass true if username and password are required
- * @param certificate true if a client certificate is required
+ * Features of a VPN type.
*/
- VpnType(String id, boolean userpass, boolean certificate)
+ public enum VpnTypeFeature
{
- this(id, userpass, certificate, false);
+ /** client certificate is required */
+ CERTIFICATE,
+ /** username and password are required */
+ USER_PASS,
+ /** enable BYOD features */
+ BYOD;
}
+ private String mIdentifier;
+ private EnumSet<VpnTypeFeature> mFeatures;
+
/**
* Enum which provides additional information about the supported VPN types.
*
* @param id identifier used to store and transmit this specific type
- * @param userpass true if username and password are required
+ * @param features of the given VPN type
* @param certificate true if a client certificate is required
- * @param byod true to enable BYOD features
*/
- VpnType(String id, boolean userpass, boolean certificate, boolean byod)
+ VpnType(String id, EnumSet<VpnTypeFeature> features)
{
mIdentifier = id;
- mUsernamePassword = userpass;
- mCertificate = certificate;
- mBYOD = byod;
+ mFeatures = features;
}
/**
}
/**
- * Whether username and password are required for this type of VPN.
- *
- * @return true if username and password are required
- */
- public boolean getRequiresUsernamePassword()
- {
- return mUsernamePassword;
- }
-
- /**
- * Whether a certificate is required for this type of VPN.
- *
- * @return true if a certificate is required
- */
- public boolean getRequiresCertificate()
- {
- return mCertificate;
- }
-
- /**
- * Whether BYOD features should be enabled.
+ * Checks whether a feature is supported/required by this type of VPN.
*
- * @return true if BYOD features are to be enabled
+ * @return true if the feature is supported/required
*/
- public boolean getEnableBYOD()
+ public boolean has(VpnTypeFeature feature)
{
- return mBYOD;
+ return mFeatures.contains(feature);
}
/**
import org.strongswan.android.data.VpnProfile;
import org.strongswan.android.data.VpnProfileDataSource;
+import org.strongswan.android.data.VpnType.VpnTypeFeature;
import org.strongswan.android.logic.VpnStateService.ErrorState;
import org.strongswan.android.logic.VpnStateService.State;
import org.strongswan.android.logic.imc.ImcState;
mIsDisconnecting = false;
BuilderAdapter builder = new BuilderAdapter(mCurrentProfile.getName());
- if (initializeCharon(builder, mLogFile, mCurrentProfile.getVpnType().getEnableBYOD()))
+ if (initializeCharon(builder, mLogFile, mCurrentProfile.getVpnType().has(VpnTypeFeature.BYOD)))
{
Log.i(TAG, "charon started");
initiate(mCurrentProfile.getVpnType().getIdentifier(),
import org.strongswan.android.R;
import org.strongswan.android.data.VpnProfile;
import org.strongswan.android.data.VpnProfileDataSource;
+import org.strongswan.android.data.VpnType.VpnTypeFeature;
import org.strongswan.android.logic.CharonVpnService;
import org.strongswan.android.logic.TrustedCertificateManager;
import org.strongswan.android.logic.VpnStateService;
profileInfo.putLong(VpnProfileDataSource.KEY_ID, profile.getId());
profileInfo.putString(VpnProfileDataSource.KEY_USERNAME, profile.getUsername());
profileInfo.putString(VpnProfileDataSource.KEY_PASSWORD, profile.getPassword());
- profileInfo.putBoolean(PROFILE_REQUIRES_PASSWORD, profile.getVpnType().getRequiresUsernamePassword());
+ profileInfo.putBoolean(PROFILE_REQUIRES_PASSWORD, profile.getVpnType().has(VpnTypeFeature.USER_PASS));
profileInfo.putString(PROFILE_NAME, profile.getName());
removeFragmentByTag(DIALOG_TAG);
import org.strongswan.android.data.VpnProfile;
import org.strongswan.android.data.VpnProfileDataSource;
import org.strongswan.android.data.VpnType;
+import org.strongswan.android.data.VpnType.VpnTypeFeature;
import org.strongswan.android.logic.TrustedCertificateManager;
import org.strongswan.android.security.TrustedCertificateEntry;
*/
private void updateCredentialView()
{
- mUsernamePassword.setVisibility(mVpnType.getRequiresUsernamePassword() ? View.VISIBLE : View.GONE);
- mUserCertificate.setVisibility(mVpnType.getRequiresCertificate() ? View.VISIBLE : View.GONE);
- mTncNotice.setVisibility(mVpnType.getEnableBYOD() ? View.VISIBLE : View.GONE);
+ mUsernamePassword.setVisibility(mVpnType.has(VpnTypeFeature.USER_PASS) ? View.VISIBLE : View.GONE);
+ mUserCertificate.setVisibility(mVpnType.has(VpnTypeFeature.CERTIFICATE) ? View.VISIBLE : View.GONE);
+ mTncNotice.setVisibility(mVpnType.has(VpnTypeFeature.BYOD) ? View.VISIBLE : View.GONE);
- if (mVpnType.getRequiresCertificate())
+ if (mVpnType.has(VpnTypeFeature.CERTIFICATE))
{
if (mUserCertLoading != null)
{
mGateway.setError(getString(R.string.alert_text_no_input_gateway));
valid = false;
}
- if (mVpnType.getRequiresUsernamePassword())
+ if (mVpnType.has(VpnTypeFeature.USER_PASS))
{
if (mUsername.getText().toString().trim().isEmpty())
{
valid = false;
}
}
- if (mVpnType.getRequiresCertificate() && mUserCertEntry == null)
+ if (mVpnType.has(VpnTypeFeature.CERTIFICATE) && mUserCertEntry == null)
{ /* let's show an error icon */
((TextView)mSelectUserCert.findViewById(android.R.id.text1)).setError("");
valid = false;
mProfile.setName(name.isEmpty() ? gateway : name);
mProfile.setGateway(gateway);
mProfile.setVpnType(mVpnType);
- if (mVpnType.getRequiresUsernamePassword())
+ if (mVpnType.has(VpnTypeFeature.USER_PASS))
{
mProfile.setUsername(mUsername.getText().toString().trim());
String password = mPassword.getText().toString().trim();
password = password.isEmpty() ? null : password;
mProfile.setPassword(password);
}
- if (mVpnType.getRequiresCertificate())
+ if (mVpnType.has(VpnTypeFeature.CERTIFICATE))
{
mProfile.setUserCertificateAlias(mUserCertEntry.getAlias());
}
import org.strongswan.android.R;
import org.strongswan.android.data.VpnProfile;
+import org.strongswan.android.data.VpnType.VpnTypeFeature;
import android.content.Context;
import android.view.LayoutInflater;
tv = (TextView)vpnProfileView.findViewById(R.id.profile_item_gateway);
tv.setText(getContext().getString(R.string.profile_gateway_label) + " " + profile.getGateway());
tv = (TextView)vpnProfileView.findViewById(R.id.profile_item_username);
- if (profile.getVpnType().getRequiresUsernamePassword())
+ if (profile.getVpnType().has(VpnTypeFeature.USER_PASS))
{ /* if the view is reused we make sure it is visible */
tv.setVisibility(View.VISIBLE);
tv.setText(getContext().getString(R.string.profile_username_label) + " " + profile.getUsername());
tv.setVisibility(View.GONE);
}
tv = (TextView)vpnProfileView.findViewById(R.id.profile_item_certificate);
- if (profile.getVpnType().getRequiresCertificate())
+ if (profile.getVpnType().has(VpnTypeFeature.CERTIFICATE))
{
tv.setText(getContext().getString(R.string.profile_user_certificate_label) + " " + profile.getUserCertificateAlias());
tv.setVisibility(View.VISIBLE);