Commit dfd81ead69e926b62157d1b13bf5147946f3b5d7

Authored by Cleverson Sacramento
1 parent befcc946
Exists in master

Movendo a extensão JAAS da incubadora:

https://github.com/demoiselle/laboratory/tree/master/incubator/jaas
impl/extension/jaas/.gitignore 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +/target
  2 +/.project
  3 +/.classpath
  4 +/.settings
  5 +/.externalToolBuilders
... ...
impl/extension/jaas/pom.xml 0 → 100644
... ... @@ -0,0 +1,93 @@
  1 +<!--
  2 + Demoiselle Framework
  3 + Copyright (C) 2010 SERPRO
  4 + ============================================================================
  5 + This file is part of Demoiselle Framework.
  6 +
  7 + Demoiselle Framework is free software; you can redistribute it and/or
  8 + modify it under the terms of the GNU Lesser General Public License version 3
  9 + as published by the Free Software Foundation.
  10 +
  11 + This program is distributed in the hope that it will be useful,
  12 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + GNU General Public License for more details.
  15 +
  16 + You should have received a copy of the GNU Lesser General Public License version 3
  17 + along with this program; if not, see <http://www.gnu.org/licenses />
  18 + or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + Fifth Floor, Boston, MA 02110-1301, USA.
  20 + ============================================================================
  21 + Este arquivo é parte do Framework Demoiselle.
  22 +
  23 + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + do Software Livre (FSF).
  26 +
  27 + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + para maiores detalhes.
  31 +
  32 + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses />
  34 + ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +-->
  37 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  38 +
  39 + <modelVersion>4.0.0</modelVersion>
  40 +
  41 + <artifactId>demoiselle-jaas</artifactId>
  42 + <packaging>jar</packaging>
  43 +
  44 + <parent>
  45 + <groupId>br.gov.frameworkdemoiselle</groupId>
  46 + <artifactId>demoiselle-extension-parent</artifactId>
  47 + <version>2.3.1-SNAPSHOT</version>
  48 + <relativePath>../../../parent/extension</relativePath>
  49 + </parent>
  50 +
  51 + <name>Demoiselle Framework JAAS Extension</name>
  52 + <description>
  53 + JAAS Extension
  54 + </description>
  55 + <url>http://www.frameworkdemoiselle.gov.br</url>
  56 +
  57 + <licenses>
  58 + <license>
  59 + <name>GNU Lesser General Public License, Version 3</name>
  60 + <url>http://www.gnu.org/licenses/lgpl-3.0.txt</url>
  61 + </license>
  62 + </licenses>
  63 +
  64 + <organization>
  65 + <name>SERPRO - Serviço Federal de Processamento de Dados</name>
  66 + <url>http://www.serpro.gov.br</url>
  67 + </organization>
  68 +
  69 + <repositories>
  70 + <repository>
  71 + <id>sonatype-nexus-snapshots</id>
  72 + <name>Sonatype Nexus Snapshots</name>
  73 + <url>https://oss.sonatype.org/content/repositories/snapshots</url>
  74 + <snapshots>
  75 + <enabled>true</enabled>
  76 + </snapshots>
  77 + <releases>
  78 + <enabled>false</enabled>
  79 + </releases>
  80 + </repository>
  81 + <repository>
  82 + <id>sonatype-nexus-releases</id>
  83 + <name>Sonatype Nexus Releases</name>
  84 + <url>https://oss.sonatype.org/content/repositories/releases</url>
  85 + <snapshots>
  86 + <enabled>false</enabled>
  87 + </snapshots>
  88 + <releases>
  89 + <enabled>true</enabled>
  90 + </releases>
  91 + </repository>
  92 + </repositories>
  93 +</project>
... ...
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JAASConfig.java 0 → 100644
... ... @@ -0,0 +1,57 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.configuration;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +import br.gov.frameworkdemoiselle.configuration.Configuration;
  42 +
  43 +@Configuration(prefix = "frameworkdemoiselle.security")
  44 +public class JAASConfig implements Serializable {
  45 +
  46 + private static final long serialVersionUID = 1L;
  47 +
  48 + private String loginModuleName;
  49 +
  50 + public String getLoginModuleName() {
  51 + return loginModuleName;
  52 + }
  53 +
  54 + public void setLoginModuleName(String loginModuleName) {
  55 + this.loginModuleName = loginModuleName;
  56 + }
  57 +}
