Merge pull request #838 from menakaj/master

Fixing code formatting issues.
apim420
Charitha Goonetilleke 7 years ago committed by GitHub
commit 0e3507053a

@ -32,10 +32,13 @@ import javax.servlet.ServletContextListener;
public class VirtualFireAlarmPermissionUpdateListener implements ServletContextListener { public class VirtualFireAlarmPermissionUpdateListener implements ServletContextListener {
private static Log log = LogFactory.getLog(VirtualFireAlarmPermissionUpdateListener.class); private static Log log = LogFactory.getLog(VirtualFireAlarmPermissionUpdateListener.class);
private static PrivilegedCarbonContext threadLocalCarbonContext;
private static RealmService realmService;
@Override @Override
public void contextInitialized(ServletContextEvent servletContextEvent) { public void contextInitialized(ServletContextEvent servletContextEvent) {
threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
realmService = (RealmService) threadLocalCarbonContext.getOSGiService(RealmService.class, null);
UserStoreManager userStoreManager = getUserStoreManager(); UserStoreManager userStoreManager = getUserStoreManager();
try { try {
if (userStoreManager != null) { if (userStoreManager != null) {
@ -47,7 +50,8 @@ public class VirtualFireAlarmPermissionUpdateListener implements ServletContextL
getAuthorizationManager().authorizeRole(VirtualFireAlarmConstants.ROLE_NAME, getAuthorizationManager().authorizeRole(VirtualFireAlarmConstants.ROLE_NAME,
VirtualFireAlarmConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION); VirtualFireAlarmConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
} }
} } catch (UserStoreException e) { }
} catch (UserStoreException e) {
log.error("Error while creating a role and adding a user for Raspberry PI.", e); log.error("Error while creating a role and adding a user for Raspberry PI.", e);
} }
} }
@ -57,57 +61,44 @@ public class VirtualFireAlarmPermissionUpdateListener implements ServletContextL
} }
public static UserStoreManager getUserStoreManager() { private UserStoreManager getUserStoreManager() {
RealmService realmService;
UserStoreManager userStoreManager; UserStoreManager userStoreManager;
try { try {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
if (realmService == null) { if (realmService == null) {
String msg = "Realm service has not initialized."; String msg = "Realm service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg); throw new IllegalStateException(msg);
} }
int tenantId = ctx.getTenantId(); int tenantId = threadLocalCarbonContext.getTenantId();
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager(); userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
realmService.getTenantUserRealm(tenantId).getAuthorizationManager(); realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving current user store manager"; String msg = "Error occurred while retrieving current user store manager";
log.error(msg, e);
throw new IllegalStateException(msg); throw new IllegalStateException(msg);
} }
return userStoreManager; return userStoreManager;
} }
public static AuthorizationManager getAuthorizationManager() { private AuthorizationManager getAuthorizationManager() {
RealmService realmService;
AuthorizationManager authorizationManager; AuthorizationManager authorizationManager;
try { try {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
if (realmService == null) { if (realmService == null) {
String msg = "Realm service has not initialized."; String msg = "Realm service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg); throw new IllegalStateException(msg);
} }
int tenantId = ctx.getTenantId(); int tenantId = threadLocalCarbonContext.getTenantId();
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager(); authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving current user store manager"; String msg = "Error occurred while retrieving current user store manager";
log.error(msg, e);
throw new IllegalStateException(msg); throw new IllegalStateException(msg);
} }
return authorizationManager; return authorizationManager;
} }
private Permission[] getPermissions() { private Permission[] getPermissions() {
Permission androidSense = new Permission(VirtualFireAlarmConstants.PERM_ENROLL_FIRE_ALARM,
Permission androidSense = new Permission(VirtualFireAlarmConstants.PERM_ENROLL_FIRE_ALARM, CarbonConstants.UI_PERMISSION_ACTION);
CarbonConstants.UI_PERMISSION_ACTION); Permission view = new Permission(VirtualFireAlarmConstants.PERM_OWNING_DEVICE_VIEW,
Permission view = new Permission(VirtualFireAlarmConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants CarbonConstants.UI_PERMISSION_ACTION);
.UI_PERMISSION_ACTION); return new Permission[]{androidSense, view};
return new Permission[]{androidSense, view};
} }
} }
Loading…
Cancel
Save