Example usage for java.lang SecurityException getMessage

List of usage examples for java.lang SecurityException getMessage

Introduction

In this page you can find the example usage for java.lang SecurityException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.jolokia.jvmagent.handler.JolokiaHttpHandler.java

private void sendForbidden(HttpExchange pExchange, SecurityException securityException) throws IOException {
    String response = "403 (Forbidden)\n";
    if (securityException != null && securityException.getMessage() != null) {
        response += "\n" + securityException.getMessage() + "\n";
    }/*from  w  w w.j  a  v a  2 s . c o  m*/
    pExchange.sendResponseHeaders(403, response.length());
    OutputStream os = pExchange.getResponseBody();
    os.write(response.getBytes());
    os.close();
}

From source file:org.sakaiproject.kernel.rest.search.RestSearchProvider.java

/**
 * {@inheritDoc}/* www .j a v a  2s. com*/
 *
 * @see org.sakaiproject.kernel.api.rest.RestProvider#dispatch(java.lang.String[],
 *      javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
public void dispatch(String[] elements, HttpServletRequest request, HttpServletResponse response) {
    try {
        Map<String, Object> map = doSearch(request, response);
        if (map != null) {
            String responseBody = beanConverter.convertToString(map);
            response.setContentType(RestProvider.CONTENT_TYPE);
            response.getOutputStream().print(responseBody);
        }
    } catch (SecurityException ex) {
        throw ex;
    } catch (RestServiceFaultException ex) {
        throw ex;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RestServiceFaultException(ex.getMessage(), ex);
    }
}

From source file:org.seedstack.seed.core.internal.application.ConfigurationMembersInjectorTest.java

public void injectMembersTest(String configParamToTest, boolean isInConfig) {
    Field field;/*from   w ww.  ja  va 2  s  . co m*/
    try {
        field = this.getClass().getDeclaredField(configParamToTest);
        ConfigurationMembersInjector<ConfigurationMembersInjectorTest> configurationMembersInjector = new ConfigurationMembersInjector<ConfigurationMembersInjectorTest>(
                field, mockConfiguration(field, isInConfig), field.getAnnotation(Configuration.class));
        configurationMembersInjector.injectMembers(this);
    } catch (SecurityException e) {
        Fail.fail(e.getMessage());
    } catch (NoSuchFieldException e) {
        Fail.fail(e.getMessage());
    }
}

From source file:org.sakaiproject.crudplus.logic.test.CrudPlusLogicImplTest.java

/**
 * Test method for {@link org.sakaiproject.crudplus.logic.impl.CrudPlusLogicImpl#removeItem(org.sakaiproject.crudplus.model.CrudPlusItem)}.
 *//*from  w w  w.j  a v  a 2s  .  c  o m*/
public void testRemoveItem() {
    // set up mock objects with return values
    userDirectoryService.getCurrentUser(); // expect this to be called
    userDirectoryServiceControl.setReturnValue(new TestUser(USER_ID));
    userDirectoryServiceControl.setReturnValue(new TestUser(MAINT_USER_ID));
    userDirectoryServiceControl.setReturnValue(new TestUser(ADMIN_USER_ID));
    userDirectoryServiceControl.setReturnValue(new TestUser(MAINT_USER_ID));
    userDirectoryServiceControl.setReturnValue(new TestUser(USER_ID));

    securityService.unlock(new TestUser(USER_ID), CrudPlusLogicImpl.ITEM_WRITE_ANY, SITE_REF);
    securityServiceControl.setReturnValue(false, MockControl.ZERO_OR_MORE);
    securityService.unlock(new TestUser(MAINT_USER_ID), CrudPlusLogicImpl.ITEM_WRITE_ANY, SITE_REF);
    securityServiceControl.setReturnValue(true, MockControl.ZERO_OR_MORE);

    // activate the mock objects
    userDirectoryServiceControl.replay();
    securityServiceControl.replay();
    toolManagerControl.replay();
    siteServiceControl.replay();

    // mock object is needed here
    try {
        logicImpl.removeItem(adminitem); // user cannot delete this
        Assert.fail("Should have thrown SecurityException");
    } catch (SecurityException e) {
        Assert.assertNotNull(e.getMessage());
        log.info("Could not remove item (this is correct)");
    }

    try {
        logicImpl.removeItem(adminitem); // permed user cannot delete this
        Assert.fail("Should have thrown SecurityException");
    } catch (SecurityException e) {
        Assert.assertNotNull(e.getMessage());
        log.info("Could not remove item (this is correct)");
    }

    CrudPlusItem item;

    logicImpl.removeItem(adminitem); // admin can delete this
    item = logicImpl.getItemById(adminitem.getId());
    Assert.assertNull(item);

    logicImpl.removeItem(maintitem); // permed user can delete this
    item = logicImpl.getItemById(maintitem.getId());
    Assert.assertNull(item);

    logicImpl.removeItem(item1); // user can delete this
    item = logicImpl.getItemById(item1.getId());
    Assert.assertNull(item);

    // verify the mock objects were used
    userDirectoryServiceControl.verify();
    securityServiceControl.verify();
    toolManagerControl.verify();
    siteServiceControl.verify();
}