... ...
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/internal/producer/CallbackHandlerProducer.java 0 → 100644
... ... @@ -0,0 +1,60 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.producer;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +import javax.enterprise.context.RequestScoped;
  42 +import javax.enterprise.inject.Produces;
  43 +import javax.security.auth.callback.CallbackHandler;
  44 +
  45 +import br.gov.frameworkdemoiselle.internal.proxy.CallbackHandlerProxy;
  46 +import br.gov.frameworkdemoiselle.security.Credentials;
  47 +import br.gov.frameworkdemoiselle.util.Beans;
  48 +
  49 +public class CallbackHandlerProducer implements Serializable {
  50 +
  51 + private static final long serialVersionUID = 1L;
  52 +
  53 + @Produces
  54 + @RequestScoped
  55 + public static CallbackHandler create() {
  56 + Credentials credentials = Beans.getReference(Credentials.class);
  57 +
  58 + return new CallbackHandlerProxy(credentials);
  59 + }
  60 +}
... ...
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoginContextFactory.java 0 → 100644
... ... @@ -0,0 +1,110 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.producer;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +import javax.enterprise.context.ContextNotActiveException;
  42 +import javax.enterprise.context.SessionScoped;
  43 +import javax.security.auth.callback.CallbackHandler;
  44 +import javax.security.auth.login.LoginContext;
  45 +import javax.security.auth.login.LoginException;
  46 +
  47 +import br.gov.frameworkdemoiselle.internal.configuration.JAASConfig;
  48 +import br.gov.frameworkdemoiselle.security.SecurityException;
  49 +import br.gov.frameworkdemoiselle.util.Beans;
  50 +
  51 +@SessionScoped
  52 +public class LoginContextFactory implements Serializable {
  53 +
  54 + private static final long serialVersionUID = 1L;
  55 +
  56 + private transient LoginContext loginContext;
  57 +
  58 + private String name;
  59 +
  60 + private CallbackHandler callbackHandler;
  61 +
  62 + private LoginContext getLoginContext() throws LoginException {
  63 + if (this.loginContext == null) {
  64 + this.loginContext = new LoginContext(getName(), getCallbackHandler());
  65 + }
  66 +
  67 + return this.loginContext;
  68 + }
  69 +
  70 + public static LoginContext createLoginContext() {
  71 + LoginContext loginContext;
  72 +
  73 + try {
  74 + loginContext = Beans.getReference(LoginContextFactory.class).getLoginContext();
  75 +
  76 + } catch (ContextNotActiveException cause) {
  77 + loginContext = null;
  78 +
  79 + } catch (LoginException cause) {
  80 + throw new SecurityException(cause);
  81 + }
  82 +
  83 + if (loginContext == null) {
  84 + try {
  85 + loginContext = new LoginContextFactory().getLoginContext();
  86 +
  87 + } catch (LoginException cause) {
  88 + throw new SecurityException(cause);
  89 + }
  90 + }
  91 +
  92 + return loginContext;
  93 + }
  94 +
  95 + private String getName() {
  96 + if (this.name == null) {
  97 + this.name = Beans.getReference(JAASConfig.class).getLoginModuleName();
  98 + }
  99 +
  100 + return this.name;
  101 + }
  102 +
  103 + private CallbackHandler getCallbackHandler() {
  104 + if (this.callbackHandler == null) {
  105 + this.callbackHandler = Beans.getReference(CallbackHandler.class);
  106 + }
  107 +
  108 + return this.callbackHandler;
  109 + }
  110 +}
