Is it possible to access WebSphere variables using java AdminClient without AdminOperations? - java

I am writing a tool that will validate WebSphere settings of a web application. I want to be able to look up all possible values of a WebSphere variable (all scopes) by remotely connecting to the server through the java AdminClient object. I have already read another post about this and although I think I now have the correct code I am not able to use the AdminOperations MBean because the WebSphere account I have to use is not granted admin privileges. I would like to know if there is a way to resolve WebSphere variables without using AdminOperations. Thanks!
Here is my code so far (again, does not work due to privilege issues):
private static String expandVariable(AdminClient client, String s)
throws Exception
{
Set result = client.queryNames(new ObjectName("*:*,type=AdminOperations,process=exampleProcess"), null);
return (String)client.invoke((javax.management.ObjectName)
result.iterator().next(),"expandVariable",new Object[]
{"${"+s+"}"}, new String[] {"java.lang.String"});
}

A User with Monitor role can use ConfigService's queryConfigObjects API and other configservice APIs to access the variables from configuration(not runtime).
Infocenter link :
http://pic.dhe.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=%2Fcom.ibm.websphere.javadoc.doc%2Fweb%2Fapidocs%2Fcom%2Fibm%2Fwebsphere%2Fmanagement%2Fconfigservice%2Fpackage-summary.html&resultof=%22ConfigServiceProxy%22%20%22configserviceproxi%22%20
Sample snippet as below:
//name of variable that needs to be expanded
String varName ="DERBY_JDBC_DRIVER_PATH";
//create a configservice proxy
configService = new ConfigServiceProxy(adminClient);
//create a session
Session session = new Session();
//ObjectName for the variables.xml
ObjectName varMapObjName = ConfigServiceHelper.createObjectName(null, "VariableMap", null);
//query all variables.xml under cell.scope is null
ObjectName[] variableMaps = configService.queryConfigObjects(session, null, varMapObjName, null);
for (int i = 0; i < variableMaps.length; i++) {
ObjectName varMap = (ObjectName) variableMaps[i];
//retrieve each variable entry
AttributeList varEntries = configService.getAttributes(session, varMap, new String[]{"entries"}, false);
List entryList = (List) ConfigServiceHelper.getAttributeValue(varEntries, "entries");
//Iterate through each entry and get the value for the specified variable(symbolicName) name.
for (int j = 0; j < entryList.size(); j++) {
ObjectName varObj = (ObjectName)entryList.get(j);
String symbolicName= (String)configService.getAttribute(session, varObj, "symbolicName");
String value = null;
if (symbolicName.equals(varName)){
value= (String)configService.getAttribute(session, varObj, "value");
System.out.println(symbolicName+"="+value);
}
}
}

Related

zoom sdk for android: can't join as a host

i already inputted all the necessary parameters for it to work according to the docs and the forums but it just can't seem to work on me
private void joinMeeting(Context context, String meetingNumber,String zak, String userName, String usID){
int ret = -1;
MeetingService meetingService = ZoomSDK.getInstance().getMeetingService();
JoinMeetingOptions options = new JoinMeetingOptions();
//JoinMeetingParams params = new JoinMeetingParams();
//params.displayName=userName;
//params.meetingNo =meetingNumber;
//params.password=meetingPassword;
//meetingService.joinMeetingWithParams(context,params,options);
StartMeetingParamsWithoutLogin params = new StartMeetingParamsWithoutLogin();
params.userId = usID; // Based on this id we are able to start the meeting as host
params.userType = MeetingService.USER_TYPE_API_USER;
params.displayName = userName;
params.zoomAccessToken = zak; //getting the zoom access token from start_url
params.meetingNo = meetingNumber; // meetingNo, getting this from create meeting api response
ret = meetingService.startMeetingWithParams(context,params,options);
Log.e("Start Meeting As Host", "===startMeetingWithNumber====ret=" + ret);
}
i tried all generating more meeting using my web sdk but it wont work either

Using dnsjava to query using java?