From source file:abanyu.transphone.taxi.controller.LoginController.java

public void getServerData() {
    int i = 1;/*from  w w w  .j a va2  s.c  om*/
    for (String param : urlParams) {
        Object value = "";

        try {
            value = loginMVC.getLoginModel().getClass().getMethod(param).invoke(loginMVC.getLoginModel());
        } catch (SecurityException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered IO exception on LoginController, getServerData(): " + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        } catch (NoSuchMethodException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered No such method exception on LoginControler, getServerData(): "
                            + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        } catch (IllegalArgumentException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered Illegal Argument exception on LoginController, getServerData(): "
                            + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        } catch (IllegalAccessException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered Illegal Access exception on LoginController, getServerData(): "
                            + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        } catch (InvocationTargetException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered Invocation Target exception on LoginController, getServerData(): "
                            + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        }

        if (setterParamClass.equals("int"))
            nextUrl = new StringBuilder().append(nextUrl).append("&arg").append(i).append("=").append(value)
                    .toString();
        else
            nextUrl = new StringBuilder().append(nextUrl).append("&arg").append(i).append("=")
                    .append(String.valueOf(value)).toString();

        i++;
    }

    new JSONManager(loginMVC, nextUrl, progDialogMsg, nextFunction, nextMode).execute();
}

From source file:org.sakaiproject.kernel.rest.me.RestMeProvider.java

/**
 * {@inheritDoc}//from  ww w .  j  av  a 2 s  .c  o m
 *
 * @see org.sakaiproject.kernel.api.rest.RestProvider#dispatch(java.lang.String[],
 *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *      /x/y/z?searchOrder=1231231
 */
public void dispatch(String[] elements, HttpServletRequest request, HttpServletResponse response) {
    try {
        if (elements.length > 1) {
            doOtherUser(elements, request, response);
        } else {
            doUser(elements, request, response);
        }
    } catch (SecurityException ex) {
        throw ex;
    } catch (RestServiceFaultException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new RestServiceFaultException(ex.getMessage(), ex);
    }

}

From source file:com.cws.esolutions.security.processors.impl.AuthenticationProcessorImpl.java

/**
 * @see com.cws.esolutions.security.processors.interfaces.IAuthenticationProcessor#processAgentLogon(com.cws.esolutions.security.processors.dto.AuthenticationRequest)
 *//*from w w w.  ja v a  2s  .  c o m*/