... ...
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/CallbackHandlerProxy.java 0 → 100644
... ... @@ -0,0 +1,92 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.proxy;
  38 +
  39 +import java.io.IOException;
  40 +import java.io.Serializable;
  41 +
  42 +import javax.security.auth.callback.Callback;
  43 +import javax.security.auth.callback.CallbackHandler;
  44 +import javax.security.auth.callback.NameCallback;
  45 +import javax.security.auth.callback.PasswordCallback;
  46 +import javax.security.auth.callback.UnsupportedCallbackException;
  47 +
  48 +import br.gov.frameworkdemoiselle.security.Credentials;
  49 +
  50 +public class CallbackHandlerProxy implements CallbackHandler, Serializable {
  51 +
  52 + private static final long serialVersionUID = 1L;
  53 +
  54 + private transient CallbackHandler delegate;
  55 +
  56 + private final Credentials credentials;
  57 +
  58 + public CallbackHandlerProxy(Credentials credentials) {
  59 + this.credentials = credentials;
  60 + }
  61 +
  62 + private CallbackHandler getDelegate() {
  63 + if (this.delegate == null) {
  64 + this.delegate = create();
  65 + }
  66 +
  67 + return this.delegate;
  68 + }
  69 +
  70 + private CallbackHandler create() {
  71 + return new CallbackHandler() {
  72 +
  73 + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
  74 + for (int i = 0; i < callbacks.length; i++) {
  75 + if (callbacks[i] instanceof NameCallback) {
  76 + ((NameCallback) callbacks[i]).setName(credentials.getUsername());
  77 +
  78 + } else if (callbacks[i] instanceof PasswordCallback) {
  79 + ((PasswordCallback) callbacks[i]).setPassword(credentials.getPassword().toCharArray());
  80 +
  81 + } else {
  82 + System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX Unsupported callback " + callbacks[i]);
  83 + }
  84 + }
  85 + }
  86 + };
  87 + }
  88 +
  89 + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
  90 + getDelegate().handle(callbacks);
  91 + }
  92 +}
... ...
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/LoginContextProxy.java 0 → 100644
... ... @@ -0,0 +1,120 @@
  1 +///*
  2 +// * Demoiselle Framework
  3 +// * Copyright (C) 2010 SERPRO
  4 +// * ----------------------------------------------------------------------------
  5 +// * This file is part of Demoiselle Framework.
  6 +// *
  7 +// * Demoiselle Framework is free software; you can redistribute it and/or
  8 +// * modify it under the terms of the GNU Lesser General Public License version 3
  9 +// * as published by the Free Software Foundation.
  10 +// *
  11 +// * This program is distributed in the hope that it will be useful,
  12 +// * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +// * GNU General Public License for more details.
  15 +// *
  16 +// * You should have received a copy of the GNU Lesser General Public License version 3
  17 +// * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 +// * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 +// * Fifth Floor, Boston, MA 02110-1301, USA.
  20 +// * ----------------------------------------------------------------------------
  21 +// * Este arquivo é parte do Framework Demoiselle.
  22 +// *
  23 +// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 +// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 +// * do Software Livre (FSF).
  26 +// *
  27 +// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 +// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 +// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 +// * para maiores detalhes.
  31 +// *
  32 +// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 +// * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 +// * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 +// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +// */
  37 +//package br.gov.frameworkdemoiselle.internal.proxy;
  38 +//
  39 +//import java.io.Serializable;
  40 +//
  41 +//import javax.enterprise.context.Dependent;
  42 +//import javax.security.auth.Subject;
  43 +//import javax.security.auth.callback.CallbackHandler;
  44 +//import javax.security.auth.login.LoginContext;
  45 +//import javax.security.auth.login.LoginException;
  46 +//
  47 +//import br.gov.frameworkdemoiselle.internal.configuration.JAASConfig;
  48 +//import br.gov.frameworkdemoiselle.security.SecurityException;
  49 +//import br.gov.frameworkdemoiselle.util.Beans;
  50 +//
  51 +////@Alternative
  52 +////@SessionScoped
  53 +//@Dependent
  54 +//public class LoginContextProxy extends LoginContext implements Serializable {
  55 +//
  56 +// private static final long serialVersionUID = 1L;
  57 +//
  58 +// private transient LoginContext delegate;
  59 +//
  60 +// private transient CallbackHandler callbackHandler;
  61 +//
  62 +// private String name;
  63 +//
  64 +// // public LoginContextProxy() {
  65 +// // super(name)
  66 +// // }
  67 +//
  68 +// public LoginContextProxy() {
  69 +// super("");
  70 +// }
  71 +//
  72 +// private String getName() {
  73 +// if (this.name == null) {
  74 +// this.name = Beans.getReference(JAASConfig.class).getLoginModuleName();
  75 +// }
  76 +//
  77 +// return this.name;
  78 +// }
  79 +//
  80 +// private LoginContext getDelegate() {
  81 +// if (this.delegate == null) {
  82 +// try {
  83 +// this.delegate = new LoginContext(getName(), getCallbackHandler());
  84 +//
  85 +// } catch (LoginException cause) {
  86 +// throw new SecurityException(cause);
  87 +// }
  88 +// }
  89 +//
  90 +// return this.delegate;
  91 +// }
  92 +//
  93 +// private CallbackHandler getCallbackHandler() {
  94 +// if (this.callbackHandler == null) {
  95 +// this.callbackHandler = Beans.getReference(CallbackHandler.class);
  96 +// }
  97 +//
  98 +// return this.callbackHandler;
  99 +// }
  100 +//
  101 +// public boolean equals(Object object) {
  102 +// return getDelegate().equals(object);
  103 +// }
  104 +//
  105 +// public Subject getSubject() {
  106 +// return getDelegate().getSubject();
  107 +// }
  108 +//
  109 +// public int hashCode() {
  110 +// return getDelegate().hashCode();
  111 +// }
  112 +//
  113 +// public void login() throws LoginException {
  114 +// getDelegate().login();
  115 +// }
  116 +//
  117 +// public void logout() throws LoginException {
  118 +// getDelegate().logout();
  119 +// }
  120 +//}
