mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Merge pull request #80 from owncloud/username_in_saml_sso
Added username to SAML SSO credentials
This commit is contained in:
commit
c8f6e5ad57
@ -82,8 +82,9 @@ public class OwnCloudClientFactory {
|
|||||||
boolean isSamlSso =
|
boolean isSamlSso =
|
||||||
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||||
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
||||||
|
|
||||||
if (isOauth2) {
|
String username = account.name.substring(0, account.name.lastIndexOf('@'));
|
||||||
|
if (isOauth2) {
|
||||||
String accessToken = am.blockingGetAuthToken(
|
String accessToken = am.blockingGetAuthToken(
|
||||||
account,
|
account,
|
||||||
AccountTypeUtils.getAuthTokenTypeAccessToken(account.type),
|
AccountTypeUtils.getAuthTokenTypeAccessToken(account.type),
|
||||||
@ -100,11 +101,10 @@ public class OwnCloudClientFactory {
|
|||||||
false);
|
false);
|
||||||
|
|
||||||
client.setCredentials(
|
client.setCredentials(
|
||||||
OwnCloudCredentialsFactory.newSamlSsoCredentials(accessToken)
|
OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken)
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String username = account.name.substring(0, account.name.lastIndexOf('@'));
|
|
||||||
//String password = am.getPassword(account);
|
//String password = am.getPassword(account);
|
||||||
String password = am.blockingGetAuthToken(
|
String password = am.blockingGetAuthToken(
|
||||||
account,
|
account,
|
||||||
@ -136,7 +136,8 @@ public class OwnCloudClientFactory {
|
|||||||
boolean isSamlSso =
|
boolean isSamlSso =
|
||||||
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||||
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
||||||
|
|
||||||
|
String username = account.name.substring(0, account.name.lastIndexOf('@'));
|
||||||
if (isOauth2) { // TODO avoid a call to getUserData here
|
if (isOauth2) { // TODO avoid a call to getUserData here
|
||||||
AccountManagerFuture<Bundle> future = am.getAuthToken(
|
AccountManagerFuture<Bundle> future = am.getAuthToken(
|
||||||
account,
|
account,
|
||||||
@ -166,12 +167,11 @@ public class OwnCloudClientFactory {
|
|||||||
String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
|
String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
|
||||||
if (accessToken == null) throw new AuthenticatorException("WTF!");
|
if (accessToken == null) throw new AuthenticatorException("WTF!");
|
||||||
client.setCredentials(
|
client.setCredentials(
|
||||||
OwnCloudCredentialsFactory.newSamlSsoCredentials(accessToken)
|
OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String username = account.name.substring(0, account.name.lastIndexOf('@'));
|
|
||||||
//String password = am.getPassword(account);
|
//String password = am.getPassword(account);
|
||||||
//String password = am.blockingGetAuthToken(account, MainApp.getAuthTokenTypePass(),
|
//String password = am.blockingGetAuthToken(account, MainApp.getAuthTokenTypePass(),
|
||||||
// false);
|
// false);
|
||||||
|
@ -36,8 +36,8 @@ public class OwnCloudCredentialsFactory {
|
|||||||
return new OwnCloudBearerCredentials(authToken);
|
return new OwnCloudBearerCredentials(authToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OwnCloudCredentials newSamlSsoCredentials(String sessionCookie) {
|
public static OwnCloudCredentials newSamlSsoCredentials(String username, String sessionCookie) {
|
||||||
return new OwnCloudSamlSsoCredentials(sessionCookie);
|
return new OwnCloudSamlSsoCredentials(username, sessionCookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final OwnCloudCredentials getAnonymousCredentials() {
|
public static final OwnCloudCredentials getAnonymousCredentials() {
|
||||||
|
@ -30,9 +30,11 @@ import android.net.Uri;
|
|||||||
|
|
||||||
public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {
|
public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {
|
||||||
|
|
||||||
|
private String mUsername;
|
||||||
private String mSessionCookie;
|
private String mSessionCookie;
|
||||||
|
|
||||||
public OwnCloudSamlSsoCredentials(String sessionCookie) {
|
public OwnCloudSamlSsoCredentials(String username, String sessionCookie) {
|
||||||
|
mUsername = username != null ? username : "";
|
||||||
mSessionCookie = sessionCookie != null ? sessionCookie : "";
|
mSessionCookie = sessionCookie != null ? sessionCookie : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +65,8 @@ public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
// its unknown
|
// not relevant for authentication, but relevant for informational purposes
|
||||||
return null;
|
return mUsername;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -167,7 +167,9 @@ public class AccountUtils {
|
|||||||
boolean isSamlSso = am.getUserData(
|
boolean isSamlSso = am.getUserData(
|
||||||
account,
|
account,
|
||||||
AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||||
|
|
||||||
|
String username = account.name.substring(0, account.name.lastIndexOf('@'));
|
||||||
|
|
||||||
if (isOauth2) {
|
if (isOauth2) {
|
||||||
String accessToken = am.blockingGetAuthToken(
|
String accessToken = am.blockingGetAuthToken(
|
||||||
account,
|
account,
|
||||||
@ -182,10 +184,9 @@ public class AccountUtils {
|
|||||||
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type),
|
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type),
|
||||||
false);
|
false);
|
||||||
|
|
||||||
credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(accessToken);
|
credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String username = account.name.substring(0, account.name.lastIndexOf('@'));
|
|
||||||
String password = am.blockingGetAuthToken(
|
String password = am.blockingGetAuthToken(
|
||||||
account,
|
account,
|
||||||
AccountTypeUtils.getAuthTokenTypePass(account.type),
|
AccountTypeUtils.getAuthTokenTypePass(account.type),
|
||||||
|
@ -135,7 +135,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
|||||||
client.setCredentials(credentials);
|
client.setCredentials(credentials);
|
||||||
assertEquals("Bearer credentials not set", credentials, client.getCredentials());
|
assertEquals("Bearer credentials not set", credentials, client.getCredentials());
|
||||||
|
|
||||||
credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials("samlSessionCookie=124");
|
credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials("user", "samlSessionCookie=124");
|
||||||
client.setCredentials(credentials);
|
client.setCredentials(credentials);
|
||||||
assertEquals("SAML2 session credentials not set", credentials, client.getCredentials());
|
assertEquals("SAML2 session credentials not set", credentials, client.getCredentials());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user