Skip to content

Commit

Permalink
Minimal changes required for Crowd 1.3.2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fisheye committed Apr 22, 2008
1 parent bbd9a74 commit dc60769
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -7,15 +7,15 @@
<artifactId>mysql-connector</artifactId>
<packaging>jar</packaging>
<name>Crowd MySQL Connector</name>
<version>1.0-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
<properties>
<myVersion>1.0-SNAPSHOT</myVersion>
</properties>
<dependencies>
<dependency>
<groupId>com.atlassian.crowd</groupId>
<artifactId>crowd-core</artifactId>
<version>1.1.0</version>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
Expand Down
87 changes: 52 additions & 35 deletions src/java/com/chariotsolutions/crowd/connector/MySQLConnector.java
Expand Up @@ -80,13 +80,13 @@ public String getDirectoryType() {
return "IONA Database";
}

public Map getAttributes() {
return new HashMap();
public Map<String, AttributeValues> getAttributes() {
return new HashMap<String, AttributeValues>();
}

public void setAttributes(Map map) {
public void setAttributes(Map<String, AttributeValues> map) {
if(map.size() > 0) {
log.debug("Setting directory attributes to "+map);
log.debug("Setting directory attributes to " + map);
}
}

Expand All @@ -106,7 +106,7 @@ public RemotePrincipal addPrincipal(RemotePrincipal principal) throws InvalidPri

String password = null;
if(principal.getCredentials().size() > 0) {
password = ((PasswordCredential) principal.getCredentials().get(0)).getCredential();
password = (principal.getCredentials().get(0)).getCredential();
}

// Handle Attributes
Expand All @@ -122,19 +122,19 @@ public RemotePrincipal addPrincipal(RemotePrincipal principal) throws InvalidPri
Map.Entry entry = (Map.Entry) o;
String key = (String) entry.getKey();
if(key.equals(RemotePrincipal.FIRSTNAME)) {
firstName = (String)((AttributeValues) entry.getValue()).getValues().get(0);
firstName = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(RemotePrincipal.EMAIL)) {
email = (String)((AttributeValues) entry.getValue()).getValues().get(0);
email = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(RemotePrincipal.LASTNAME)) {
lastName = (String)((AttributeValues) entry.getValue()).getValues().get(0);
lastName = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(ATTRIBUTE_COUNTRY)) {
country = (String)((AttributeValues) entry.getValue()).getValues().get(0);
country = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(ATTRIBUTE_TITLE)) {
title = (String)((AttributeValues) entry.getValue()).getValues().get(0);
title = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(ATTRIBUTE_PHONE)) {
phoneNumber = (String)((AttributeValues) entry.getValue()).getValues().get(0);
phoneNumber = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(ATTRIBUTE_COMPANY)) {
company = (String)((AttributeValues) entry.getValue()).getValues().get(0);
company = ((AttributeValues) entry.getValue()).getValues().get(0);
} else {
log.warn("Unrecognized attribute when creating principal: "+key+"="+entry.getValue());
}
Expand Down Expand Up @@ -494,7 +494,7 @@ public void testConnection() throws RemoteException {
}
}

public List findGroupMemberships(String username) throws RemoteException, ObjectNotFoundException {
public List<RemoteGroup> findGroupMemberships(String username) throws RemoteException, ObjectNotFoundException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
Expand All @@ -510,13 +510,21 @@ public List findGroupMemberships(String username) throws RemoteException, Object
rs.close(); rs = null;
ps.close();

ps = con.prepareStatement("SELECT g.group_name FROM user_groups ug, group_table g " +
"WHERE ug.user_id=? AND g.id = ug.group_id");
ps = con.prepareStatement("SELECT g.id, g.group_name, g.created, g.description, g.disabled " +
" FROM user_groups ug, group_table g " +
" WHERE ug.user_id=? AND g.id = ug.group_id");
ps.setLong(1, userId);
rs = ps.executeQuery();
List<String> list = new ArrayList<String>();
List<RemoteGroup> list = new ArrayList<RemoteGroup>();
while(rs.next()) {
list.add(rs.getString(1));
RemoteGroup result = new RemoteGroup();
result.setID(rs.getLong(1));
result.setName(rs.getString(2));
result.setConception(rs.getDate(3));
result.setDirectoryID(this.id);
result.setDescription(rs.getString(4));
result.setActive(rs.getInt(5) == 0);
list.add(result);
}
return list;
} catch (SQLException e) {
Expand All @@ -526,7 +534,7 @@ public List findGroupMemberships(String username) throws RemoteException, Object
}
}

