Search in sources :

Example 1 with DataGridServerException

use of com.emc.metalnx.core.domain.exceptions.DataGridServerException in project metalnx-web by irods-contrib.

the class ResourceServiceImpl method getDataGridResource.

private DataGridResource getDataGridResource(Resource irodsResource) {
    logger.info("getDataGridResource()");
    try {
        long irodsResourceId = Long.valueOf(irodsResource.getId());
        String irodsResourceName = irodsResource.getName();
        String irodsResourceZone = irodsResource.getZone().getZoneName();
        String irodsResourceType = irodsResource.getType();
        String irodsResourcePath = irodsResource.getVaultPath();
        long irodsResourceFreeSpace = irodsResource.getFreeSpace();
        Date irodsResourceFreeSpaceTimeStamp = irodsResource.getFreeSpaceTime();
        List<String> irodsResourceChildren = irodsResource.getImmediateChildren();
        String irodsResourceParent = irodsResource.getParentName();
        String irodsResourceStatus = irodsResource.getStatus();
        String irodsResourceHost = irodsResource.getLocation();
        Date irodsResourceCreateTime = irodsResource.getCreateTime();
        Date irodsResourceModifyTime = irodsResource.getModifyTime();
        String irodsResourceInfo = irodsResource.getInfo();
        String irodsContextString = irodsResource.getContextString();
        int irodsResourceTotalRecords = irodsResource.getTotalRecords();
        if (irodsResourceParent == null || irodsResourceParent.isEmpty()) {
            irodsResourceParent = irodsServices.getCurrentUserZone();
        }
        if (irodsResourceType == null || irodsResourceType.isEmpty()) {
            irodsResourceType = irodsContextString;
        }
        DataGridResource newDataGridResource = new DataGridResource(irodsResourceId, irodsResourceName, irodsResourceZone, irodsResourceType, irodsResourcePath, irodsResourceFreeSpace, irodsResourceFreeSpaceTimeStamp, irodsResourceChildren, irodsResourceParent, irodsResourceStatus, irodsResourceHost, irodsResourceCreateTime, irodsResourceModifyTime, irodsResourceInfo, irodsResourceTotalRecords, irodsContextString);
        logger.debug("got dataGridResource:{}", newDataGridResource);
        return newDataGridResource;
    } catch (Throwable t) {
        logger.error("intercepted exception getting data grid resource", t);
        throw new DataGridServerException(t.getMessage());
    }
}
Also used : DataGridServerException(com.emc.metalnx.core.domain.exceptions.DataGridServerException) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) Date(java.util.Date)

Example 2 with DataGridServerException

use of com.emc.metalnx.core.domain.exceptions.DataGridServerException in project metalnx-web by irods-contrib.

the class IRODSAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String username = authentication.getName();
    String password = authentication.getCredentials().toString();
    AuthResponse authResponse;
    UsernamePasswordAuthenticationToken authObject;
    logger.debug("Setting username {}", username);
    try {
        authResponse = this.authenticateAgainstIRODS(username, password);
        // Settings iRODS account
        this.irodsAccount = authResponse.getAuthenticatedIRODSAccount();
        // Retrieving logging user
        User irodsUser = new User();
        try {
            irodsUser = this.irodsAccessObjectFactory.getUserAO(this.irodsAccount).findByName(username);
        } catch (JargonException e) {
            logger.error("Could not find user: " + e.getMessage());
        }
        GrantedAuthority grantedAuth;
        if (irodsUser.getUserType().equals(UserTypeEnum.RODS_ADMIN)) {
            grantedAuth = new IRODSAdminGrantedAuthority();
        } else {
            grantedAuth = new IRODSUserGrantedAuthority();
        }
        // Settings granted authorities
        List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
        grantedAuths.add(grantedAuth);
        // Returning authentication token with the access object factory injected
        authObject = new UsernamePasswordAuthenticationToken(username, password, grantedAuths);
        // Creating UserTokenDetails instance for the current authenticated user
        UserTokenDetails userDetails = new UserTokenDetails();
        userDetails.setIrodsAccount(this.irodsAccount);
        userDetails.setUser(this.user);
        // Settings the user details object into the authentication object
        authObject.setDetails(userDetails);
    } catch (TransactionException e) {
        logger.error("Database not responding");
        throw new DataGridDatabaseException(e.getMessage());
    } catch (InvalidUserException | org.irods.jargon.core.exception.AuthenticationException e) {
        logger.error("Could not authenticate user: ", username);
        throw new DataGridAuthenticationException(e.getMessage());
    } catch (JargonException e) {
        logger.error("Server not responding");
        throw new DataGridServerException(e.getMessage());
    }
    return authObject;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) DataGridAuthenticationException(com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException) AuthenticationException(org.springframework.security.core.AuthenticationException) JargonException(org.irods.jargon.core.exception.JargonException) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) InvalidUserException(org.irods.jargon.core.exception.InvalidUserException) DataGridAuthenticationException(com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException) AuthResponse(org.irods.jargon.core.connection.auth.AuthResponse) DataGridDatabaseException(com.emc.metalnx.core.domain.exceptions.DataGridDatabaseException) TransactionException(org.springframework.transaction.TransactionException) DataGridServerException(com.emc.metalnx.core.domain.exceptions.DataGridServerException)

Aggregations

DataGridServerException (com.emc.metalnx.core.domain.exceptions.DataGridServerException)2 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)1 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)1 DataGridAuthenticationException (com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException)1 DataGridDatabaseException (com.emc.metalnx.core.domain.exceptions.DataGridDatabaseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 AuthResponse (org.irods.jargon.core.connection.auth.AuthResponse)1 InvalidUserException (org.irods.jargon.core.exception.InvalidUserException)1 JargonException (org.irods.jargon.core.exception.JargonException)1 User (org.irods.jargon.core.pub.domain.User)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 TransactionException (org.springframework.transaction.TransactionException)1