public AuthenticationResponse processAgentLogon(final AuthenticationRequest request)
        throws AuthenticationException {
    final String methodName = IAuthenticationProcessor.CNAME
            + "#processAgentLogon(final AuthenticationRequest request) throws AuthenticationException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("AuthenticationRequest: {}", request);
    }

    UserAccount userAccount = null;
    AuthenticationResponse response = new AuthenticationResponse();

    final RequestHostInfo reqInfo = request.getHostInfo();
    final UserAccount authUser = request.getUserAccount();
    final AuthenticationData authSec = request.getUserSecurity();

    if (DEBUG) {
        DEBUGGER.debug("RequestHostInfo: {}", reqInfo);
        DEBUGGER.debug("UserAccount: {}", authUser);
    }

    try {
        List<String[]> userInfo = userManager.searchUsers(authUser.getUsername());

        if (DEBUG) {
            DEBUGGER.debug("List<Object[]>: {}", userInfo);
        }

        if (userInfo.size() != 1) {
            response.setRequestStatus(SecurityRequestStatus.FAILURE);

            return response;
        }

        String userSalt = userSec.getUserSalt(userInfo.get(0)[0], SaltType.LOGON.name());

        if (StringUtils.isEmpty(userSalt)) {
            throw new AuthenticationException("Unable to obtain configured user salt. Cannot continue");
        }

        List<Object> authObject = authenticator.performLogon(userInfo.get(0)[1],
                PasswordUtils.encryptText(authSec.getPassword(), userSalt,
                        secBean.getConfigData().getSecurityConfig().getAuthAlgorithm(),
                        secBean.getConfigData().getSecurityConfig().getIterations(),
                        secBean.getConfigData().getSystemConfig().getEncoding()));

        if (DEBUG) {
            DEBUGGER.debug("List<Object>: {}", authObject);
        }

        if (authObject.size() == 0) {
            throw new AuthenticationException("Authentication processing failed. Cannot continue.");
        }

        if (((Integer) authObject.get(3) >= secConfig.getMaxAttempts()) || ((Boolean) authObject.get(13))) {
            // user locked
            response.setRequestStatus(SecurityRequestStatus.FAILURE);

            return response;
        }

        // if the user has enabled otp auth, do it here
        if (StringUtils.isNotEmpty((String) authObject.get(2))) {
            userAccount = new UserAccount();
            userAccount.setGuid((String) authObject.get(0));
            userAccount.setUsername((String) authObject.get(1));
            userAccount.setStatus(LoginStatus.CONTINUE);

            response.setRequestStatus(SecurityRequestStatus.SUCCESS);
            response.setUserAccount(userAccount);

            return response;
        }

        userAccount = new UserAccount();
        userAccount.setGuid((String) authObject.get(0));
        userAccount.setUsername((String) authObject.get(1));
        userAccount.setFailedCount((Integer) authObject.get(3));
        userAccount.setLastLogin((Date) authObject.get(4));
        userAccount.setExpiryDate((Date) authObject.get(5));
        userAccount.setSurname((String) authObject.get(6));
        userAccount.setGivenName((String) authObject.get(7));
        userAccount.setDisplayName((String) authObject.get(8));
        userAccount.setEmailAddr((String) authObject.get(9));
        userAccount.setPagerNumber((String) authObject.get(10));
        userAccount.setTelephoneNumber((String) authObject.get(11));
        userAccount.setGroups(StringUtils.split((String) authObject.get(12), ","));
        userAccount.setSuspended((Boolean) authObject.get(13));
        userAccount.setOlrSetup((Boolean) authObject.get(14));
        userAccount.setOlrLocked((Boolean) authObject.get(15));

        if (DEBUG) {
            DEBUGGER.debug("UserAccount: {}", userAccount);
        }

        // have a user account, run with it
        if ((userAccount.getExpiryDate().before(new Date(System.currentTimeMillis())))
                || (userAccount.getExpiryDate().equals(new Date(System.currentTimeMillis())))) {
            userAccount.setStatus(LoginStatus.EXPIRED);

            response.setRequestStatus(SecurityRequestStatus.SUCCESS);
            response.setUserAccount(userAccount);
        } else {
            userAccount.setStatus(LoginStatus.SUCCESS);

            response.setRequestStatus(SecurityRequestStatus.SUCCESS);
            response.setUserAccount(userAccount);
        }

        if (DEBUG) {
            DEBUGGER.debug("AuthenticationResponse: {}", response);
        }
    } catch (AuthenticatorException ax) {
        ERROR_RECORDER.error(ax.getMessage(), ax);

        try {
            if (ax.getResultCode() == ResultCode.INVALID_CREDENTIALS) {
                // failed authentication, update counter
                // find out if this is a valid user...
                List<String[]> userList = userManager.searchUsers(authUser.getUsername());

                // only do the work if the userlist is equal to 1.
                // if there were 150 users found then we dont want
                // to shoot them all
                if ((userList != null) && (userList.size() == 1)) {
                    // do it
                    userManager.modifyUserLock(userList.get(0)[0], false, request.getCount() + 1);
                }
            }
        } catch (UserManagementException umx) {
            ERROR_RECORDER.error(umx.getMessage(), umx);
        }

        response.setCount(request.getCount() + 1);
        response.setRequestStatus(SecurityRequestStatus.FAILURE);
    } catch (SecurityServiceException ssx) {
        ERROR_RECORDER.error(ssx.getMessage(), ssx);

        throw new AuthenticationException(ssx.getMessage(), ssx);
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new AuthenticationException(sqx.getMessage(), sqx);
    } catch (SecurityException sx) {
        ERROR_RECORDER.error(sx.getMessage(), sx);
    } finally {
        // audit
        try {
            AuditEntry auditEntry = new AuditEntry();
            auditEntry.setHostInfo(reqInfo);
            auditEntry.setAuditType(AuditType.LOGON);
            auditEntry.setUserAccount(authUser);
            auditEntry.setAuthorized(Boolean.TRUE);
            auditEntry.setApplicationId(request.getApplicationId());
            auditEntry.setApplicationName(request.getApplicationName());

            if (DEBUG) {
                DEBUGGER.debug("AuditEntry: {}", auditEntry);
            }

            AuditRequest auditRequest = new AuditRequest();
            auditRequest.setAuditEntry(auditEntry);

            if (DEBUG) {
                DEBUGGER.debug("AuditRequest: {}", auditRequest);
            }

            auditor.auditRequest(auditRequest);
        } catch (AuditServiceException asx) {
            ERROR_RECORDER.error(asx.getMessage(), asx);
        }
    }

    return response;
}

