use of com.wso2telco.core.dbutils.exception.BusinessException in project core-util by WSO2Telco.
the class WSO2PermissionBuilder method build.
/**
* This will build the permision tree using given users name
*/
public Map<String, Object> build(final String userName) throws BusinessException {
Map<String, Object> permisionTree = Collections.emptyMap();
RetunEntitiy retunItem = new RetunEntitiy();
try {
UserRoleProsser userRoleRetriever = new UserRoleProsser();
UIPermissionNode uiPermissionTree = null;
List<String> currentUserRoleList = userRoleRetriever.getRolesByUserName(userName);
/**
* None of the roles are assign for the user
*/
if (currentUserRoleList.isEmpty()) {
throw new BusinessException("No roles assigned for user :" + userName);
}
for (Iterator<String> iterator = currentUserRoleList.iterator(); iterator.hasNext(); ) {
String roleName = iterator.next();
UIPermissionNode rolePermissions = userAdminStub.getRolePermissions(roleName);
/**
* if the permission node is empty
*/
if (rolePermissions == null || rolePermissions.getNodeList() == null) {
continue;
}
/**
* filter out ui permission only
*/
Optional<UIPermissionNode> optNode = Arrays.stream(rolePermissions.getNodeList()).filter(rowItem -> rowItem.getDisplayName().equalsIgnoreCase(UserRolePermissionType.UI_PERMISSION.getTObject())).findFirst();
/**
* check for existence of node
*/
if (optNode.isPresent()) {
uiPermissionTree = optNode.get();
if (uiPermissionTree.getNodeList() != null && uiPermissionTree.getNodeList().length > 0) {
retunItem = popUserRolePermissions(uiPermissionTree.getNodeList());
if (retunItem.atLeastOneSelected) {
break;
}
} else {
/**
* if the current role does not contain Ui permission then continue
*/
continue;
}
}
}
if (retunItem.returnMap.isEmpty()) {
throw new BusinessException(UserRolePermissionType.UI_PERMISSION.getTObject() + " not assigned for the user :" + userName + " , assigned roles :[ " + StringUtils.join(currentUserRoleList, ",") + "]");
}
} catch (RemoteException | UserAdminUserAdminException e) {
log.error("UIPermission.build", e);
throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR);
}
if (retunItem.returnMap.isEmpty()) {
log.warn(" No ui permission tree found for " + userName);
return Collections.emptyMap();
} else {
return retunItem.returnMap;
}
}
use of com.wso2telco.core.dbutils.exception.BusinessException in project core-util by WSO2Telco.
the class DbUtils method getConnection.
/**
* Gets the db connection.
*
* @return the db connection
* @throws SQLException the SQL exception
*/
public Connection getConnection(DataSourceNames dataSourceName) throws BusinessException {
try {
if (!dbDataSourceMap.containsKey(dataSourceName)) {
Context ctx = new InitialContext();
dbDataSourceMap.put(dataSourceName, (DataSource) ctx.lookup(dataSourceName.jndiName()));
}
DataSource dbDatasource = dbDataSourceMap.get(dataSourceName);
if (dbDatasource != null) {
log.info(dataSourceName.toString() + " DB Initialize successfully.");
return dbDatasource.getConnection();
} else {
log.info(dataSourceName.toString() + " DB NOT Initialize successfully.");
return null;
}
} catch (NamingException | SQLException e) {
log.error("", e);
throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR);
}
/*
*
try {} catch (Exception e) {
log.info("Error while looking up the data source: " + dataSourceName.toString(), e);
throw e;
}*/
}
use of com.wso2telco.core.dbutils.exception.BusinessException in project core-util by WSO2Telco.
the class JSessionAuthenticationFilter method isAuthenticated.
@Override
public boolean isAuthenticated(ContainerRequestContext requestContext, Method method, String header) {
boolean isExpired = false;
try {
UserProfileCachable cachable = CacheFactory.getInstance(CacheType.LOCAL).getService();
String sessionId = header.replace(AuthFilterParam.JSESSION_ID.getTObject(), "");
isExpired = cachable.isExpired(sessionId);
if (isExpired) {
requestContext.abortWith(accessDenied);
return false;
}
UserProfileDTO userProfileDTO = cachable.get(sessionId);
userName = userProfileDTO.getUserName();
log.debug("username : " + userName);
} catch (BusinessException e) {
requestContext.abortWith(accessDenied);
return false;
}
return true;
}
use of com.wso2telco.core.dbutils.exception.BusinessException in project core-util by WSO2Telco.
the class UserManageHealper method getUser.
/**
* this is for extracting the user from the basic auth string.
* eg :Basic YWRtaW46YWRtaW4=
* return the admin as user
* @param authHeader
* @return
* @throws BusinessException
*/
public String getUser(String authHeader) throws BusinessException {
/**
* validate null
*/
if (authHeader == null) {
log.debug("Auth header is null : " + authHeader);
throw new BusinessException(GenaralError.AUTH_HEADER_NULL);
}
/**
* validate auth Header string this need to formated as Basic encodeBase64(userName:password)
*/
if (!(authHeader.contains("Basic") || authHeader.contains("basic"))) {
// if Basic missing in the string
log.debug("keyword Basic is missing in the string : " + authHeader);
throw new BusinessException(GenaralError.INVALID_AUTH_HEADER);
}
if (authHeader.length() <= 5) {
// if encodeBase64(userName:password) missing in the string
log.debug("encodeBase64(userName:password) is missing in the string : " + authHeader);
throw new BusinessException(GenaralError.INVALID_AUTH_HEADER);
}
final String credential = authHeader.substring(5, authHeader.length() - 1).trim();
try {
/**
* decode the credential and convert into string
*/
final String userPwd = new String(Base64.getDecoder().decode(credential), "utf-8");
String[] userPwdArry = userPwd.split(":");
/**
* Split the username:password by :
*/
if (userPwdArry.length == 2) {
// get the user name from the array as first index
return userPwdArry[0];
} else {
/**
* if length is less than two, that implies error on format
*/
log.debug("Invalid format of userName:password in the string : " + authHeader);
throw new BusinessException(GenaralError.INVALID_AUTH_HEADER);
}
} catch (UnsupportedEncodingException e) {
log.error("invalid Auth header format" + authHeader, e);
throw new BusinessException(GenaralError.INVALID_AUTH_HEADER);
}
}
Aggregations