public List searchGroups(SearchContext searchContext) throws RemoteException {
public List<RemoteGroup> searchGroups(SearchContext searchContext) throws RemoteException {
log.debug("Group Search "+searchContext);

String sql = "SELECT id, group_name, created, description, disabled FROM group_table";
Expand All @@ -545,7 +553,7 @@ public List searchGroups(SearchContext searchContext) throws RemoteException {
} else if (entry.getKey().equals("group.directory.id")) {
long value = (Long) entry.getValue();
if (value != this.id) {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
} else if (entry.getKey().equals("group.name")) {
where += "AND group_name=? ";
Expand Down Expand Up @@ -615,7 +623,7 @@ public List searchGroups(SearchContext searchContext) throws RemoteException {
}
}

public List searchPrincipals(SearchContext searchContext) throws RemoteException {
public List<RemotePrincipal> searchPrincipals(SearchContext searchContext) throws RemoteException {
log.debug("Principal Search "+searchContext);
String sql = USER_SELECT;
String where = "";
Expand All @@ -630,7 +638,7 @@ public List searchPrincipals(SearchContext searchContext) throws RemoteException
} else if (entry.getKey().equals("principal.directory.id")) {
long value = (Long) entry.getValue();
if (value != this.id) {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
} else if (entry.getKey().equals("principal.name")) {
where += "AND user_name=? ";
Expand Down Expand Up @@ -705,6 +713,17 @@ public RemoteGroup updateGroup(RemoteGroup group) throws RemoteException, Object
}
}

public List<RemotePrincipal> findAllGroupMembers(String groupName) throws RemoteException {
// unsupported operation
// TODO implement this it will make other code a lot more efficient
return Collections.emptyList();
}

public List<RemotePrincipal> findAllRoleMembers(String roleName) throws RemoteException {
// unsupported operation
return Collections.emptyList();
}

public RemotePrincipal updatePrincipal(RemotePrincipal principal) throws RemoteException, ObjectNotFoundException {
Connection con = null;
PreparedStatement ps = null;
Expand All @@ -715,7 +734,7 @@ public RemotePrincipal updatePrincipal(RemotePrincipal principal) throws RemoteE

String password = null;
if(principal.getCredentials().size() > 0) {
password = ((PasswordCredential) principal.getCredentials().get(0)).getCredential();
password = principal.getCredentials().get(0).getCredential();
}

// Handle Attributes
Expand All @@ -731,19 +750,19 @@ public RemotePrincipal updatePrincipal(RemotePrincipal principal) throws RemoteE
Map.Entry entry = (Map.Entry) o;
String key = (String) entry.getKey();
if(key.equals(RemotePrincipal.FIRSTNAME)) {
firstName = (String)((AttributeValues) entry.getValue()).getValues().get(0);
firstName = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(RemotePrincipal.EMAIL)) {
email = (String)((AttributeValues) entry.getValue()).getValues().get(0);
email = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(RemotePrincipal.LASTNAME)) {
lastName = (String)((AttributeValues) entry.getValue()).getValues().get(0);
lastName = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(ATTRIBUTE_COUNTRY)) {
country = (String)((AttributeValues) entry.getValue()).getValues().get(0);
country = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(ATTRIBUTE_TITLE)) {
title = (String)((AttributeValues) entry.getValue()).getValues().get(0);
title = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(ATTRIBUTE_PHONE)) {
phoneNumber = (String)((AttributeValues) entry.getValue()).getValues().get(0);
phoneNumber = ((AttributeValues) entry.getValue()).getValues().get(0);
} else if(key.equals(ATTRIBUTE_COMPANY)) {
company = (String)((AttributeValues) entry.getValue()).getValues().get(0);
company = ((AttributeValues) entry.getValue()).getValues().get(0);
} else {
log.warn("Unrecognized attribute when updating principal: "+key+"="+entry.getValue());
}
Expand Down Expand Up @@ -773,8 +792,8 @@ public RemotePrincipal updatePrincipal(RemotePrincipal principal) throws RemoteE
}
}

public List searchRoles(SearchContext searchContext) throws RemoteException {
return Collections.EMPTY_LIST;
public List<RemoteRole> searchRoles(SearchContext searchContext) throws RemoteException {
return Collections.emptyList();
}

public RemoteRole findRoleByName(String string) throws RemoteException, ObjectNotFoundException {
Expand Down Expand Up @@ -805,12 +824,10 @@ public boolean isRoleMember(String role, String principal) throws RemoteExceptio
return false;
}

public List findRoleMemberships(String username) throws RemoteException, ObjectNotFoundException {
return Collections.EMPTY_LIST;
public List<RemoteRole> findRoleMemberships(String username) throws RemoteException, ObjectNotFoundException {
return Collections.emptyList();
}



private RemotePrincipal readPrincipal(String username, ResultSet rs, PasswordCredential pwd) throws SQLException {
long id = rs.getLong(USER_ID_FIELD);
if(username == null) username = rs.getString(USER_NAME_FIELD);
Expand Down

0 comments on commit dc60769

Please sign in to comment.