From source file:org.hyperic.hq.plugin.weblogic.jmx.WeblogicRuntimeDiscoverer.java

public RuntimeResourceReport discoverResources(int serverId, AIPlatformValue aiplatform, ConfigResponse config)
        throws PluginException {

    if (useJAAS) {
        return discoverAs(serverId, aiplatform, config);
    } else {/*from   w w w . j  a v  a  2 s.c  o m*/
        try {
            return discover(serverId, aiplatform, config);
        } catch (SecurityException e) {
            String msg = "SecurityException: " + e.getMessage();
            throw new PluginException(msg, e);
        }
    }
}

From source file:abanyu.transphone.taxi.controller.LoginController.java

public void setLoginDataIDs() {
    if (requirePassword) {
        System.out.println("Box: " + box);
        if (box.equals("password")) {
            passwordBox = new PasswordBox(loginMVC, dbTableEntryList, itemClicked, idSetterFunction,
                    setterParamClass, mapComparator, keyGet);
            passwordBox.show();//from   w  w w . jav  a 2  s .  com
        } else {
            loginBox = new LoginBox(loginMVC, dbTableEntryList, itemClicked, idSetterFunction, setterParamClass,
                    mapComparator, keyGet);
            loginBox.show();
        }
    } else {
        try {
            if (setterParamClass.equals("int"))
                loginMVC.getLoginModel().getClass().getMethod(idSetterFunction, int.class)
                        .invoke(loginMVC.getLoginModel(), Integer.parseInt((String) loginMVC.getLoginModel()
                                .getKeyValueByName(mapComparator, itemClicked, keyGet, dbTableEntryList)));
            else
                loginMVC.getLoginModel().getClass().getMethod(idSetterFunction, String.class)
                        .invoke(loginMVC.getLoginModel(), loginMVC.getLoginModel()
                                .getKeyValueByName(mapComparator, itemClicked, keyGet, dbTableEntryList));

            thisMode = nextMode;//change of mode when the target setter function has been invoked          
        } catch (SecurityException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered IO exception on LoginController, setLoginDataIDs(): " + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        } catch (NoSuchMethodException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered No such method exception on LoginControler, setLoginDataIDs(): "
                            + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        } catch (IllegalArgumentException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered Illegal Argument exception on LoginController, setLoginDataIDs(): "
                            + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        } catch (IllegalAccessException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered Illegal Access exception on LoginController, setLoginDataIDs(): "
                            + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        } catch (InvocationTargetException e) {
            Toast.makeText(loginMVC.getLoginView(),
                    "Encountered Invocation Target exception on LoginController, setLoginDataIDS(): "
                            + e.getMessage(),
                    Toast.LENGTH_LONG).show();
        }

        getServerData();
    }

}

From source file:org.hyperic.hq.plugin.weblogic.jmx.WeblogicRuntimeDiscoverer.java

private RuntimeResourceReport discoverAs(int serverId, AIPlatformValue aiplatform, ConfigResponse config)
        throws PluginException {

    Object obj;/*from  w w  w .  j a v a 2  s .  c o  m*/
    WeblogicAuth auth = WeblogicAuth.getInstance(config.toProperties());

    this.serverId = serverId;
    this.aiplatform = aiplatform;
    this.config = config;

    try {
        obj = auth.runAs(this);
    } catch (SecurityException e) {
        throw new PluginException(e.getMessage(), e);
    }

    if (obj instanceof RuntimeResourceReport) {
        return (RuntimeResourceReport) obj;
    }

    if (obj instanceof PluginException) {
        throw (PluginException) obj;
    }

    if (obj instanceof Exception) {
        Exception e = (Exception) obj;
        throw new PluginException(e.getMessage(), e);
    }

    throw new IllegalArgumentException();
}