|
|
| Line 1: | |||
| + | This is a report of all the roles a given user has in the system. This report has to be used in conjunction with a report template such as the [[HTML Template]]. | ||
| + | ---- | ||
| + | ''Meta-Data Script:'' | ||
| + | <pre>import com.urbancode.anthill3.domain.project.*; | ||
| + | import com.urbancode.anthill3.domain.reporting.*; | ||
| + | import com.urbancode.anthill3.domain.authentication.*; | ||
| + | ReportMetaData rmd = new ReportMetaData(); | ||
| + | TextParamMetaData userNameParam = new TextParamMetaData(); | ||
| + | userNameParam.setName("username"); | ||
| + | userNameParam.setLabel("Username"); | ||
| + | userNameParam.setDescription("The username to report on."); | ||
| + | userNameParam.setRequired(true); | ||
| + | rmd.addParameter(userNameParam); | ||
| + | AuthenticationRealm[] realms = AuthenticationRealmFactory.getInstance().restoreAllActive(); | ||
| + | String[] labels = new String[realms.length]; | ||
| + | String[] values = new String[realms.length]; | ||
| + | for (int i = 0; i < realms.length; i++) { | ||
| + | labels[i] = realms[i].getName(); | ||
| + | values[i] = realms[i].getName(); | ||
| + | } | ||
| + | SelectParamMetaData params = new SelectParamMetaData(); | ||
| + | params.setLabels(labels); | ||
| + | params.setValues(values); | ||
| + | params.setName("realmName"); | ||
| + | params.setLabel("Authentication Realm"); | ||
| + | params.setDescription("The User Authentication Realm"); | ||
| + | params.setRequired(true); | ||
| + | rmd.addParameter(params); | ||
| + | // Configure columns | ||
| + | rmd.addColumn("RoleName"); | ||
| + | return rmd; | ||
| + | </pre> | ||
| + | ---- | ||
| + | ''Report Script:'' | ||
| + | <pre>import com.urbancode.anthill3.domain.security.*; | ||
| + | import com.urbancode.anthill3.domain.authentication.*; | ||
| + | import com.urbancode.anthill3.domain.reporting.*; | ||
| + | import java.util.*; | ||
| + | // The output of a report is based on the meta-data | ||
| + | ReportOutput output = new ReportOutput(metaData); | ||
| + | AuthenticationRealm realm = AuthenticationRealmFactory.getInstance().restore(realmName); | ||
| + | User user = UserFactory.getInstance().restoreForNameAndRealm(username, realm); | ||
| + | Role[] roles = user.getRoles(); | ||
| + | for (int i = 0; i < roles.length; i++) { | ||
| + | Role role = roles[i]; | ||
| + | ReportRow row = new ReportRow(output, "Row"); | ||
| + | row.setColumnValue("RoleName", role.getName()); | ||
| + | output.addRow(row); | ||
| + | } | ||
| + | return output; | ||
| + | </pre> | ||
| + | ---- | ||
| + | '''Related Content''' | ||
| + | [[AnthillPro Template Reports]]<br/> | ||
| + | [[Report Templates]] | ||