... ...
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/security/Credentials.java 0 → 100644
... ... @@ -0,0 +1,75 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.security;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +import javax.enterprise.context.RequestScoped;
  42 +import javax.inject.Named;
  43 +
  44 +@Named
  45 +@RequestScoped
  46 +public class Credentials implements Serializable {
  47 +
  48 + private static final long serialVersionUID = 1L;
  49 +
  50 + private String username;
  51 +
  52 + private String password;
  53 +
  54 + public void clear() {
  55 + this.username = null;
  56 + this.password = null;
  57 + }
  58 +
  59 + public String getUsername() {
  60 + return username;
  61 + }
  62 +
  63 + public void setUsername(String username) {
  64 + this.username = username;
  65 + }
  66 +
  67 + public String getPassword() {
  68 + return password;
  69 + }
  70 +
  71 + public void setPassword(String password) {
  72 + this.password = password;
  73 + }
  74 +
  75 +}
... ...
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/security/JAASAuthenticator.java 0 → 100644
... ... @@ -0,0 +1,161 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.security;
  38 +
  39 +import java.security.Principal;
  40 +
  41 +import javax.inject.Inject;
  42 +import javax.security.auth.login.LoginContext;
  43 +import javax.security.auth.login.LoginException;
  44 +
  45 +import br.gov.frameworkdemoiselle.internal.producer.LoginContextFactory;
  46 +
  47 +//@SessionScoped
  48 +public class JAASAuthenticator implements Authenticator {
  49 +
  50 + private static final long serialVersionUID = 1L;
  51 +
  52 + private transient LoginContext loginContext;
  53 +
  54 + private User user;
  55 +
  56 + @Inject
  57 + private Credentials credentials;
  58 +
  59 + @Override
  60 + public boolean authenticate() {
  61 + boolean result = false;
  62 +
  63 + try {
  64 + getLoginContext().login();
  65 + getLoginContext().getSubject().getPrincipals().add(new Principal() {
  66 +
  67 + @Override
  68 + public String getName() {
  69 + return credentials.getUsername();
  70 + }
  71 + });
  72 +
  73 + this.credentials.clear();
  74 + result = true;
  75 +
  76 + } catch (LoginException cause) {
  77 + result = false;
  78 + }
  79 +
  80 + return result;
  81 + }
  82 +
  83 + @Override
  84 + public void unAuthenticate() {
  85 + try {
  86 + getLoginContext().logout();
  87 + user = null;
  88 +
  89 + } catch (LoginException cause) {
  90 + cause.printStackTrace();
  91 + }
  92 + }
  93 +
  94 + @Override
  95 + public User getUser() {
  96 + if (this.user == null && getLoginContext().getSubject() != null
  97 + && !getLoginContext().getSubject().getPrincipals().isEmpty()) {
  98 + this.user = new User() {
  99 +
  100 + private static final long serialVersionUID = 1L;
  101 +
  102 + @Override
  103 + public String getId() {
  104 + return getLoginContext().getSubject().getPrincipals().iterator().next().getName();
  105 + }
  106 +
  107 + @Override
  108 + public Object getAttribute(Object key) {
  109 + return null;
  110 + }
  111 +
  112 + @Override
  113 + public void setAttribute(Object key, Object value) {
  114 + }
  115 + };
  116 + }
  117 +
  118 + return this.user;
  119 + }
  120 +
  121 + public LoginContext getLoginContext() {
  122 + if (this.loginContext == null) {
  123 + this.loginContext = LoginContextFactory.createLoginContext();
  124 + }
  125 +
  126 + return this.loginContext;
  127 + }
  128 +
  129 + //
  130 + // protected LoginContext createLoginContext() {
  131 + // LoginContext result = null;
  132 + //
  133 + // try {
  134 + // result = new LoginContext(this.config.getLoginModuleName(), createCallbackHandler());
  135 + //
  136 + // } catch (LoginException cause) {
  137 + // throw new SecurityException(cause);
  138 + // }
  139 + //
  140 + // return result;
  141 + // }
  142 +
  143 + // protected CallbackHandler createCallbackHandler() {
  144 + // return new CallbackHandler() {
  145 + //
  146 + // public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
  147 + // for (int i = 0; i < callbacks.length; i++) {
  148 + // if (callbacks[i] instanceof NameCallback) {
  149 + // ((NameCallback) callbacks[i]).setName(credentials.getUsername());
  150 + //
  151 + // } else if (callbacks[i] instanceof PasswordCallback) {
  152 + // ((PasswordCallback) callbacks[i]).setPassword(credentials.getPassword().toCharArray());
  153 + //
  154 + // } else {
  155 + // System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX Unsupported callback " + callbacks[i]);
  156 + // }
  157 + // }
  158 + // }
  159 + // };
  160 + // }
  161 +}