I am trying to query using the google public dns server (8.8.8.8) to get the IP address of some known URL. However, it seems like I am not able to get that using the following code? I am using the dnsjava java library. This is my current code
The results
Lookup lookup = new Lookup("stackoverflow.com", Type.NS);
SimpleResolver resolver=new SimpleResolver("8.8.8.8");
lookup.setDefaultResolver(resolver);
lookup.setResolver(resolver);
Record [] records = lookup.run();
for (int i = 0; i < records.length; i++) {
Record r = (Record ) records[i];
System.out.println(r.getName()+","+r.getAdditionalName());
}
}
catch ( Exception ex) {
ex.printStackTrace();
logger.error(ex.getMessage(),ex);
}
Results:
stackoverflow.com.,ns-1033.awsdns-01.org.
stackoverflow.com.,ns-cloud-e1.googledomains.com.
stackoverflow.com.,ns-cloud-e2.googledomains.com.
stackoverflow.com.,ns-358.awsdns-44.com.
You don’t need a DNS library just to look up an IP address. You can simply use JNDI:
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.dns.DnsContextFactory");
env.setProperty(Context.PROVIDER_URL, "dns://8.8.8.8");
DirContext context = new InitialDirContext(env);
Attributes list = context.getAttributes("stackoverflow.com",
new String[] { "A" });
NamingEnumeration<? extends Attribute> records = list.getAll();
while (records.hasMore()) {
Attribute record = records.next();
String name = record.get().toString();
System.out.println(name);
}
If you insist on using the dnsjava library, you need to use Type.A (as your code was originally doing, before your edit).
Looking at the documentation for the Record class, notice the long list under Direct Known Subclasses. You need to cast each Record to the appropriate subclass, which in this case is ARecord.
Once you’ve done that cast, you have an additional method available, getAddress:
for (int i = 0; i < records.length; i++) {
ARecord r = (ARecord) records[i];
System.out.println(r.getName() + "," + r.getAdditionalName()
+ " => " + r.getAddress());
}

JAVA LDAP : How do I obtain the Dn?

I did an LDAP Directory Search and received some results. I need to iterate over these results and display the Dn for each entry.
In my test environment I returned the Dn value by obtaining the value of the entryDN attribute.
In the production environment the entryDN attribute always returns null.
In both environments when I return the value of the Dn attribute all I get is null.
What I really need to do is reliably obtain the Dn from any environment.
Suggestions?
To reliably get the Dn use the method SearchResult.getNameInNamespace();
Building on user2135970's answer, it's not pretty to mix JNDI with Spring LDAP, but it can be done:
private String getDistinguishedName(String addtlFilter) throws NamingException {
String dn = null;
LdapContextSource contextSource = (LdapContextSource) ldapTemplate.getContextSource();
SearchControls ctrls = new SearchControls();
ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE);
DirContext dc = null;
try {
dc = ldapTemplate.getContextSource().getContext(contextSource.getUserDn(), contextSource.getPassword());
final String filter = String.format("(&(%s)%s)", addtlFilter, searchFilter);
NamingEnumeration<SearchResult> results = dc.search(searchBase, filter, ctrls);
if (results.hasMore()) {
dn = results.next().getNameInNamespace();
}
} finally {
if (dc != null) {
dc.close();
}
}
return dn;
}

Java- Retrieving permissions from LDAP for shiro

im trying to get the User Permissions (read, write, browse,...) for LDAP objects using a java application with shiro. I dont have much experience with LDAP. I set up a server with Apache Directory Studio for testing purpose. Then i created a domain (dc=testdomain) and added a subentry with the "accessControlSubentry" objectclass and added the "prescriptiveACI" attribute. Everthing works the way it should if i browse the server with Apache DS and i can connect to the server in my java app.
In order to get the permissions i subclassed the ActiveDirectoryRealm from shiro. But i cant manage to make the query get the subentrys.
private Set<String> getPermissionsForUser(String username, LdapContext ldapContext) throws NamingException{
Set<String> permissions;
permissions = new LinkedHashSet<String>();
SearchControls searchCtls = new SearchControls();
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
searchCtls.setReturningAttributes(new String[]{"prescriptiveACI"});
String searchFilter = "(objectClass=subentry)";
String searchBase = "dc=testdomain";
NamingEnumeration answer = ldapContext.search(searchBase, searchFilter, searchCtls);
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult) answer.next();
if (log.isDebugEnabled()) {
log.debug("Retrieving permissions for user [" + sr.getName() + "]");
}
Attributes attrs = sr.getAttributes();
if (attrs != null) {
NamingEnumeration ae = attrs.getAll();
while (ae.hasMore()) {
Attribute attr = (Attribute) ae.next();
if (attr.getID().equals("prescriptiveACI")) {
if (log.isDebugEnabled()) {
log.debug("Permissions found");
}
}
}
}
}
return permissions;
}
When I change the searchFilter to "(objectClass=*)" i get all the OrganisationUnits in the domain. But i just cant seem to find the subentry objects that i need for the prescriptiveACI attribute.
Here is the content of my Shiro.ini file
activeDirectoryRealm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealmPermissions
activeDirectoryRealm.systemUsername = uid=admin,ou=system
activeDirectoryRealm.systemPassword = secret
activeDirectoryRealm.url = ldap://localhost:10389
activeDirectoryRealm.searchBase = ""
How can i make the search query subentries? Or is there a better/alternative way to get the permission from the LDAP server?
So you want to find all instances of accessControlSubentry objects with a prescriptiveACI attribute?
Try this:
(&(objectClass=accessControlSubentry)(prescriptiveACI=*))

