Example usage for java.lang SecurityException SecurityException

List of usage examples for java.lang SecurityException SecurityException

Introduction

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

Prototype

public SecurityException(Throwable cause) 

Source Link

Document

Creates a SecurityException with the specified cause and a detail message of (cause==null ?

Usage

From source file:CustomSecurityManager.java

public void checkDelete(String fileName) {
    if (fileName != null && fileName.endsWith(".java")) {
        throw new SecurityException(" You are not allowed to delete " + " file names ending with .java");
    }/*www  .j  a v a2 s .  c o m*/
    super.checkDelete(fileName);
}

From source file:security.SecurityAdvice.java

@Override
public void before(Method method, Object[] arg1, Object arg2) throws Throwable {
    UserInfo user = manager.getLoggedUser();
    if (null == user) {
        System.out.println("Not authenticated");
        throw new SecurityException("You must login before attempting to invoke method:" + method.getName());
    } else if ("clarence".equals(user.getUserName())) {
        System.out.println("Logged in user `Clarence` - OKEY!");
    } else {//from w w  w  .  j ava2 s.c o  m
        System.out.println("Logged in user " + user.getUserName() + " NOT GOOD!");
        throw new SecurityException(
                "User: `" + user.getUserName() + "` is not allowed access to " + "method " + method.getName());
    }
}

From source file:com.glaf.core.security.EncryptorFactory.java

public static Encryptor getEncryptor() {
    if (cncryptor == null) {
        if (conf.get("sys.encryptor") != null) {
            String cncryptorClass = conf.get("sys.encryptor");
            try {
                cncryptor = (Encryptor) ReflectUtils.instantiate(cncryptorClass);
            } catch (Exception ex) {
                ex.printStackTrace();/*from w  w w. j av a 2  s .  c  o  m*/
                LOG.error(cncryptorClass + " instantiate error", ex);
            }
        }
        if (cncryptor == null) {
            try {
                cncryptor = new DefaultEncryptor();
            } catch (Exception ex) {
                throw new SecurityException(ex);
            }
        }
    }
    return cncryptor;
}

From source file:com.zf.decipher.DataEn.java

private static byte[] encrypt(byte[] data) throws Exception {
    if (null == secretKey) {
        throw new SecurityException("secretKey is null");
    }// ww  w .  ja  v  a2  s  .c o m
    Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm());
    cipher.init(Cipher.ENCRYPT_MODE, secretKey);
    return cipher.doFinal(data);
}

From source file:be.fedict.eid.applet.service.impl.UserIdentifierUtil.java

/**
 * Gives back a unique user identifier given an X509 certificate.
 * /*w w  w .  j  a va  2  s .c  o m*/
 * @param signingCertificate
 * @return
 */
public static String getUserId(X509Certificate signingCertificate) {
    X500Principal userPrincipal = signingCertificate.getSubjectX500Principal();
    String name = userPrincipal.toString();
    int serialNumberBeginIdx = name.indexOf("SERIALNUMBER=");
    if (-1 == serialNumberBeginIdx) {
        throw new SecurityException("SERIALNUMBER not found in X509 CN");
    }
    int serialNumberValueBeginIdx = serialNumberBeginIdx + "SERIALNUMBER=".length();
    int serialNumberValueEndIdx = name.indexOf(",", serialNumberValueBeginIdx);
    if (-1 == serialNumberValueEndIdx) {
        serialNumberValueEndIdx = name.length();
    }
    String userId = name.substring(serialNumberValueBeginIdx, serialNumberValueEndIdx);
    return userId;
}

From source file:com.appeligo.search.entity.Permissions.java

public static void checkUser(User user) {
    if ((getCurrentUser() != SUPERUSER) && (getCurrentUser() != null) && (!getCurrentUser().equals(user))) {
        throw new SecurityException("Invalid user. User id " + user.getUserId()
                + " does not match current user: " + getCurrentUser());
    }//from   ww  w .j a  v  a  2 s .  c  om
}

From source file:org.mule.management.support.SimplePasswordJmxAuthenticator.java

public Subject authenticate(Object authToken) {
    if (authToken == null) {
        throw new SecurityException("No authentication token available");
    }/* ww w .  j  a  va2  s.com*/
    if (!(authToken instanceof String[]) || ((String[]) authToken).length != 2) {
        throw new SecurityException("Unsupported credentials format");
    }

    String[] authentication = (String[]) authToken;

    String username = StringUtils.defaultString(authentication[0]);
    String password = StringUtils.defaultString(authentication[1]);

    if (!credentials.containsKey(username)) {
        throw new SecurityException("Unauthenticated user: " + username);
    }

    if (!password.equals(ObjectUtils.toString(credentials.get(username)))) {
        throw new SecurityException("Invalid password");
    }

    Set principals = new HashSet();
    principals.add(new JMXPrincipal(username));
    return new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
}

From source file:com.zf.decipher.DataEn.java

private static byte[] decrypt(byte[] data) throws Exception {
    if (null == secretKey) {
        throw new SecurityException("secretKey is null");
    }/*from  w  ww.ja  va2 s. c o m*/
    Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm());
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    return cipher.doFinal(data);
}

From source file:org.socialhistoryservices.pid.util.NamingAuthority.java

public static List<String> getNaRole(Authentication userAuthentication) {

    final Collection<? extends GrantedAuthority> authorities = userAuthentication.getAuthorities();
    final List<String> nas = new ArrayList(authorities.size());
    for (GrantedAuthority authority : authorities) {
        String role = authority.getAuthority().replace("\n", ""); // ToDo: find out if there still is a \n in the role.
        if (role.startsWith(role_prefix)) {
            nas.add(role.substring(role_prefix.length()));
        } else if (role.startsWith(role_prefix_deprecated)) {
            nas.add(role.substring(role_prefix_deprecated.length()));
        }//from  w w  w . j av a2 s .com
    }
    if (nas.size() == 0)
        throw new SecurityException("User " + userAuthentication.getName()
                + " has not got the required roles to use this service.");
    return nas;
}

From source file:org.apache.hadoop.hive.llap.daemon.impl.LlapTokenChecker.java

public static LlapTokenInfo getTokenInfo(String clusterId) throws IOException {
    if (!UserGroupInformation.isSecurityEnabled())
        return NO_SECURITY;
    UserGroupInformation current = UserGroupInformation.getCurrentUser();
    String kerberosName = current.hasKerberosCredentials() ? current.getShortUserName() : null;
    List<LlapTokenIdentifier> tokens = getLlapTokens(current, clusterId);
    if ((tokens == null || tokens.isEmpty()) && kerberosName == null) {
        throw new SecurityException("No tokens or kerberos for " + current);
    }/*from  www. j  av  a  2  s  .c  o  m*/
    warnMultipleTokens(tokens);
    return getTokenInfoInternal(kerberosName, tokens);
}