... ...
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/security/JAASAuthorizer.java 0 → 100644
... ... @@ -0,0 +1,95 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.security;
  38 +
  39 +import java.security.Principal;
  40 +import java.security.acl.Group;
  41 +import java.util.Enumeration;
  42 +
  43 +import javax.security.auth.login.LoginContext;
  44 +
  45 +import br.gov.frameworkdemoiselle.internal.producer.LoginContextFactory;
  46 +
  47 +public class JAASAuthorizer implements Authorizer {
  48 +
  49 + private static final long serialVersionUID = 1L;
  50 +
  51 + private transient LoginContext loginContext;
  52 +
  53 + @Override
  54 + public boolean hasRole(String role) {
  55 + boolean result = false;
  56 +
  57 + Group group;
  58 + Principal member;
  59 + Enumeration<? extends Principal> enumeration;
  60 +
  61 + for (Principal principal : getLoginContext().getSubject().getPrincipals()) {
  62 +
  63 + if (principal instanceof Group) {
  64 + group = (Group) principal;
  65 + enumeration = group.members();
  66 +
  67 + while (enumeration.hasMoreElements()) {
  68 + member = (Principal) enumeration.nextElement();
  69 +
  70 + System.out.println("xxxxxx: " + member.getName());
  71 +
  72 + if (member.getName().equals(role)) {
  73 + result = true;
  74 + break;
  75 + }
  76 + }
  77 + }
  78 + }
  79 +
  80 + return result;
  81 + }
  82 +
  83 + public LoginContext getLoginContext() {
  84 + if (this.loginContext == null) {
  85 + this.loginContext = LoginContextFactory.createLoginContext();
  86 + }
  87 +
  88 + return this.loginContext;
  89 + }
  90 +
  91 + @Override
  92 + public boolean hasPermission(String resource, String operation) {
  93 + return true;
  94 + }
  95 +}
... ...
impl/extension/jaas/src/main/resources/META-INF/beans.xml 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +<!--
  2 + Demoiselle Framework
  3 + Copyright (C) 2010 SERPRO
  4 + ============================================================================
  5 + This file is part of Demoiselle Framework.
  6 +
  7 + Demoiselle Framework is free software; you can redistribute it and/or
  8 + modify it under the terms of the GNU Lesser General Public License version 3
  9 + as published by the Free Software Foundation.
  10 +
  11 + This program is distributed in the hope that it will be useful,
  12 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + GNU General Public License for more details.
  15 +
  16 + You should have received a copy of the GNU Lesser General Public License version 3
  17 + along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + Fifth Floor, Boston, MA 02110-1301, USA.
  20 + ============================================================================
  21 + Este arquivo é parte do Framework Demoiselle.
  22 +
  23 + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + do Software Livre (FSF).
  26 +
  27 + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + para maiores detalhes.
  31 +
  32 + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +-->
  37 +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  39 +
  40 +</beans>
0 41 \ No newline at end of file
... ...
pom.xml
... ... @@ -70,6 +70,7 @@
70 70 <module>impl/extension/jta</module>
71 71 <module>impl/extension/se</module>
72 72 <module>impl/extension/servlet</module>
  73 + <module>impl/extension/jaas</module>
73 74 <module>archetype/minimal</module>
74 75 <module>archetype/jsf-jpa</module>
75 76 <module>documentation/quickstart</module>
... ...