How can I determine and save a remote user's MAC address?

I'm using the code
byte[] mac = ni.getHardwareAddress();
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
to output: 00-27-0E-C2-53-B7
I need this output to be stored in a variable and I need a query to save it to a MySQL database. I also want to fetch MAC addresses automatically on my login page along with user details.
That way, I can store users' MAC addresses along with their usernames and passwords in the database. The idea is that, when a user logs in, I want to be able to fetch the MAC address automatically to authenticate the user.
How can I do this?
You are asking a lot of questions.
Your mac address is already stored in variable. Array mac[] is a array variable. If you need separate variable just define it like the following:
String myMac = mac[i];
Saving data in DB. I believe that you are already using DB. If for exampel you are using plain JDBC construct insert or update SQL statement like this:
insert into UserData ('mac') VAULUES (?) where user_id=?
Obviously the concrete fields depend on your DB schema.
If you are using some ORM system ask more specific question about this ORM. But in most cases this will be even simpler. If for example you already have class User:
class User {
private String username;
private String password;
// etc
}
...just add the new field mac there:
class User {
private String username;
private String password;
private String mac;
// etc
}
If you are using JPA your DB schema will be updated automatically and the data will be saved there too.
The same is about login page. If you already have login page that shows for example user ID, add similar code for MAC
etc, etc....
The zen of Python says "simple is better than complex."
This code is from SO user Carles Barrobes:
public String obtainMacAddress() throws Exception
{
Process aProc = Runtime.getRuntime().exec("ipconfig /all");
InputStream procOut = new DataInputStream(aProc.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(procOut));
String aMacAddress = "((\\p{XDigit}\\p{XDigit}-){5}\\p{XDigit}\\p{XDigit})";
Pattern aPatternMac = Pattern.compile(aMacAddress);
String aIpAddress = ".*IP.*: (([0-9]*\\.){3}[0-9]).*$";
Pattern aPatternIp = Pattern.compile(aIpAddress);
String aNewAdaptor = "[A-Z].*$";
Pattern aPatternNewAdaptor = Pattern.compile(aNewAdaptor);
// locate first MAC address that has IP address
boolean zFoundMac = false;
boolean zFoundIp = false;
String foundMac = null;
String theGoodMac = null;
String strLine;
while (((strLine = br.readLine()) != null) && !(zFoundIp && zFoundMac)) {
Matcher aMatcherNewAdaptor = aPatternNewAdaptor.matcher(strLine);
if (aMatcherNewAdaptor.matches()) {
zFoundMac = zFoundIp = false;
}
Matcher aMatcherMac = aPatternMac.matcher(strLine);
if (aMatcherMac.find()) {
foundMac = aMatcherMac.group(0);
zFoundMac = true;
}
Matcher aMatcherIp = aPatternIp.matcher(strLine);
if (aMatcherIp.matches()) {
zFoundIp = true;
if(zFoundMac && (theGoodMac == null)) theGoodMac = foundMac;
}
}
aProc.destroy();
aProc.waitFor();
return theGoodMac;}
Note that it is necessary to have an ethernet or wifi connection to run the above.

Categories

Resources