Skip to content

Commit

Permalink
Merge pull request #80 from owncloud/username_in_saml_sso
Browse files Browse the repository at this point in the history
Added username to SAML SSO credentials
  • Loading branch information
masensio committed Aug 6, 2015
2 parents 3b9777c + 1fa8e79 commit c8f6e5a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/com/owncloud/android/lib/common/OwnCloudClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ public static OwnCloudClient createOwnCloudClient (Account account, Context appC
boolean isSamlSso =
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);

if (isOauth2) {

String username = account.name.substring(0, account.name.lastIndexOf('@'));
if (isOauth2) {
String accessToken = am.blockingGetAuthToken(
account,
AccountTypeUtils.getAuthTokenTypeAccessToken(account.type),
Expand All @@ -100,11 +101,10 @@ public static OwnCloudClient createOwnCloudClient (Account account, Context appC
false);

client.setCredentials(
OwnCloudCredentialsFactory.newSamlSsoCredentials(accessToken)
OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken)
);

} else {
String username = account.name.substring(0, account.name.lastIndexOf('@'));
//String password = am.getPassword(account);
String password = am.blockingGetAuthToken(
account,
Expand Down Expand Up @@ -136,7 +136,8 @@ public static OwnCloudClient createOwnCloudClient (Account account, Context appC
boolean isSamlSso =
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);


String username = account.name.substring(0, account.name.lastIndexOf('@'));
if (isOauth2) { // TODO avoid a call to getUserData here
AccountManagerFuture<Bundle> future = am.getAuthToken(
account,
Expand Down Expand Up @@ -166,12 +167,11 @@ public static OwnCloudClient createOwnCloudClient (Account account, Context appC
String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
if (accessToken == null) throw new AuthenticatorException("WTF!");
client.setCredentials(
OwnCloudCredentialsFactory.newSamlSsoCredentials(accessToken)
OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken)
);


} else {
String username = account.name.substring(0, account.name.lastIndexOf('@'));
//String password = am.getPassword(account);
//String password = am.blockingGetAuthToken(account, MainApp.getAuthTokenTypePass(),
// false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static OwnCloudCredentials newBearerCredentials(String authToken) {
return new OwnCloudBearerCredentials(authToken);
}

public static OwnCloudCredentials newSamlSsoCredentials(String sessionCookie) {
return new OwnCloudSamlSsoCredentials(sessionCookie);
public static OwnCloudCredentials newSamlSsoCredentials(String username, String sessionCookie) {
return new OwnCloudSamlSsoCredentials(username, sessionCookie);
}

public static final OwnCloudCredentials getAnonymousCredentials() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@

public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {

private String mUsername;
private String mSessionCookie;

public OwnCloudSamlSsoCredentials(String sessionCookie) {
public OwnCloudSamlSsoCredentials(String username, String sessionCookie) {
mUsername = username != null ? username : "";
mSessionCookie = sessionCookie != null ? sessionCookie : "";
}

Expand Down Expand Up @@ -63,8 +65,8 @@ public void applyTo(OwnCloudClient client) {

@Override
public String getUsername() {
// its unknown
return null;
// not relevant for authentication, but relevant for informational purposes
return mUsername;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public static OwnCloudCredentials getCredentialsForAccount(Context context, Acco
boolean isSamlSso = am.getUserData(
account,
AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;


String username = account.name.substring(0, account.name.lastIndexOf('@'));

if (isOauth2) {
String accessToken = am.blockingGetAuthToken(
account,
Expand All @@ -182,10 +184,9 @@ public static OwnCloudCredentials getCredentialsForAccount(Context context, Acco
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type),
false);

credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(accessToken);
credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken);

} else {
String username = account.name.substring(0, account.name.lastIndexOf('@'));
String password = am.blockingGetAuthToken(
account,
AccountTypeUtils.getAuthTokenTypePass(account.type),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void testGetSetCredentials() {
client.setCredentials(credentials);
assertEquals("Bearer credentials not set", credentials, client.getCredentials());

credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials("samlSessionCookie=124");
credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials("user", "samlSessionCookie=124");
client.setCredentials(credentials);
assertEquals("SAML2 session credentials not set", credentials, client.getCredentials());

Expand Down

0 comments on commit c8f6e5a

Please sign in to comment.