Skip to content

Instantly share code, notes, and snippets.

@AlexanderWillner
Created April 28, 2015 13:48
Show Gist options
  • Save AlexanderWillner/344f6e527fb18b42f834 to your computer and use it in GitHub Desktop.
Save AlexanderWillner/344f6e527fb18b42f834 to your computer and use it in GitHub Desktop.
private void setupJfed(final GeniUrn cfgUrnUser, final String authorityURN,
final String cfgPwd, final String cfgPem) throws IOException,
JFedException {
final char[] pemPass = cfgPwd.toCharArray();
final File pemFile = new File(PerformanceTest.class.getResource(cfgPem)
.getFile());
final String pemPath = PerformanceTest.class.getResource(cfgPem)
.getPath();
this.user = new SimpleGeniUser(null, cfgUrnUser,
IOUtils.fileToString(pemPath), pemPass, pemFile, pemFile);
this.injector = Guice.createInjector(new BasicAuthoritiesModule(),
new DirectUserModule(this.user), new CoreModule(),
new CorePreferencesModule());
this.authorityListModel = this.injector
.getInstance(AuthorityListModel.class);
// if this one here doesn't work, edit the authorities.xml file
final GeniUser loggedInUser = this.injector.getInstance(GeniUser.class);
if (loggedInUser != null) {
System.out.println("You are logged in as user: "
+ loggedInUser.getUserUrn());
if (loggedInUser.getUserAuthority() != null) {
System.out.println(" on authority: "
+ loggedInUser.getUserAuthority().getUrn());
if ((loggedInUser.getUserAuthority().getUrls() == null)
|| loggedInUser.getUserAuthority().getUrls().isEmpty()) {
System.err
.println("ERROR: there are no URLs known for your user authority! (urls="
+ loggedInUser.getUserAuthority().getUrls()
+ ")");
System.exit(1);
}
if (!loggedInUser.getUserUrnString().equals(
this.user.getUserUrnString())) {
System.err
.println("WARNING: the user you are now logged in with ("
+ loggedInUser.getUserUrnString()
+ "), "
+ "does not match the user you started login with ("
+ this.user.getUserUrnString()
+ "). "
+ "(this should not happen)");
}
} else {
System.err
.println("ERROR: the authority of your user was not found!");
}
} else {
System.err.println("ERROR: null user!");
}
this.authority = this.authorityListModel.getByUrn(authorityURN,
SubAuthMatchAllowed.ALLOW_TOPLEVEL,
SubAuthMatchPreference.PREFER_TOPLEVEL);
// conPool = injector.getInstance(JFedConnectionProvider.class);
// jFedPreferences = injector.getInstance(JFedPreferences.class);
this.am = this.injector
.getInstance(
AutomaticAggregateManagerWrapper.AutomaticAggregateManagerWrapperFactory.class)
.create(this.authority);
this.sa = this.injector
.getInstance(
AutomaticUserAndSliceApiWrapper.AutomaticUserAndSliceApiWrapperFactory.class)
.create();
this.creds = this.sa.getUserCredentials(this.logger,
this.user.getUserUrn());
// for (final AnyCredential cred : this.creds) {
// System.out.println("\n\ncredential:\n"
// + cred.getCredentialXml().substring(
// 0,
// cred.getCredentialXml().length() > 300 ? 300 : cred
// .getCredentialXml().length()) + "...\n");
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment